1- name : 👽 Atmos Pro Determine Affected Stacks
2- run-name : 👽 Atmos Pro Determine Affected Stacks
1+ name : Atmos Pro
2+ run-name : Atmos Pro
33
44# Atmos Pro reacts to events defined in the Atmos stack settings
55# and will trigger the appropriate workflows for the given event.
66#
77# For example, pull requests opened, synchronize, and reopened will trigger plan workflows.
8- # Whereas pull requests merged will trigger apply workflows
8+ # Whereas pull requests merged will trigger apply workflows.
99on :
1010 pull_request :
1111 types :
1717 - main
1818
1919# Avoid conflicting workflow triggers.
20- # For example, wait to trigger apply until plan has been triggered
20+ # For example, wait to trigger apply until plan has been triggered.
2121concurrency :
2222 group : " ${{ github.ref }}"
2323 cancel-in-progress : false
2424
2525permissions :
26- id-token : write # This is required for requesting the JWT (OIDC) token
27- contents : read # This is required for actions/checkout
26+ id-token : write # Required for requesting the JWT (OIDC) token
27+ contents : read # Required for actions/checkout
2828
2929jobs :
3030 affected :
@@ -36,39 +36,41 @@ jobs:
3636 - " tag=affected-stacks"
3737 - " private=false"
3838
39- # Trigger Atmos Pro for Pull Request plan events and specifically closed PRs that have been merged (not just closed)
40- # Skip if the PR has the "no-apply" label
39+ # Trigger for PR plan events and specifically closed PRs that have been merged (not just closed).
40+ # Skip if the PR has the "no-apply" label.
4141 if : |
4242 !contains(github.event.pull_request.labels.*.name, 'no-apply') &&
4343 (github.event.action != 'closed' || (github.event.action == 'closed' && github.event.pull_request.merged == true))
4444
4545 steps :
46- - uses : runs-on/action@v1
46+ - uses : runs-on/action@v2
47+
48+ # Checkout the PR head SHA so the uploaded HeadSHA matches the webhook trigger event.
4749 - name : Checkout
48- # For merged PRs, we will need to checkout the base branch to get the correct base branch SHA.
49- # This isn't necessary for other events.
50- if : github.event.action == 'closed'
5150 uses : actions/checkout@v6
5251 with :
53- fetch-depth : 0 # Fetch all history for all branches and tags
52+ ref : ${{ github.event.pull_request.head.sha }}
53+ fetch-depth : 0
54+
55+ - name : Install Atmos
56+ uses : cloudposse/github-action-setup-atmos@v3
57+ with :
58+ install-wrapper : false
59+ atmos-version : ${{ vars.ATMOS_VERSION }}
5460
55- # For merged PRs, we want to use 1 previous commit from the base branch SHA
56- # This is because by the time this workflow runs, the PR branch has already been merged.
57- # It's critical to use the base branch SHA to get the correct changes, not the previous commit from the PR branch.
58- - name : Determine previous commit on base branch
59- id : get_parent
60- if : github.event.action == 'closed'
61+ # For merged PRs, use HEAD~1 to get the commit before the merge.
62+ # For open PRs, use the PR base SHA directly.
63+ - name : Determine base ref
64+ id : refs
6165 shell : bash
6266 run : |
63- # For squash merges, github.event.pull_request.base.sha represents the state of the base branch
64- # when the PR was created (or last updated). This may be stale compared to the actual commit
65- # on the main branch at the time of the merge. Using 'HEAD~1' after the merge ensures we get
66- # the commit that was the tip of main immediately before the squash merge commit was added.
67- echo "Merge commit: $(git rev-parse HEAD)"
68- PARENT=$(git rev-parse HEAD~1)
69- echo "Parent (base) commit: $PARENT"
70- echo "merge_commit=$MERGE_COMMIT" >> "$GITHUB_OUTPUT"
71- echo "parent_commit=$PARENT" >> "$GITHUB_OUTPUT"
67+ if [[ "${{ github.event.action }}" == "closed" ]]; then
68+ PARENT=$(git rev-parse HEAD~1)
69+ echo "base_ref=$PARENT" >> "$GITHUB_OUTPUT"
70+ else
71+ echo "base_ref=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
72+ fi
73+ echo "head_ref=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
7274
7375 - name : Assume Planner Role
7476 uses : aws-actions/configure-aws-credentials@v6
@@ -79,16 +81,13 @@ jobs:
7981 mask-aws-account-id : " no"
8082
8183 - name : Determine Affected Stacks
82- id : affected
83- uses : cloudposse/github-action-atmos-affected-stacks@v6
84+ shell : bash
8485 env :
8586 ATMOS_PRO_WORKSPACE_ID : ${{ vars.ATMOS_PRO_WORKSPACE_ID }}
8687 ATMOS_PROFILE : " github-plan"
87- with :
88- atmos-version : ${{ vars.ATMOS_VERSION }}
89- atmos-config-path : ${{ vars.ATMOS_CONFIG_PATH }}
90- atmos-pro-upload : true
91- # Compare the head of the PR to the base of the PR if the PR is not merged.
92- # If the PR is merged, compare the head of the PR to 1 previous commit on the base branch.
93- head-ref : ${{ github.event.pull_request.head.sha }}
94- base-ref : ${{ github.event.action == 'closed' && steps.get_parent.outputs.parent_commit || github.event.pull_request.base.sha }}
88+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
89+ run : |
90+ atmos describe affected \
91+ --ref ${{ steps.refs.outputs.head_ref }} \
92+ --sha ${{ steps.refs.outputs.base_ref }} \
93+ --upload
0 commit comments