|
| 1 | +name: Pending Deploy Check |
| 2 | + |
| 3 | +# This workflow validates that pending deploy PRs are safe to merge. |
| 4 | +# |
| 5 | +# Trigger: Pull requests to main from automation/pending-deploy-* branches |
| 6 | +# Purpose: Verify all commits in the PR have been deployed in managed-service |
| 7 | +# |
| 8 | +# Why: SDK changes are generated from managed-service OpenAPI specs. We must ensure |
| 9 | +# the corresponding managed-service changes have been deployed before merging the SDK changes, |
| 10 | +# otherwise the SDK could reference unreleased API features. |
| 11 | +# |
| 12 | +# Flow: |
| 13 | +# 1. For each commit in the PR, extract the Managed-service-commit-SHA trailer |
| 14 | +# 2. Check if that SHA is in the latest managed-service release tag |
| 15 | +# 3. If any commits are not yet deployed, post a detailed comment and fail the PR |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request: |
| 19 | + branches: [main] |
| 20 | + workflow_dispatch: |
| 21 | + inputs: |
| 22 | + branch: |
| 23 | + description: 'Pending deploy branch to check' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + pr_url: |
| 27 | + description: 'PR URL to comment on if check fails' |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + |
| 31 | +permissions: |
| 32 | + contents: read # Checkout repository and read commit history |
| 33 | + pull-requests: write # Post failure comments on PRs |
| 34 | + |
| 35 | +jobs: |
| 36 | + pending-deploy-check: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + if: | |
| 39 | + (github.event_name == 'pull_request' && startsWith(github.head_ref, 'automation/pending-deploy-')) || |
| 40 | + (github.event_name == 'workflow_dispatch' && startsWith(inputs.branch, 'automation/pending-deploy-')) |
| 41 | + steps: |
| 42 | + - name: Checkout repository |
| 43 | + uses: actions/checkout@v6 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + - name: Validate workflow input |
| 48 | + if: github.event_name == 'workflow_dispatch' |
| 49 | + id: validate-input |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ github.token }} |
| 52 | + run: | |
| 53 | + source scripts/lib/actions-helpers.sh |
| 54 | +
|
| 55 | + # Extract PR number from URL |
| 56 | + PR_NUMBER=$(echo "${{ inputs.pr_url }}" | grep -oE '[0-9]+$') |
| 57 | + set_output pr_number "$PR_NUMBER" |
| 58 | +
|
| 59 | + # Validate the PR's head branch matches the input branch |
| 60 | + PR_HEAD_BRANCH=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.headRefName') |
| 61 | + if [ "$PR_HEAD_BRANCH" != "${{ inputs.branch }}" ]; then |
| 62 | + log_error "PR #$PR_NUMBER head branch ($PR_HEAD_BRANCH) does not match input branch (${{ inputs.branch }})" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Run deployment check |
| 67 | + id: check-deployment |
| 68 | + env: |
| 69 | + PENDING_DEPLOY_BRANCH: ${{ inputs.branch || github.head_ref }} |
| 70 | + MANAGED_SERVICE_TOKEN: ${{ secrets.MANAGED_SERVICE_TOKEN }} |
| 71 | + run: scripts/pending-deploy-check.sh |
| 72 | + |
| 73 | + - name: Post failure comment and fail |
| 74 | + if: steps.check-deployment.outputs.has_issues == 'true' |
| 75 | + env: |
| 76 | + PR_NUMBER: ${{ steps.validate-input.outputs.pr_number || github.event.pull_request.number }} |
| 77 | + GITHUB_TOKEN: ${{ github.token }} |
| 78 | + run: | |
| 79 | + scripts/post-failure-comment.sh |
| 80 | + source scripts/lib/actions-helpers.sh |
| 81 | + log_error "Deployment check failed - see PR comment for details" |
| 82 | + exit 1 |
| 83 | +
|
| 84 | + - name: Summary |
| 85 | + if: always() |
| 86 | + run: | |
| 87 | + source scripts/lib/actions-helpers.sh |
| 88 | + if [ "${{ steps.check-deployment.outputs.has_issues }}" != "true" ]; then |
| 89 | + log_info "All commits in pending deploy branch are deployed in managed-service" |
| 90 | + else |
| 91 | + log_info "Some commits are not deployed or potentially not deployed" |
| 92 | + fi |
0 commit comments