Skip to content

Commit c6ce879

Browse files
milldrgoruha
andauthored
feat: Report GitHub Summaries with Atmos Pro (#101)
* check either atmos pro or github actions enabled * adding tests * Add pull request trigger for Atmos Pro Enabled tests * Enabled all tests * removed unnecessary triggers * Add atmos version 1.174.0 to atmos-pro-enabled workflow * Update foobar-atmos-pro.yaml * Update action.yml * fixed tests * fixed tests --------- Co-authored-by: Igor Rodionov <goruha@gmail.com>
1 parent f08a7b8 commit c6ce879

File tree

6 files changed

+200
-9
lines changed

6 files changed

+200
-9
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: "Test - Atmos Pro Enabled"
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
env:
10+
AWS_REGION: us-east-2
11+
12+
# Permissions required for assuming AWS identity
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
jobs:
18+
setup:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Setup
22+
run: echo "Do setup"
23+
24+
test:
25+
runs-on: ubuntu-latest
26+
continue-on-error: true
27+
needs: [setup]
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.pull_request.head.ref }}
32+
33+
- shell: bash
34+
run: |
35+
mkdir -p ${{ runner.temp }}
36+
cp ./tests/terraform/atmos.yaml ${{ runner.temp }}/atmos.yaml
37+
sed -i -e 's#__INFRACOST_ENABLED__#false#g' ${{ runner.temp }}/atmos.yaml
38+
sed -i -e 's#__STORAGE_REGION__#${{ env.AWS_REGION }}#g' ${{ runner.temp }}/atmos.yaml
39+
sed -i -e 's#__STORAGE_BUCKET__#${{ secrets.TERRAFORM_STATE_BUCKET }}#g' ${{ runner.temp }}/atmos.yaml
40+
sed -i -e 's#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g' ${{ runner.temp }}/atmos.yaml
41+
sed -i -e 's#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g' ${{ runner.temp }}/atmos.yaml
42+
sed -i -e 's#__STORAGE_ROLE__#${{ secrets.TERRAFORM_STATE_ROLE }}#g' ${{ runner.temp }}/atmos.yaml
43+
sed -i -e 's#__PLAN_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g' ${{ runner.temp }}/atmos.yaml
44+
sed -i -e 's#__APPLY_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g' ${{ runner.temp }}/atmos.yaml
45+
46+
for file in ./tests/terraform/stacks/catalog/*.yaml; do
47+
if [ -f "$file" ]; then
48+
sed -i -e "s#__INFRACOST_ENABLED__#false#g" "$file"
49+
sed -i -e "s#__STORAGE_REGION__#${{ env.AWS_REGION }}#g" "$file"
50+
sed -i -e "s#__STORAGE_BUCKET__#${{ secrets.TERRAFORM_STATE_BUCKET }}#g" "$file"
51+
sed -i -e "s#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g" "$file"
52+
sed -i -e "s#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g" "$file"
53+
sed -i -e "s#__STORAGE_ROLE__#${{ secrets.TERRAFORM_STATE_ROLE }}#g" "$file"
54+
sed -i -e "s#__PLAN_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g" "$file"
55+
sed -i -e "s#__APPLY_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g" "$file"
56+
fi
57+
done
58+
59+
cat ${{ runner.temp }}/atmos.yaml
60+
61+
- name: Plan Atmos Pro Component
62+
id: current
63+
uses: ./
64+
with:
65+
component: "foobar-atmos-pro"
66+
stack: "plat-ue2-sandbox"
67+
sha: ${{ github.sha }}
68+
atmos-config-path: ${{ runner.temp }}
69+
atmos-version: ">= 1.174.0"
70+
skip-checkout: false
71+
72+
outputs:
73+
result: ${{ steps.current.outcome }}
74+
summary: ${{ steps.current.outputs.summary }}
75+
76+
assert:
77+
runs-on: ubuntu-latest
78+
needs: [test]
79+
steps:
80+
- uses: nick-fields/assert-action@v2
81+
with:
82+
expected: 'success'
83+
actual: "${{ needs.test.outputs.result }}"
84+
85+
- name: Display structure of downloaded files
86+
id: metadata
87+
run: |
88+
set +e
89+
90+
test -d ./metadata
91+
DIR_EXISTS=$?
92+
echo "dir_exists=${DIR_EXISTS}" >> $GITHUB_OUTPUT
93+
94+
- uses: nick-fields/assert-action@v2
95+
with:
96+
actual: "${{ steps.metadata.outputs.dir_exists }}"
97+
expected: "1"
98+
99+
- uses: nick-fields/assert-action@v2
100+
with:
101+
actual: "${{ fromJSON(needs.test.outputs.summary) }}"
102+
expected: |
103+
## Changes Found for `foobar-atmos-pro` in `plat-ue2-sandbox`
104+
105+
<a href="https://cloudposse.com/"><img src="https://cloudposse.com/logo-300x69.svg" width="100px" align="right"/></a>
106+
[![create](https://shields.io/badge/PLAN-CREATE-success?style=for-the-badge)](#user-content-create-plat-ue2-sandbox-foobar-atmos-pro)
107+
108+
109+
110+
<details><summary><a id="result-plat-ue2-sandbox-foobar-atmos-pro" />Plan: 1 to add, 0 to change, 0 to destroy.</summary>
111+
112+
<br/>
113+
To reproduce this locally, run:<br/><br/>
114+
115+
```shell
116+
atmos terraform plan foobar-atmos-pro -s plat-ue2-sandbox
117+
```
118+
119+
120+
121+
122+
---
123+
### <a id="create-plat-ue2-sandbox-foobar-atmos-pro" />Create
124+
```diff
125+
+ random_id.foo[0]
126+
```
127+
128+
</details>
129+
130+
<details><summary>Terraform <strong>Plan</strong> Summary</summary>
131+
132+
```hcl
133+
134+
# random_id.foo[0] will be created
135+
+ resource "random_id" "foo" {
136+
+ b64_std = (known after apply)
137+
+ b64_url = (known after apply)
138+
+ byte_length = 8
139+
+ dec = (known after apply)
140+
+ hex = (known after apply)
141+
+ id = (known after apply)
142+
+ keepers = {
143+
+ "seed" = "foo-plat-ue2-sandbox-blue"
144+
}
145+
}
146+
147+
Plan: 1 to add, 0 to change, 0 to destroy.
148+
```
149+
150+
</details>
151+
152+
teardown:
153+
runs-on: ubuntu-latest
154+
needs: [assert]
155+
if: ${{ always() }}
156+
steps:
157+
- name: Tear down
158+
run: echo "Do Tear down"

action.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ runs:
103103
- component: ${{ inputs.component }}
104104
stack: ${{ inputs.stack }}
105105
settingsPath: settings.github.actions_enabled
106-
outputPath: enabled
106+
outputPath: github-actions-enabled
107+
- component: ${{ inputs.component }}
108+
stack: ${{ inputs.stack }}
109+
settingsPath: settings.pro.enabled
110+
outputPath: atmos-pro-enabled
107111
- component: ${{ inputs.component }}
108112
stack: ${{ inputs.stack }}
109113
settingsPath: component_info.component_path
@@ -241,21 +245,21 @@ runs:
241245
mask-aws-account-id: "no"
242246

243247
- name: Set atmos cli base path vars
244-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
248+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
245249
shell: bash
246250
run: |-
247251
# Set ATMOS_BASE_PATH allow `cloudposse/utils` provider to read atmos config from the correct path
248252
ATMOS_BASE_PATH="${{ fromJson(steps.atmos-settings.outputs.settings).base-path }}"
249253
echo "ATMOS_BASE_PATH=$(realpath ${ATMOS_BASE_PATH:-./})" >> $GITHUB_ENV
250254
251255
- name: Prepare Artifacts Directory
252-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
256+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
253257
shell: bash
254258
run: |
255259
mkdir -p metadata
256260
257261
- name: Define Job Variables
258-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
262+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
259263
id: vars
260264
shell: bash
261265
run: |
@@ -288,14 +292,14 @@ runs:
288292
- name: Cache .terraform
289293
id: cache
290294
uses: actions/cache@v4
291-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
295+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
292296
with:
293297
path: |
294298
./${{ steps.vars.outputs.component_path }}/.terraform
295299
key: ${{ steps.vars.outputs.cache-key }}
296300

297301
- name: Atmos Terraform Plan
298-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
302+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
299303
id: atmos-plan
300304
shell: bash
301305
run: |
@@ -533,7 +537,7 @@ runs:
533537
sed -i -e '/%INFRACOST_DIFF%/{r /tmp/infracost.txt' -e 'd}' ${{ steps.vars.outputs.step_summary_file }}
534538
535539
- name: Store Component Metadata to Artifacts
536-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled && inputs.drift-detection-mode-enabled == 'true' }}
540+
if: ${{ (fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled) && inputs.drift-detection-mode-enabled == 'true' }}
537541
shell: bash
538542
run: |
539543
echo -n '{ "stack": "${{ inputs.stack }}", "component": "${{ inputs.component }}", "componentPath": "${{ steps.vars.outputs.component_path }}", "drifted": '"${{ steps.atmos-plan.outputs.changes }}"', "error": '"${{ steps.atmos-plan.outputs.error }}"' }' > "metadata/${{ steps.vars.outputs.component_slug }}.metadata.json"
@@ -577,7 +581,7 @@ runs:
577581
echo "rand=$(openssl rand -hex 5)" >> "$GITHUB_OUTPUT"
578582
579583
- name: Upload Artifacts
580-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled && inputs.drift-detection-mode-enabled == 'true' }}
584+
if: ${{ (fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled) && inputs.drift-detection-mode-enabled == 'true' }}
581585
uses: actions/upload-artifact@v4
582586
with:
583587
# The name of the artifact needs to be unique for every job run!
@@ -587,7 +591,7 @@ runs:
587591
retention-days: ${{ inputs.metadata-retention-days }}
588592

589593
- name: Exit status
590-
if: ${{ fromJson(steps.atmos-settings.outputs.settings).enabled }}
594+
if: ${{ fromJson(steps.atmos-settings.outputs.settings).github-actions-enabled || fromJson(steps.atmos-settings.outputs.settings).atmos-pro-enabled }}
591595
shell: bash
592596
run: |
593597
exit ${{ steps.atmos-plan.outputs.result }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
components:
2+
terraform:
3+
foobar-atmos-pro:
4+
metadata:
5+
component: foobar
6+
settings:
7+
pro:
8+
enabled: true
9+
github:
10+
actions_enabled: false
11+
vars:
12+
example: blue
13+
enabled: true

tests/opentofu/stacks/orgs/foo/plat/sandbox/plat-ue2-sandbox.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import:
33
- catalog/foobar-fail
44
- catalog/foobar-changes
55
- catalog/foobar-disabled
6+
- catalog/foobar-atmos-pro
67

78
terraform:
89
backend_type: local
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
components:
2+
terraform:
3+
foobar-atmos-pro:
4+
metadata:
5+
component: foobar
6+
settings:
7+
pro:
8+
enabled: true
9+
github:
10+
actions_enabled: false
11+
vars:
12+
example: blue
13+
enabled: true
14+

tests/terraform/stacks/orgs/foo/plat/sandbox/plat-ue2-sandbox.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import:
33
- catalog/foobar-fail
44
- catalog/foobar-changes
55
- catalog/foobar-disabled
6+
- catalog/foobar-atmos-pro
67

78
terraform:
89
backend_type: local

0 commit comments

Comments
 (0)