Browse Source

Add openapi.json upload to new repo server

Joshua M. Boniface 1 year ago
parent
commit
b77a9e98c2
1 changed files with 51 additions and 0 deletions
  1. 51 0
      .github/workflows/ci-openapi.yml

+ 51 - 0
.github/workflows/ci-openapi.yml

@@ -137,3 +137,54 @@ jobs:
             <!--openapi-diff-workflow-comment-->
 
             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