2021-07-12 08:06:13 +00:00
|
|
|
name: OpenAPI
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
2024-05-13 15:19:06 +00:00
|
|
|
tags:
|
|
|
|
- 'v*'
|
2021-11-05 18:09:44 +00:00
|
|
|
pull_request_target:
|
2021-07-12 08:06:13 +00:00
|
|
|
|
2022-12-03 15:47:30 +00:00
|
|
|
permissions: {}
|
|
|
|
|
2021-07-12 08:06:13 +00:00
|
|
|
jobs:
|
|
|
|
openapi-head:
|
|
|
|
name: OpenAPI - HEAD
|
|
|
|
runs-on: ubuntu-latest
|
2021-11-05 21:43:09 +00:00
|
|
|
permissions: read-all
|
2021-07-12 08:06:13 +00:00
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
2024-05-16 22:24:50 +00:00
|
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
2021-11-05 18:09:44 +00:00
|
|
|
with:
|
2022-02-19 16:36:53 +00:00
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
2021-11-05 21:12:43 +00:00
|
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
2022-11-09 14:28:52 +00:00
|
|
|
- name: Setup .NET
|
2023-12-04 15:55:08 +00:00
|
|
|
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
2023-11-15 15:16:51 +00:00
|
|
|
dotnet-version: '8.0.x'
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Generate openapi.json
|
2021-09-15 17:32:55 +00:00
|
|
|
run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Upload openapi.json
|
2024-04-23 02:18:53 +00:00
|
|
|
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
name: openapi-head
|
|
|
|
retention-days: 14
|
|
|
|
if-no-files-found: error
|
2023-10-23 21:36:56 +00:00
|
|
|
path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net8.0/openapi.json
|
2021-07-12 08:06:13 +00:00
|
|
|
|
|
|
|
openapi-base:
|
|
|
|
name: OpenAPI - BASE
|
|
|
|
if: ${{ github.base_ref != '' }}
|
|
|
|
runs-on: ubuntu-latest
|
2021-11-05 21:43:09 +00:00
|
|
|
permissions: read-all
|
2021-07-12 08:06:13 +00:00
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
2024-05-16 22:24:50 +00:00
|
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
2022-12-30 15:08:02 +00:00
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
|
|
fetch-depth: 0
|
|
|
|
- name: Checkout common ancestor
|
2023-06-19 13:56:15 +00:00
|
|
|
env:
|
|
|
|
HEAD_REF: ${{ github.head_ref }}
|
2022-12-30 15:08:02 +00:00
|
|
|
run: |
|
|
|
|
git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}
|
|
|
|
git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules upstream +refs/heads/*:refs/remotes/upstream/* +refs/tags/*:refs/tags/*
|
2023-06-19 14:51:01 +00:00
|
|
|
ANCESTOR_REF=$(git merge-base upstream/${{ github.base_ref }} origin/$HEAD_REF)
|
2022-12-30 15:08:02 +00:00
|
|
|
git checkout --progress --force $ANCESTOR_REF
|
2022-11-09 14:28:52 +00:00
|
|
|
- name: Setup .NET
|
2023-12-04 15:55:08 +00:00
|
|
|
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
2023-11-15 15:16:51 +00:00
|
|
|
dotnet-version: '8.0.x'
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Generate openapi.json
|
2021-09-15 17:32:55 +00:00
|
|
|
run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Upload openapi.json
|
2024-04-23 02:18:53 +00:00
|
|
|
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
name: openapi-base
|
|
|
|
retention-days: 14
|
|
|
|
if-no-files-found: error
|
2023-10-23 21:36:56 +00:00
|
|
|
path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net8.0/openapi.json
|
2021-07-12 08:06:13 +00:00
|
|
|
|
|
|
|
openapi-diff:
|
2022-12-03 15:47:30 +00:00
|
|
|
permissions:
|
|
|
|
pull-requests: write # to create or update comment (peter-evans/create-or-update-comment)
|
|
|
|
|
2021-07-12 08:06:13 +00:00
|
|
|
name: OpenAPI - Difference
|
2021-11-05 18:09:44 +00:00
|
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
2021-07-12 08:06:13 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
|
|
- openapi-head
|
|
|
|
- openapi-base
|
|
|
|
steps:
|
|
|
|
- name: Download openapi-head
|
2024-04-25 13:15:31 +00:00
|
|
|
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
name: openapi-head
|
|
|
|
path: openapi-head
|
|
|
|
- name: Download openapi-base
|
2024-04-25 13:15:31 +00:00
|
|
|
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
name: openapi-base
|
|
|
|
path: openapi-base
|
|
|
|
- name: Workaround openapi-diff issue
|
|
|
|
run: |
|
|
|
|
sed -i 's/"allOf"/"oneOf"/g' openapi-head/openapi.json
|
|
|
|
sed -i 's/"allOf"/"oneOf"/g' openapi-base/openapi.json
|
|
|
|
- name: Calculate OpenAPI difference
|
|
|
|
uses: docker://openapitools/openapi-diff
|
|
|
|
continue-on-error: true
|
|
|
|
with:
|
|
|
|
args: --fail-on-changed --markdown openapi-changes.md openapi-base/openapi.json openapi-head/openapi.json
|
|
|
|
- id: read-diff
|
|
|
|
name: Read openapi-diff output
|
|
|
|
run: |
|
2024-05-21 13:18:59 +00:00
|
|
|
# Read and fix markdown
|
2021-07-12 08:06:13 +00:00
|
|
|
body=$(cat openapi-changes.md)
|
2024-05-21 13:18:59 +00:00
|
|
|
# Write to workflow summary
|
2024-05-21 17:57:12 +00:00
|
|
|
echo "$body" >> $GITHUB_STEP_SUMMARY
|
2024-05-21 13:18:59 +00:00
|
|
|
# Set ApiChanged var
|
2024-05-21 17:38:53 +00:00
|
|
|
if [ "$body" != '' ]; then
|
2024-05-21 13:18:59 +00:00
|
|
|
echo "ApiChanged=1" >> "$GITHUB_OUTPUT"
|
|
|
|
else
|
|
|
|
echo "ApiChanged=0" >> "$GITHUB_OUTPUT"
|
|
|
|
fi
|
|
|
|
# Add header/footer for diff comment
|
|
|
|
echo '<!--openapi-diff-workflow-comment-->' > openapi-changes-reply.md
|
|
|
|
echo "<details>" >> openapi-changes-reply.md
|
|
|
|
echo "<summary>Changes in OpenAPI specification found. Expand to see details.</summary>" >> openapi-changes-reply.md
|
2024-05-21 17:57:12 +00:00
|
|
|
echo "" >> openapi-changes-reply.md
|
2024-05-21 13:18:59 +00:00
|
|
|
echo "$body" >> openapi-changes-reply.md
|
2024-05-21 17:57:12 +00:00
|
|
|
echo "" >> openapi-changes-reply.md
|
2024-05-21 13:18:59 +00:00
|
|
|
echo "</details>" >> openapi-changes-reply.md
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Find difference comment
|
2024-04-02 13:04:40 +00:00
|
|
|
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
|
2021-07-12 08:06:13 +00:00
|
|
|
id: find-comment
|
|
|
|
with:
|
|
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
|
|
direction: last
|
|
|
|
body-includes: openapi-diff-workflow-comment
|
|
|
|
- name: Reply or edit difference comment (changed)
|
2024-01-25 12:09:48 +00:00
|
|
|
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
|
2024-05-21 13:18:59 +00:00
|
|
|
if: ${{ steps.read-diff.outputs.ApiChanged == '1' }}
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
|
|
comment-id: ${{ steps.find-comment.outputs.comment-id }}
|
|
|
|
edit-mode: replace
|
2024-05-21 13:18:59 +00:00
|
|
|
body-path: openapi-changes-reply.md
|
2021-07-12 08:06:13 +00:00
|
|
|
- name: Edit difference comment (unchanged)
|
2024-01-25 12:09:48 +00:00
|
|
|
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
|
2024-05-21 13:18:59 +00:00
|
|
|
if: ${{ steps.read-diff.outputs.ApiChanged == '0' && steps.find-comment.outputs.comment-id != '' }}
|
2021-07-12 08:06:13 +00:00
|
|
|
with:
|
|
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
|
|
comment-id: ${{ steps.find-comment.outputs.comment-id }}
|
|
|
|
edit-mode: replace
|
|
|
|
body: |
|
|
|
|
<!--openapi-diff-workflow-comment-->
|
|
|
|
|
|
|
|
No changes to OpenAPI specification found. See history of this comment for previous changes.
|
2024-03-25 14:32:52 +00:00
|
|
|
|
2024-05-13 15:30:25 +00:00
|
|
|
publish-unstable:
|
2024-03-25 14:32:52 +00:00
|
|
|
name: OpenAPI - Publish Unstable Spec
|
2024-05-19 13:57:51 +00:00
|
|
|
if: ${{ github.event_name != 'pull_request_target' && !startsWith(github.ref, 'refs/tags/v') && contains(github.repository_owner, 'jellyfin') }}
|
2024-03-25 14:32:52 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
|
|
- openapi-head
|
|
|
|
steps:
|
|
|
|
- name: Set unstable dated version
|
|
|
|
id: version
|
|
|
|
run: |-
|
2024-03-25 14:58:11 +00:00
|
|
|
echo "JELLYFIN_VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
|
2024-03-25 14:32:52 +00:00
|
|
|
- name: Download openapi-head
|
2024-04-25 13:15:31 +00:00
|
|
|
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
|
2024-03-25 14:32:52 +00:00
|
|
|
with:
|
|
|
|
name: openapi-head
|
|
|
|
path: openapi-head
|
|
|
|
- name: Upload openapi.json (unstable) to repository server
|
|
|
|
uses: appleboy/scp-action@917f8b81dfc1ccd331fef9e2d61bdc6c8be94634 # v0.1.7
|
|
|
|
with:
|
|
|
|
host: "${{ secrets.REPO_HOST }}"
|
|
|
|
username: "${{ secrets.REPO_USER }}"
|
|
|
|
key: "${{ secrets.REPO_KEY }}"
|
|
|
|
source: openapi-head/openapi.json
|
|
|
|
strip_components: 1
|
2024-03-25 16:32:49 +00:00
|
|
|
target: "/srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}"
|
2024-03-25 14:32:52 +00:00
|
|
|
- name: Move openapi.json (unstable) into place
|
|
|
|
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
|
|
|
|
with:
|
|
|
|
host: "${{ secrets.REPO_HOST }}"
|
|
|
|
username: "${{ secrets.REPO_USER }}"
|
|
|
|
key: "${{ secrets.REPO_KEY }}"
|
|
|
|
debug: false
|
|
|
|
script_stop: false
|
|
|
|
script: |
|
2024-04-18 13:29:31 +00:00
|
|
|
if ! test -d /run/workflows; then
|
|
|
|
sudo mkdir -p /run/workflows
|
|
|
|
sudo chown ${{ secrets.REPO_USER }} /run/workflows
|
|
|
|
fi
|
2024-04-18 13:03:06 +00:00
|
|
|
(
|
|
|
|
flock -x -w 300 200 || exit 1
|
2024-03-25 14:32:52 +00:00
|
|
|
TGT_DIR="/srv/repository/main/openapi"
|
2024-03-25 15:49:19 +00:00
|
|
|
LAST_SPEC="$( ls -lt ${TGT_DIR}/unstable/ | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )"
|
2024-03-25 15:53:40 +00:00
|
|
|
# If new and previous spec don't differ (diff retcode 0), remove incoming and finish
|
2024-03-25 16:32:49 +00:00
|
|
|
if diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}/openapi.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then
|
|
|
|
rm -r /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}
|
2024-03-25 15:47:29 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2024-03-25 15:53:40 +00:00
|
|
|
# Move new spec into place
|
2024-03-25 16:32:49 +00:00
|
|
|
sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}/openapi.json ${TGT_DIR}/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json
|
2024-03-25 14:32:52 +00:00
|
|
|
# Delete previous jellyfin-openapi-unstable_previous.json
|
|
|
|
sudo rm ${TGT_DIR}/jellyfin-openapi-unstable_previous.json
|
|
|
|
# Move current jellyfin-openapi-unstable.json symlink to jellyfin-openapi-unstable_previous.json
|
|
|
|
sudo mv ${TGT_DIR}/jellyfin-openapi-unstable.json ${TGT_DIR}/jellyfin-openapi-unstable_previous.json
|
2024-04-18 13:03:06 +00:00
|
|
|
# Create new jellyfin-openapi-unstable.json symlink
|
2024-03-25 14:32:52 +00:00
|
|
|
sudo ln -s unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/jellyfin-openapi-unstable.json
|
2024-04-18 13:03:06 +00:00
|
|
|
# Check that the previous openapi unstable spec link is correct
|
2024-03-25 14:32:52 +00:00
|
|
|
if [[ "$( readlink ${TGT_DIR}/jellyfin-openapi-unstable_previous.json )" != "unstable/${LAST_SPEC}" ]]; then
|
|
|
|
sudo rm ${TGT_DIR}/jellyfin-openapi-unstable_previous.json
|
|
|
|
sudo ln -s unstable/${LAST_SPEC} ${TGT_DIR}/jellyfin-openapi-unstable_previous.json
|
|
|
|
fi
|
2024-04-18 13:29:31 +00:00
|
|
|
) 200>/run/workflows/openapi-unstable.lock
|
2024-05-13 15:19:06 +00:00
|
|
|
|
2024-05-13 15:30:25 +00:00
|
|
|
publish-stable:
|
2024-05-13 15:19:06 +00:00
|
|
|
name: OpenAPI - Publish Stable Spec
|
2024-05-19 13:57:51 +00:00
|
|
|
if: ${{ startsWith(github.ref, 'refs/tags/v') && contains(github.repository_owner, 'jellyfin') }}
|
2024-05-13 15:19:06 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
|
|
- openapi-head
|
|
|
|
steps:
|
|
|
|
- name: Set version number
|
|
|
|
id: version
|
|
|
|
run: |-
|
|
|
|
echo "JELLYFIN_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
|
|
|
- name: Download openapi-head
|
|
|
|
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
|
|
|
|
with:
|
|
|
|
name: openapi-head
|
|
|
|
path: openapi-head
|
|
|
|
- name: Upload openapi.json (stable) to repository server
|
|
|
|
uses: appleboy/scp-action@917f8b81dfc1ccd331fef9e2d61bdc6c8be94634 # v0.1.7
|
|
|
|
with:
|
|
|
|
host: "${{ secrets.REPO_HOST }}"
|
|
|
|
username: "${{ secrets.REPO_USER }}"
|
|
|
|
key: "${{ secrets.REPO_KEY }}"
|
|
|
|
source: openapi-head/openapi.json
|
|
|
|
strip_components: 1
|
|
|
|
target: "/srv/incoming/openapi/stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}"
|
|
|
|
- name: Move openapi.json (stable) into place
|
|
|
|
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
|
|
|
|
with:
|
|
|
|
host: "${{ secrets.REPO_HOST }}"
|
|
|
|
username: "${{ secrets.REPO_USER }}"
|
|
|
|
key: "${{ secrets.REPO_KEY }}"
|
|
|
|
debug: false
|
|
|
|
script_stop: false
|
|
|
|
script: |
|
|
|
|
if ! test -d /run/workflows; then
|
|
|
|
sudo mkdir -p /run/workflows
|
|
|
|
sudo chown ${{ secrets.REPO_USER }} /run/workflows
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
flock -x -w 300 200 || exit 1
|
|
|
|
TGT_DIR="/srv/repository/main/openapi"
|
|
|
|
LAST_SPEC="$( ls -lt ${TGT_DIR}/stable/ | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )"
|
|
|
|
# If new and previous spec don't differ (diff retcode 0), remove incoming and finish
|
|
|
|
if diff /srv/incoming/openapi/stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}/openapi.json ${TGT_DIR}/stable/${LAST_SPEC} &>/dev/null; then
|
|
|
|
rm -r /srv/incoming/openapi/stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
# Move new spec into place
|
|
|
|
sudo mv /srv/incoming/openapi/stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}/openapi.json ${TGT_DIR}/stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json
|
|
|
|
# Delete previous jellyfin-openapi-stable_previous.json
|
|
|
|
sudo rm ${TGT_DIR}/jellyfin-openapi-stable_previous.json
|
|
|
|
# Move current jellyfin-openapi-stable.json symlink to jellyfin-openapi-stable_previous.json
|
|
|
|
sudo mv ${TGT_DIR}/jellyfin-openapi-stable.json ${TGT_DIR}/jellyfin-openapi-stable_previous.json
|
|
|
|
# Create new jellyfin-openapi-stable.json symlink
|
|
|
|
sudo ln -s stable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/jellyfin-openapi-stable.json
|
|
|
|
# Check that the previous openapi stable spec link is correct
|
|
|
|
if [[ "$( readlink ${TGT_DIR}/jellyfin-openapi-stable_previous.json )" != "stable/${LAST_SPEC}" ]]; then
|
|
|
|
sudo rm ${TGT_DIR}/jellyfin-openapi-stable_previous.json
|
|
|
|
sudo ln -s stable/${LAST_SPEC} ${TGT_DIR}/jellyfin-openapi-stable_previous.json
|
|
|
|
fi
|
|
|
|
) 200>/run/workflows/openapi-stable.lock
|