Skip to content

Commit 525f355

Browse files
milldrBenbentwocloudpossebot
authored
Merged Workflows (#777)
Co-authored-by: Benbentwo <14911525+Benbentwo@users.noreply.github.com> Co-authored-by: Cloud Posse Bot (CI/CD) <bot@cloudposse.com> Co-authored-by: milldr <14060048+milldr@users.noreply.github.com>
1 parent e18e7eb commit 525f355

13 files changed

+199
-41
lines changed

examples/snippets/.github/workflows/atmos-components-updater.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ on:
99
jobs:
1010
update:
1111
environment: atmos
12-
runs-on: ["self-hosted", "default"]
12+
runs-on:
13+
- self-hosted
14+
- terraform
1315
steps:
1416
- name: "Checkout source code at current commit"
1517
uses: actions/checkout@v4
Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
1-
name: Atmos Pro Terraform Apply
1+
name: 👽 Atmos Pro Terraform Apply
2+
run-name: apply ${{ inputs.component }}/${{ inputs.stack }}/${{ inputs.atmos_pro_run_id}}
23

34
on:
4-
workflow_call:
5+
workflow_dispatch:
56
inputs:
7+
atmos_pro_run_id:
8+
description: "Atmos Pro Run ID"
9+
type: string
10+
sha:
11+
description: "Commit SHA"
12+
type: string
13+
component:
14+
description: "Component"
15+
required: true
16+
type: string
617
stack:
18+
description: "Stack"
719
required: true
820
type: string
9-
component:
21+
github_environment:
22+
description: "GitHub Environment"
1023
required: true
1124
type: string
1225

26+
# Avoid running the same stack in parallel mode (from different workflows)
27+
# This applied to across workflows to both plan and apply
28+
concurrency:
29+
group: "${{ inputs.stack }}-${{ inputs.component }}"
30+
cancel-in-progress: false
31+
32+
permissions:
33+
id-token: write # This is required for requesting the JWT
34+
contents: read # This is required for actions/checkout
35+
1336
jobs:
14-
apply:
15-
runs-on: ubuntu-latest
37+
atmos-apply:
38+
name: ${{ inputs.component }}-${{ inputs.stack }}
39+
40+
# The GitHub environment is defined in Atmos Pro settings.
41+
# Typically this is <tenant>-<stage>
42+
environment: ${{ inputs.github_environment }}
43+
44+
runs-on:
45+
- "runs-on=${{ github.run_id }}"
46+
- "runner=terraform"
47+
- "tag=${{ inputs.component }}-${{ inputs.stack }}"
48+
- "private=false"
49+
1650
steps:
17-
- name: Terraform Apply
18-
uses: cloudposse/github-action-atmos-pro-terraform-apply@main
51+
- uses: runs-on/action@v1
52+
- uses: unfor19/install-aws-cli-action@v1
53+
54+
- name: Apply Atmos Component
55+
uses: cloudposse/github-action-atmos-terraform-apply@v4
1956
with:
20-
workspace-id: ${{ vars.ATMOS_PRO_WORKSPACE_ID }}
21-
api-key: ${{ secrets.ATMOS_PRO_API_KEY }}
57+
# Atmos Pro args
58+
component: ${{ inputs.component }}
2259
stack: ${{ inputs.stack }}
23-
component: ${{ inputs.component }}
60+
sha: ${{ inputs.sha }}
61+
# Atmos required configuration
62+
atmos-version: ${{ vars.ATMOS_VERSION }}
63+
atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }}
64+
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,56 @@
1-
name: Atmos Pro Terraform Plan
1+
name: 👽 Atmos Pro Terraform Plan
2+
run-name: plan ${{ inputs.component }}/${{ inputs.stack }}/${{ inputs.atmos_pro_run_id}}
23

34
on:
4-
workflow_call:
5+
workflow_dispatch:
56
inputs:
6-
stack:
7-
required: true
7+
atmos_pro_run_id:
8+
description: "Atmos Pro Run ID"
9+
type: string
10+
sha:
11+
description: "Commit SHA"
812
type: string
913
component:
14+
description: "Component"
15+
required: true
16+
type: string
17+
stack:
18+
description: "Stack"
1019
required: true
1120
type: string
1221

22+
# Avoid running the same stack in parallel mode (from different workflows)
23+
# This applied to across workflows to both plan and apply
24+
concurrency:
25+
group: "${{ inputs.stack }}-${{ inputs.component }}"
26+
cancel-in-progress: false
27+
28+
permissions:
29+
id-token: write # This is required for requesting the JWT (OIDC) token
30+
contents: read # This is required for actions/checkout
31+
1332
jobs:
14-
plan:
15-
runs-on: ubuntu-latest
33+
atmos-plan:
34+
name: ${{ inputs.component }}-${{ inputs.stack }}
35+
36+
runs-on:
37+
- "runs-on=${{ github.run_id }}"
38+
- "runner=terraform"
39+
- "tag=${{ inputs.component }}-${{ inputs.stack }}"
40+
- "private=false"
41+
1642
steps:
17-
- name: Terraform Plan
18-
uses: cloudposse/github-action-atmos-pro-terraform-plan@main
43+
- uses: runs-on/action@v1
44+
- uses: unfor19/install-aws-cli-action@v1
45+
46+
- name: Plan Atmos Component
47+
uses: cloudposse/github-action-atmos-terraform-plan@v5
1948
with:
20-
workspace-id: ${{ vars.ATMOS_PRO_WORKSPACE_ID }}
21-
api-key: ${{ secrets.ATMOS_PRO_API_KEY }}
49+
# Atmos Pro args
50+
component: ${{ inputs.component }}
2251
stack: ${{ inputs.stack }}
23-
component: ${{ inputs.component }}
52+
sha: ${{ inputs.sha }}
53+
# Atmos required configuration
54+
atmos-version: ${{ vars.ATMOS_VERSION }}
55+
atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }}
56+
Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,83 @@
1-
name: Atmos Pro
1+
name: 👽 Atmos Pro Determine Affected Stacks
2+
run-name: 👽 Atmos Pro Determine Affected Stacks
23

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
39
on:
410
pull_request:
5-
types: [opened, synchronize, reopened]
6-
workflow_dispatch:
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
728

829
jobs:
9-
describe-affected:
10-
runs-on: ubuntu-latest
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+
1142
steps:
12-
- name: Describe Affected
13-
uses: cloudposse/github-action-atmos-pro-describe-affected@main
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
1449
with:
15-
workspace-id: ${{ vars.ATMOS_PRO_WORKSPACE_ID }}
16-
api-key: ${{ secrets.ATMOS_PRO_API_KEY }}
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 }}
83+

examples/snippets/.github/workflows/atmos-terraform-apply-matrix.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ jobs:
3131
atmos-apply:
3232
if: ${{ inputs.stacks != '{include:[]}' }}
3333
name: ${{ matrix.stack_slug }}
34-
runs-on: ["self-hosted", "terraform"]
34+
runs-on:
35+
- self-hosted
36+
- terraform
3537
strategy:
3638
max-parallel: 10
3739
fail-fast: false # Don't fail fast to avoid locking TF State

examples/snippets/.github/workflows/atmos-terraform-apply.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
name: Determine Affected Stacks
3535
if: needs.pr.outputs.no-apply == 'false'
3636
needs: ["pr"]
37-
runs-on: ["self-hosted", "terraform"]
37+
runs-on:
38+
- self-hosted
39+
- terraform
3840
steps:
3941
- id: affected
4042
uses: cloudposse/github-action-atmos-affected-stacks@v4

examples/snippets/.github/workflows/atmos-terraform-dispatch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ permissions:
2828

2929
jobs:
3030
dispatch-id:
31-
runs-on: ["self-hosted", "terraform"]
31+
runs-on:
32+
- self-hosted
33+
- terraform
3234
steps:
3335
- name: echo Distinct ID ${{ github.event.inputs.distinct_id }}
3436
run: echo ${{ github.event.inputs.distinct_id }}

examples/snippets/.github/workflows/atmos-terraform-drift-detection.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ permissions:
1717
jobs:
1818
select-components:
1919
name: Select Components
20-
runs-on: ["self-hosted", "terraform"]
20+
runs-on:
21+
- self-hosted
22+
- terraform
2123
steps:
2224
- name: Selected Components
2325
id: components
@@ -52,7 +54,7 @@ jobs:
5254
needs: ["plan-atmos-components"]
5355
if: always()
5456
name: Reconcile issues
55-
runs-on: ["self-hosted", "terraform"]
57+
runs-on: ['self-hosted', 'terraform']
5658
steps:
5759
- name: Drift Detection
5860
uses: cloudposse/github-action-atmos-terraform-drift-detection@v2

examples/snippets/.github/workflows/atmos-terraform-drift-remediation.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
remediate-drift:
1717
if: github.event.action == 'labeled' && contains(github.event.issue.labels.*.name, 'apply')
1818
name: Remediate Drift
19-
runs-on: ["self-hosted", "terraform"]
19+
runs-on:
20+
- self-hosted
21+
- terraform
2022
steps:
2123
- uses: unfor19/install-aws-cli-action@v1
2224
- name: Remediate Drift
@@ -35,7 +37,7 @@ jobs:
3537
) &&
3638
!contains(github.event.issue.labels.*.name, 'remediated')
3739
name: Discard Drift
38-
runs-on: ["self-hosted", "terraform"]
40+
runs-on: ['self-hosted', 'terraform']
3941
steps:
4042
- name: Discard Drift
4143
uses: cloudposse/github-action-atmos-terraform-drift-remediation@v2

examples/snippets/.github/workflows/atmos-terraform-plan-matrix.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ jobs:
4141
atmos-plan:
4242
if: ${{ inputs.stacks != '{include:[]}' }}
4343
name: ${{ matrix.stack_slug }}
44-
runs-on: ["self-hosted", "terraform"]
44+
runs-on:
45+
- self-hosted
46+
- terraform
4547
continue-on-error: ${{ inputs.continue-on-error == 'true' }}
4648
strategy:
4749
max-parallel: 10

0 commit comments

Comments
 (0)