|
| 1 | +name: Update api-schemas pinned commit |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-and-update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout docs repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Get latest api-schemas commit |
| 20 | + id: get-commit |
| 21 | + run: | |
| 22 | + LATEST_COMMIT=$(curl -s -H "Accept: application/vnd.github.v3+json" \ |
| 23 | + https://api.github.com/repos/cloudflare/api-schemas/commits/main | \ |
| 24 | + jq -r '.sha') |
| 25 | + echo "latest_commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + - name: Check current commit reference |
| 28 | + id: check-current |
| 29 | + run: | |
| 30 | + CURRENT_COMMIT=$(grep 'const COMMIT = ' src/util/api.ts | sed 's/.*"\(.*\)".*/\1/') |
| 31 | + echo "current_commit=$CURRENT_COMMIT" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + - name: Create PR if needed |
| 34 | + if: steps.get-commit.outputs.latest_commit != steps.check-current.outputs.current_commit |
| 35 | + run: | |
| 36 | + # Create a new branch |
| 37 | + git config --global user.name 'github-actions[bot]' |
| 38 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 39 | + BRANCH_NAME="update-api-schemas-$(date +%Y%m%d-%H%M%S)" |
| 40 | + git checkout -b $BRANCH_NAME |
| 41 | +
|
| 42 | + # Update the commit reference |
| 43 | + NEW_COMMIT="${{ steps.get-commit.outputs.latest_commit }}" |
| 44 | + sed -i "s/const COMMIT = \".*\"/const COMMIT = \"$NEW_COMMIT\"/" src/util/api.ts |
| 45 | +
|
| 46 | + # Commit and push changes |
| 47 | + git add src/util/api.ts |
| 48 | + git commit -m "[Docs Site] Update pinned api-schemas commit to $NEW_COMMIT" |
| 49 | + git push origin $BRANCH_NAME |
| 50 | +
|
| 51 | + # Create pull request |
| 52 | + gh pr create \ |
| 53 | + --title "[Docs Site] Update pinned api-schemas commit" \ |
| 54 | + --body "This PR updates the api-schemas commit reference to the latest version ($NEW_COMMIT)." \ |
| 55 | + --base main \ |
| 56 | + --head $BRANCH_NAME |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments