|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on pull request events but only for the "main" branch |
| 8 | + pull_request: |
| 9 | + branches: [ "main" ] |
| 10 | + |
| 11 | + # Allows you to run this workflow manually from the Actions tab |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + # ... other jobs here |
| 16 | + |
| 17 | + wait-for-external-status: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + needs: [build, test] # list all your previous jobs |
| 20 | + if: always() # run even if previous jobs failed (adjust as needed) |
| 21 | + steps: |
| 22 | + - name: Wait for external status "ci/prow/e2e" |
| 23 | + env: |
| 24 | + DESIRED_CONTEXT: "ci/prow/e2e" |
| 25 | + MAX_RETRIES: 30 |
| 26 | + RETRY_DELAY: 10 |
| 27 | + COMMIT_SHA: ${{ github.sha }} |
| 28 | + REPO: ${{ github.repository }} |
| 29 | + TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + run: | |
| 31 | + i=0 |
| 32 | + statusFound=false |
| 33 | + while [ $i -lt $MAX_RETRIES ]; do |
| 34 | + echo "Checking statuses for commit $COMMIT_SHA (attempt $((i+1))/$MAX_RETRIES)..." |
| 35 | + RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" \ |
| 36 | + -H "Authorization: token $TOKEN" \ |
| 37 | + "https://api.github.com/repos/$REPO/commits/$COMMIT_SHA/statuses") |
| 38 | + # Use jq to look for our desired context and get its state |
| 39 | + STATE=$(echo "$RESPONSE" | jq -r --arg context "$DESIRED_CONTEXT" '.[] | select(.context==$context) | .state' ) |
| 40 | + if [ -n "$STATE" ] && [ "$STATE" != "pending" ]; then |
| 41 | + echo "Found status context '$DESIRED_CONTEXT' with state: $STATE" |
| 42 | + statusFound=true |
| 43 | + break |
| 44 | + else |
| 45 | + echo "Status context '$DESIRED_CONTEXT' not found or still pending. Waiting..." |
| 46 | + fi |
| 47 | + i=$((i+1)) |
| 48 | + sleep $RETRY_DELAY |
| 49 | + done |
| 50 | +
|
| 51 | + if [ "$statusFound" = false ]; then |
| 52 | + echo "Timeout waiting for status context '$DESIRED_CONTEXT'" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Proceed with final steps |
| 57 | + run: echo "All statuses are now complete. Continuing with the workflow..." |
0 commit comments