|
6 | 6 | workflow_run: |
7 | 7 | workflows: [build] |
8 | 8 | types: [completed] |
9 | | - workflow_dispatch: |
10 | | - inputs: |
11 | | - compute_type: |
12 | | - description: "Compute type to deploy" |
13 | | - required: true |
14 | | - type: choice |
15 | | - options: |
16 | | - - all |
17 | | - - agentcore |
18 | 9 | permissions: {} |
19 | 10 | jobs: |
20 | 11 | resolve-targets: |
21 | | - if: >- |
22 | | - github.event_name == 'workflow_dispatch' || |
23 | | - github.event.workflow_run.conclusion == 'success' |
| 12 | + if: github.event.workflow_run.conclusion == 'success' |
24 | 13 | runs-on: ubuntu-latest |
25 | 14 | permissions: |
26 | 15 | actions: read |
27 | 16 | pull-requests: read |
28 | 17 | outputs: |
29 | 18 | matrix: ${{ steps.targets.outputs.matrix }} |
30 | 19 | has_targets: ${{ steps.targets.outputs.has_targets }} |
31 | | - run_id: ${{ steps.targets.outputs.run_id }} |
| 20 | + run_id: ${{ github.event.workflow_run.id }} |
32 | 21 | steps: |
| 22 | + - name: Download deploy intent |
| 23 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
| 24 | + with: |
| 25 | + name: deploy-intent |
| 26 | + run-id: ${{ github.event.workflow_run.id }} |
| 27 | + github-token: ${{ github.token }} |
| 28 | + |
33 | 29 | - name: Resolve deploy targets |
34 | 30 | id: targets |
35 | 31 | env: |
36 | 32 | GH_TOKEN: ${{ github.token }} |
37 | | - EVENT_NAME: ${{ github.event_name }} |
38 | | - HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
39 | | - BUILD_EVENT_TYPE: ${{ github.event.workflow_run.event }} |
40 | 33 | REPO: ${{ github.repository }} |
41 | 34 | PR_NUMBER_FROM_EVENT: ${{ github.event.workflow_run.pull_requests[0].number }} |
42 | | - WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }} |
43 | | - DISPATCH_COMPUTE_TYPE: ${{ inputs.compute_type }} |
44 | 35 | run: | |
45 | 36 | ALL_TYPES='["agentcore"]' |
| 37 | + INTENT=$(jq -r '.deploy' deploy-intent.json) |
| 38 | + echo "Deploy intent from build: $INTENT" |
46 | 39 |
|
47 | | - # workflow_dispatch: use input choice |
48 | | - if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then |
49 | | - if [[ "$DISPATCH_COMPUTE_TYPE" == "all" ]]; then |
50 | | - echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
51 | | - else |
52 | | - echo "matrix=[\"$DISPATCH_COMPUTE_TYPE\"]" >> "$GITHUB_OUTPUT" |
53 | | - fi |
54 | | - echo "has_targets=true" >> "$GITHUB_OUTPUT" |
55 | | - # Find the latest successful build run for this branch |
56 | | - RUN_ID=$(gh api "repos/$REPO/actions/workflows/build.yml/runs?branch=$(git branch --show-current 2>/dev/null || echo main)&status=success&per_page=1" --jq '.workflow_runs[0].id // empty') |
57 | | - echo "run_id=${RUN_ID}" >> "$GITHUB_OUTPUT" |
58 | | - exit 0 |
59 | | - fi |
60 | | -
|
61 | | - # workflow_run context from here on |
62 | | - echo "run_id=${WORKFLOW_RUN_ID}" >> "$GITHUB_OUTPUT" |
63 | | -
|
64 | | - # Push to main or workflow_dispatch on build always deploys all |
65 | | - if [[ "$HEAD_BRANCH" == "main" && ("$BUILD_EVENT_TYPE" == "push" || "$BUILD_EVENT_TYPE" == "workflow_dispatch") ]]; then |
66 | | - echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
67 | | - echo "has_targets=true" >> "$GITHUB_OUTPUT" |
68 | | - exit 0 |
69 | | - fi |
70 | | -
|
71 | | - # For PRs, look up labels via API |
72 | | - if [[ -z "$PR_NUMBER_FROM_EVENT" ]]; then |
73 | | - echo "matrix=[]" >> "$GITHUB_OUTPUT" |
74 | | - echo "has_targets=false" >> "$GITHUB_OUTPUT" |
75 | | - exit 0 |
76 | | - fi |
| 40 | + case "$INTENT" in |
| 41 | + -) |
| 42 | + echo "matrix=[]" >> "$GITHUB_OUTPUT" |
| 43 | + echo "has_targets=false" >> "$GITHUB_OUTPUT" |
| 44 | + ;; |
| 45 | + labels) |
| 46 | + # PR-triggered build — check labels |
| 47 | + if [[ -z "$PR_NUMBER_FROM_EVENT" ]]; then |
| 48 | + echo "matrix=[]" >> "$GITHUB_OUTPUT" |
| 49 | + echo "has_targets=false" >> "$GITHUB_OUTPUT" |
| 50 | + exit 0 |
| 51 | + fi |
77 | 52 |
|
78 | | - LABELS=$(gh api "repos/$REPO/pulls/$PR_NUMBER_FROM_EVENT" --jq '[.labels[].name]') |
| 53 | + LABELS=$(gh api "repos/$REPO/pulls/$PR_NUMBER_FROM_EVENT" --jq '[.labels[].name]') |
79 | 54 |
|
80 | | - if echo "$LABELS" | jq -e 'index("deploy:*")' > /dev/null 2>&1; then |
81 | | - echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
82 | | - echo "has_targets=true" >> "$GITHUB_OUTPUT" |
83 | | - elif echo "$LABELS" | jq -e '[.[] | select(startswith("deploy:"))] | length > 0' > /dev/null 2>&1; then |
84 | | - TYPES=$(echo "$LABELS" | jq -c '[.[] | select(startswith("deploy:")) | ltrimstr("deploy:")]') |
85 | | - echo "matrix=$TYPES" >> "$GITHUB_OUTPUT" |
86 | | - echo "has_targets=true" >> "$GITHUB_OUTPUT" |
87 | | - elif echo "$LABELS" | jq -e 'index("deploy")' > /dev/null 2>&1; then |
88 | | - echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
89 | | - echo "has_targets=true" >> "$GITHUB_OUTPUT" |
90 | | - else |
91 | | - echo "matrix=[]" >> "$GITHUB_OUTPUT" |
92 | | - echo "has_targets=false" >> "$GITHUB_OUTPUT" |
93 | | - fi |
| 55 | + if echo "$LABELS" | jq -e 'index("deploy:*")' > /dev/null 2>&1; then |
| 56 | + echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
| 57 | + echo "has_targets=true" >> "$GITHUB_OUTPUT" |
| 58 | + elif echo "$LABELS" | jq -e '[.[] | select(startswith("deploy:"))] | length > 0' > /dev/null 2>&1; then |
| 59 | + TYPES=$(echo "$LABELS" | jq -c '[.[] | select(startswith("deploy:")) | ltrimstr("deploy:")]') |
| 60 | + echo "matrix=$TYPES" >> "$GITHUB_OUTPUT" |
| 61 | + echo "has_targets=true" >> "$GITHUB_OUTPUT" |
| 62 | + elif echo "$LABELS" | jq -e 'index("deploy")' > /dev/null 2>&1; then |
| 63 | + echo "matrix=$ALL_TYPES" >> "$GITHUB_OUTPUT" |
| 64 | + echo "has_targets=true" >> "$GITHUB_OUTPUT" |
| 65 | + else |
| 66 | + echo "matrix=[]" >> "$GITHUB_OUTPUT" |
| 67 | + echo "has_targets=false" >> "$GITHUB_OUTPUT" |
| 68 | + fi |
| 69 | + ;; |
| 70 | + *) |
| 71 | + # Specific compute_type from push-to-main or workflow_dispatch |
| 72 | + echo "matrix=[\"$INTENT\"]" >> "$GITHUB_OUTPUT" |
| 73 | + echo "has_targets=true" >> "$GITHUB_OUTPUT" |
| 74 | + ;; |
| 75 | + esac |
94 | 76 |
|
95 | 77 | deploy: |
96 | 78 | needs: resolve-targets |
|
0 commit comments