|
| 1 | +name: Update Compute Discovery Document |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs every Monday at 09:00 UTC |
| 6 | + - cron: '0 9 * * 1' |
| 7 | + workflow_dispatch: # Allows manual trigger from the GitHub Actions UI |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-compute-discovery: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + persist-credentials: false |
| 24 | + |
| 25 | + - name: Setup Git user identity |
| 26 | + run: | |
| 27 | + git config user.name "cloud-cpp-automation[bot]" |
| 28 | + git config user.email "cloud-cpp-automation[bot]@users.noreply.github.com" |
| 29 | +
|
| 30 | + - name: Run update_discovery_doc.sh |
| 31 | + run: | |
| 32 | + ./generator/discovery/update_discovery_doc.sh --no-create-branch |
| 33 | +
|
| 34 | + - name: Run checkers |
| 35 | + run: | |
| 36 | + ci/cloudbuild/build.sh -t checkers-pr |
| 37 | +
|
| 38 | + - name: Push branch and create Pull Request if changes exist |
| 39 | + env: |
| 40 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + run: | |
| 42 | + # Check if a new commit was made (HEAD differs from origin/main) |
| 43 | + if [[ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]]; then |
| 44 | + echo "Changes detected. Pushing branch automation/update-compute-discovery..." |
| 45 | + git push origin HEAD:automation/update-compute-discovery --force |
| 46 | +
|
| 47 | + echo "Checking if a PR is already open..." |
| 48 | + if ! gh pr list --head "automation/update-compute-discovery" --json number -q '.[0].number' | grep -q '^[0-9]'; then |
| 49 | + echo "Opening new PR..." |
| 50 | + BODY="Automated update of Compute Engine Discovery Document and generated C++ client code.\n\nTriggered automatically by the \`update-compute-discovery\` workflow." |
| 51 | + gh pr create \ |
| 52 | + --title "feat(compute): update discovery doc and generate new services" \ |
| 53 | + --body "$(printf '%b' "$BODY")" \ |
| 54 | + --base main \ |
| 55 | + --head automation/update-compute-discovery \ |
| 56 | + --label "autorelease: pending" |
| 57 | + else |
| 58 | + echo "Pull request already exists for automation/update-compute-discovery. Branch has been updated." |
| 59 | + fi |
| 60 | + else |
| 61 | + echo "No changes committed. Nothing to push or create." |
| 62 | + fi |
0 commit comments