|
| 1 | +name: 👽 Atmos Pro Determine Affected Stacks |
| 2 | +run-name: 👽 Atmos Pro Determine Affected Stacks |
| 3 | + |
| 4 | +# Atmos Pro reacts to events defined in the Atmos stack settings |
| 5 | +# and will trigger the appropriate workflows for the given event. |
| 6 | +# |
| 7 | +# For example, pull requests opened, synchronize, and reopened will trigger plan workflows. |
| 8 | +# Whereas pull requests merged will trigger apply workflows |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - synchronize |
| 14 | + - reopened |
| 15 | + - closed |
| 16 | + branches: |
| 17 | + - main |
| 18 | + |
| 19 | +# Avoid conflicting workflow triggers. |
| 20 | +# For example, wait to trigger apply until plan has been triggered |
| 21 | +concurrency: |
| 22 | + group: "${{ github.ref }}" |
| 23 | + cancel-in-progress: false |
| 24 | + |
| 25 | +permissions: |
| 26 | + id-token: write # This is required for requesting the JWT (OIDC) token |
| 27 | + contents: read # This is required for actions/checkout |
| 28 | + |
| 29 | +jobs: |
| 30 | + affected: |
| 31 | + name: Trigger Affected Stacks |
| 32 | + |
| 33 | + runs-on: |
| 34 | + - "runs-on=${{ github.run_id }}" |
| 35 | + - "runner=small" |
| 36 | + - "tag=affected-stacks" |
| 37 | + - "private=false" |
| 38 | + |
| 39 | + # Trigger Atmos Pro for Pull Request plan events and specifically closed PRs that have been merged (not just closed) |
| 40 | + if: github.event.action != 'closed' || (github.event.action == 'closed' && github.event.pull_request.merged == true) |
| 41 | + |
| 42 | + steps: |
| 43 | + - uses: runs-on/action@v1 |
| 44 | + - name: Checkout |
| 45 | + # For merged PRs, we will need to checkout the base branch to get the correct base branch SHA. |
| 46 | + # This isn't necessary for other events. |
| 47 | + if: github.event.action == 'closed' |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 # Fetch all history for all branches and tags |
| 51 | + |
| 52 | + # For merged PRs, we want to use 1 previous commit from the base branch SHA |
| 53 | + # This is because by the time this workflow runs, the PR branch has already been merged. |
| 54 | + # It's critical to use the base branch SHA to get the correct changes, not the previous commit from the PR branch. |
| 55 | + - name: Determine previous commit on base branch |
| 56 | + id: get_parent |
| 57 | + if: github.event.action == 'closed' |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + # For squash merges, github.event.pull_request.base.sha represents the state of the base branch |
| 61 | + # when the PR was created (or last updated). This may be stale compared to the actual commit |
| 62 | + # on the main branch at the time of the merge. Using 'HEAD~1' after the merge ensures we get |
| 63 | + # the commit that was the tip of main immediately before the squash merge commit was added. |
| 64 | + echo "Merge commit: $(git rev-parse HEAD)" |
| 65 | + PARENT=$(git rev-parse HEAD~1) |
| 66 | + echo "Parent (base) commit: $PARENT" |
| 67 | + echo "merge_commit=$MERGE_COMMIT" >> "$GITHUB_OUTPUT" |
| 68 | + echo "parent_commit=$PARENT" >> "$GITHUB_OUTPUT" |
| 69 | +
|
| 70 | + - name: Determine Affected Stacks |
| 71 | + id: affected |
| 72 | + uses: cloudposse/github-action-atmos-affected-stacks@v6 |
| 73 | + env: |
| 74 | + ATMOS_PRO_WORKSPACE_ID: ${{ vars.ATMOS_PRO_WORKSPACE_ID }} |
| 75 | + with: |
| 76 | + atmos-version: ${{ vars.ATMOS_VERSION }} |
| 77 | + atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }} |
| 78 | + atmos-pro-upload: true |
| 79 | + # Compare the head of the PR to the base of the PR if the PR is not merged. |
| 80 | + # If the PR is merged, compare the head of the PR to 1 previous commit on the base branch. |
| 81 | + head-ref: ${{ github.event.pull_request.head.sha }} |
| 82 | + base-ref: ${{ github.event.action == 'closed' && steps.get_parent.outputs.parent_commit || github.event.pull_request.base.sha }} |
0 commit comments