Update OpenAPI Workflow #643
This file contains 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 Workflow | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: { } | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
- name: Install yq | |
run: | | |
go install github.com/mikefarah/yq/v4@latest | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Backup original files | |
run: | | |
mv openapi.yaml openapi.old.yaml | |
mv openapi.slim.yaml openapi.old.slim.yaml | |
- name: Download the latest version | |
uses: enflo/curl-action@master | |
with: | |
curl: -o openapi.yaml https://api.gsmtasks.com/docs/schema/ | |
- name: Preprocess files | |
run: | | |
VERSION=$(~/go/bin/yq e '.info.version' openapi.yaml) | |
sed -e "s/; version=${VERSION}/; version=\${version}/g"\ | |
-e "s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}[+-][0-9]\{2\}:[0-9]\{2\}/\${date}/g"\ | |
-e "s/[0-9a-fA-F]\{8\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{4\}-[0-9a-fA-F]\{12\}/\${uuid}/g"\ | |
openapi.yaml > openapi.slim.yaml | |
- name: Compare files | |
run: | | |
set +e | |
diff openapi.old.slim.yaml openapi.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: Commit and push changes | |
if: ${{ steps.compare.outputs.exit_code == 1 }} | |
run: | | |
VERSION=$(~/go/bin/yq e '.info.version' openapi.yaml) | |
git config --global user.email "action@github.com" | |
git config --global user.name "GitHub Action" | |
git add openapi.yaml openapi.slim.yaml | |
git commit -m "Update OpenAPI ${VERSION}" | |
git push |