Sync #149
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: Sync | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 1-4' | |
permissions: | |
contents: write | |
pull-requests: write | |
checks: write | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.x | |
cache-dependency-path: | | |
./go.sum | |
_tools/go.sum | |
- name: Go version | |
run: go version | |
- name: Install Swagger binary | |
run: | | |
bin/deps.sh github.com/go-swagger/go-swagger/cmd/swagger | |
echo "$(pwd)/bin" >> $GITHUB_PATH | |
- name: Regenerate Swagger code | |
id: swagger | |
run: | | |
REVISION=$(curl -s https://app.firehydrant.io/infra/health | jq -r .revision) | |
set -x | |
echo "REVISION=${REVISION}" >> "$GITHUB_OUTPUT" | |
bin/update-swagger-doc.sh | |
bin/regenerate.sh | |
echo "API_MD5=$(md5sum swagger_doc.json | awk '{print $1}')" >> "$GITHUB_OUTPUT" | |
- name: Commit changes | |
run: | | |
api_server_revision="${{ steps.swagger.outputs.REVISION }}" | |
api_md5="${{ steps.swagger.outputs.API_MD5 }}" | |
# Use MD5 of Swagger document as branch name to avoid duplicate PRs | |
branch="swagger/${api_md5}" | |
set -x | |
# If remote branch exists, just terminate early. | |
git fetch origin "${branch}" && exit 0 || true | |
git checkout -b "${branch}" | |
git config --global user.email "[email protected]" | |
git config --global user.name "FireHydrant Bot" | |
git add . | |
# If there are no changes, exit 0 and don't push | |
git commit -m "Regenerate Swagger code ${api_server_revision}" || exit 0 | |
git push -u origin "${branch}" | |
gh pr create \ | |
--title "Regenerate Swagger code \`${api_server_revision}\`" \ | |
--body "https://github.com/firehydrant/laddertruck/commits/${api_server_revision}" \ | |
--base main \ | |
--head "${branch}" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |