Update OpenAPI #1275
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update OpenAPI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - ".github/**" | |
| - "slim.js" | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: { } | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Read old API version | |
| id: apiVersionOld | |
| uses: mikefarah/yq@master | |
| with: | |
| cmd: yq '.info.version' 'openapi.yaml' | |
| - name: Download the latest version | |
| uses: enflo/curl-action@master | |
| with: | |
| curl: -o openapi.new.yaml https://api.gsmtasks.com/docs/schema/ | |
| - name: Read API version | |
| id: apiVersion | |
| uses: mikefarah/yq@master | |
| with: | |
| cmd: yq '.info.version' openapi.new.yaml | |
| - name: Tag on version change | |
| if: ${{ steps.apiVersion.outputs.result != steps.apiVersionOld.outputs.result }} | |
| run: | | |
| git tag ${{ steps.apiVersionOld.outputs.result }} | |
| git push origin "${{ steps.apiVersionOld.outputs.result }}" | |
| - name: Set up node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: v24 | |
| - name: Generate slim file | |
| run: npx betterer-json slim.js openapi.new.yaml > openapi.new.slim.yaml | |
| - name: Compare files | |
| run: | | |
| set +e | |
| diff openapi.slim.yaml openapi.new.slim.yaml | |
| exit_code=$? | |
| echo "exit_code=${exit_code}" >> $GITHUB_OUTPUT | |
| set -e | |
| id: compare | |
| continue-on-error: true | |
| - name: Outputs from Compare step | |
| run: | | |
| echo "Outputs from compare:" | |
| echo "${{ toJson(steps.compare.outputs) }}" | |
| - name: Rename the new files | |
| if: ${{ steps.compare.outputs.exit_code == 1 }} | |
| run: | | |
| mv openapi.new.yaml openapi.yaml | |
| mv openapi.new.slim.yaml openapi.slim.yaml | |
| - name: Commit and push changes | |
| if: ${{ steps.compare.outputs.exit_code == 1 }} | |
| run: | | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add openapi.yaml openapi.slim.yaml | |
| git commit -m "Update OpenAPI ${{ steps.apiVersion.outputs.result }}" | |
| git push |