From b77a9e98c284a09b296f8fff0691199d39dd389b Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 10:32:52 -0400 Subject: [PATCH 01/10] Add openapi.json upload to new repo server --- .github/workflows/ci-openapi.yml | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index b5ccafb865..ede94b54ce 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -137,3 +137,54 @@ jobs: No changes to OpenAPI specification found. See history of this comment for previous changes. + + publish: + name: OpenAPI - Publish Unstable Spec + if: + - github.event_name != 'pull_request' + - ${{ contains(github.repository_owner, 'jellyfin') }} + runs-on: ubuntu-latest + needs: + - openapi-head + steps: + - name: Set unstable dated version + id: version + run: |- + echo "JELLYFIN_VERSION=$(date +'%Y%m%d%H')" >> $GITHUB_ENV + - name: Download openapi-head + uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 + 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 + target: "/srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json" + - 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: | + TGT_DIR="/srv/repository/main/openapi" + LAST_SPEC="$( ls -lt ${TGT_DIR} | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" + sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/ jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json + # 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 + # Create new jellyfin-openapi-stable.json symlink + sudo ln -s unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/jellyfin-openapi-unstable.json + # Check that the previous openapi spec is correct + 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 From 38e76963948a18763fb9e31790a339e65a8dd922 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 10:35:09 -0400 Subject: [PATCH 02/10] Remove interpolation Make these consistent since that seems to work based on other examples. --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index ede94b54ce..fbd2518337 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -142,7 +142,7 @@ jobs: name: OpenAPI - Publish Unstable Spec if: - github.event_name != 'pull_request' - - ${{ contains(github.repository_owner, 'jellyfin') }} + - contains(github.repository_owner, 'jellyfin') runs-on: ubuntu-latest needs: - openapi-head From a39cd584e8646a497e0f07c076c686eea7404299 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 10:57:02 -0400 Subject: [PATCH 03/10] Fix multi-condition syntax --- .github/workflows/ci-openapi.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index fbd2518337..a96771b77b 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -140,9 +140,9 @@ jobs: publish: name: OpenAPI - Publish Unstable Spec - if: - - github.event_name != 'pull_request' - - contains(github.repository_owner, 'jellyfin') + if: | + github.event_name != 'pull_request' && + contains(github.repository_owner, 'jellyfin') runs-on: ubuntu-latest needs: - openapi-head From f64e64544f4ec8753f9d18077e39a2f6f287c6ae Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 10:58:11 -0400 Subject: [PATCH 04/10] Make date to the second --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index a96771b77b..43a2e2510a 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -150,7 +150,7 @@ jobs: - name: Set unstable dated version id: version run: |- - echo "JELLYFIN_VERSION=$(date +'%Y%m%d%H')" >> $GITHUB_ENV + echo "JELLYFIN_VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV - name: Download openapi-head uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: From a08f8e22da1b15a16cc6558e10eb18146d5b36a6 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:46:22 -0400 Subject: [PATCH 05/10] Fix extra space --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index 43a2e2510a..f8a35999e6 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -176,7 +176,7 @@ jobs: script: | TGT_DIR="/srv/repository/main/openapi" LAST_SPEC="$( ls -lt ${TGT_DIR} | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" - sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/ jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json + sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json # 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 From 77bd040c1fdd6d7b4f621eaaa98b5c25d0292bc3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:47:29 -0400 Subject: [PATCH 06/10] Only proceed if the spec differs Avoids overwriting identical specs and burying the old ones. --- .github/workflows/ci-openapi.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index f8a35999e6..79f046be83 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -176,6 +176,9 @@ jobs: script: | TGT_DIR="/srv/repository/main/openapi" LAST_SPEC="$( ls -lt ${TGT_DIR} | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" + if ! diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then + exit 0 + fi sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json # Delete previous jellyfin-openapi-unstable_previous.json sudo rm ${TGT_DIR}/jellyfin-openapi-unstable_previous.json From 1cea9eff6e2d3ec1a4b3a3c491b1f098d787ae30 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:49:19 -0400 Subject: [PATCH 07/10] Add correct directory to TGT_DIR in LAST_SPEC --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index 79f046be83..8d497069b9 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -175,7 +175,7 @@ jobs: script_stop: false script: | TGT_DIR="/srv/repository/main/openapi" - LAST_SPEC="$( ls -lt ${TGT_DIR} | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" + LAST_SPEC="$( ls -lt ${TGT_DIR}/unstable/ | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" if ! diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then exit 0 fi From 015a256f1b373146b7d5549251328a1e9717959d Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:50:38 -0400 Subject: [PATCH 08/10] Remove incoming spec if not needed --- .github/workflows/ci-openapi.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index 8d497069b9..67de4154d7 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -177,6 +177,7 @@ jobs: TGT_DIR="/srv/repository/main/openapi" LAST_SPEC="$( ls -lt ${TGT_DIR}/unstable/ | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" if ! diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then + rm /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json exit 0 fi sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json From 77cc4068b18a23f6514b2ac92d3f8c3f9de7b8ae Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:52:02 -0400 Subject: [PATCH 09/10] Flip conditional diff returns 0 if no difference which is what we want. --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index 67de4154d7..5eead47f1e 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -176,7 +176,7 @@ jobs: script: | TGT_DIR="/srv/repository/main/openapi" LAST_SPEC="$( ls -lt ${TGT_DIR}/unstable/ | grep 'jellyfin-openapi' | head -1 | awk '{ print $NF }' )" - if ! diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then + if diff /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then rm /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json exit 0 fi From 5cf3e8b6063e1d0bbad2662b7c77113191f135d0 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 25 Mar 2024 11:53:40 -0400 Subject: [PATCH 10/10] Add more comments --- .github/workflows/ci-openapi.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index 5eead47f1e..b80bff1292 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -176,10 +176,12 @@ jobs: script: | TGT_DIR="/srv/repository/main/openapi" LAST_SPEC="$( ls -lt ${TGT_DIR}/unstable/ | 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/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/${LAST_SPEC} &>/dev/null; then rm /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json exit 0 fi + # Move new spec into place sudo mv /srv/incoming/openapi/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json ${TGT_DIR}/unstable/jellyfin-openapi-${{ env.JELLYFIN_VERSION }}.json # Delete previous jellyfin-openapi-unstable_previous.json sudo rm ${TGT_DIR}/jellyfin-openapi-unstable_previous.json