@@ -16,18 +16,15 @@ jobs:
1616 uses : actions/setup-go@v5
1717 with :
1818 go-version : ' 1.18'
19- id : go
2019
21- - name : Check out code into the Go module directory
20+ - name : Check out code
2221 uses : actions/checkout@v4
2322
2423 - name : Get dependencies
25- run : |
26- go mod download
24+ run : go mod download
2725
2826 - name : Build
29- run : |
30- go build -v .
27+ run : go build -v .
3128
3229 drift :
3330 name : " Drift Detection (TF ${{ matrix.terraform }})"
@@ -37,12 +34,11 @@ jobs:
3734 max-parallel : 1
3835 fail-fast : false
3936 matrix :
40- terraform : [
41- ' 0.15.5' ,
42- ' 0.14.11' ,
43- ' 1.1.2' ,
44- ' 1.5.3'
45- ]
37+ terraform :
38+ - ' 0.15.5'
39+ - ' 0.14.11'
40+ - ' 1.1.2'
41+ - ' 1.5.3'
4642 env :
4743 TF_VAR_aquasec_url : ${{ secrets.AQUA_URL }}
4844 TF_VAR_aquasec_username : ${{ secrets.AQUA_USER }}
@@ -77,13 +73,25 @@ jobs:
7773 terraform plan -input=false -detailed-exitcode -out=tfplan.binary
7874 exitcode=$?
7975 echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
80- # Fail for both drift (2) and error (1)
76+ # exit code 0 = no changes, 2 = changes (drift detected), 1 = error
8177 if [ "$exitcode" -ne 0 ]; then
8278 exit $exitcode
8379 fi
8480
85- outputs :
86- drifted : ${{ steps.plan.outputs.exitcode }}
81+ - name : Write result file
82+ run : |
83+ version="${{ matrix.terraform }}"
84+ exitcode="${{ steps.plan.outputs.exitcode }}"
85+ if [ -z "$exitcode" ]; then
86+ exitcode=99 # choose a default, e.g. 99 for unknown
87+ fi
88+ echo "{\"version\":\"${{ matrix.terraform }}\",\"exitcode\":${{ steps.plan.outputs.exitcode }}}" > result-drift-${{ matrix.terraform }}.json
89+ - name : Upload result artifact
90+ uses : actions/upload-artifact@v4
91+ with :
92+ name : drift-results-${{ matrix.terraform }}
93+ path : examples/result-drift-${{ matrix.terraform }}.json
94+ if-no-files-found : error
8795
8896 acceptance :
8997 name : " Acceptance Tests (TF ${{ matrix.terraform }})"
@@ -93,12 +101,11 @@ jobs:
93101 max-parallel : 1
94102 fail-fast : false
95103 matrix :
96- terraform : [
97- ' 0.15.5' ,
98- ' 0.14.11' ,
99- ' 1.1.2' ,
100- ' 1.5.3'
101- ]
104+ terraform :
105+ - ' 0.15.5'
106+ - ' 0.14.11'
107+ - ' 1.1.2'
108+ - ' 1.5.3'
102109 env :
103110 AQUA_URL : ${{ secrets.AQUA_URL }}
104111 AQUA_USER : ${{ secrets.AQUA_USER }}
@@ -108,52 +115,129 @@ jobs:
108115 uses : actions/setup-go@v5
109116 with :
110117 go-version : ' 1.18'
111- id : go
112118
113119 - name : Check out repo
114120 uses : actions/checkout@v4
115121
116122 - name : Get dependencies
117- run : |
118- go mod download
123+ run : go mod download
119124
120125 - name : Run TF acceptance tests
121126 id : accept_tests
122127 uses : nick-fields/retry@v2
128+ with :
129+ max_attempts : 2
130+ timeout_minutes : 15
131+ command : go test -v -cover ./aquasec/ -timeout 15m
123132 env :
124133 TF_ACC : " 1"
125134 TF_ACC_TERRAFORM_VERSION : ${{ matrix.terraform }}
126135 AQUA_URL : ${{ secrets.AQUA_URL }}
127136 AQUA_USER : ${{ secrets.AQUA_USER }}
128137 AQUA_PASSWORD : ${{ secrets.AQUA_PASSWORD }}
129- with :
130- max_attempts : 2
131- timeout_minutes : 15
132- command : go test -v -cover ./aquasec/ -timeout 15m
133138
134- outputs :
135- accepted : ${{ steps.accept_tests.outcome }}
139+ - name : Write acceptance result file
140+ run : |
141+ version="${{ matrix.terraform }}"
142+ outcome="${{ steps.accept_tests.outcome }}"
143+ # If outcome is empty or weird, default to "unknown"
144+ if [ -z "$outcome" ]; then
145+ outcome="unknown"
146+ fi
147+ result="failure"
148+ if [ "${{ steps.accept_tests.outcome }}" = "success" ]; then
149+ result="success"
150+ fi
151+ echo "{\"version\":\"${{ matrix.terraform }}\",\"result\":\"${result}\"}" > result-acceptance-${{ matrix.terraform }}.json
152+ - name : Debug before upload
153+ run : |
154+ echo "Current directory: $(pwd)"
155+ ls -la .
156+ - name : Upload acceptance result artifact
157+ uses : actions/upload-artifact@v4
158+ with :
159+ name : acceptance-results-${{ matrix.terraform }}
160+ path : ./result-acceptance-${{ matrix.terraform }}.json
161+ if-no-files-found : error
136162
137163 notify :
138164 name : " Notify via Power Automate Webhook"
139165 runs-on : ubuntu-latest
140- needs : [drift, acceptance]
166+ needs :
167+ - drift
168+ - acceptance
141169 if : ${{ always() }}
142170 steps :
171+ - name : Download all drift artifacts
172+ uses : actions/download-artifact@v4
173+ with :
174+ path : drift-artifacts
175+
176+ - name : Download all artifacts
177+ uses : actions/download-artifact@v4
178+ with :
179+ path : artifacts
180+
181+ - name : Build summary payload
182+ id : build_payload
183+ run : |
184+ echo "PWD: $(pwd)"
185+ ls -R artifacts
186+
187+ drift_summary="{"
188+ acc_summary="{"
189+ first=true
190+
191+ # Loop through drift artifacts
192+ for file in artifacts/drift-results-*/result-drift-*.json; do
193+ version=$(jq -r .version < "$file")
194+ exitcode=$(jq -r .exitcode < "$file")
195+ status="unknown"
196+ if [ "$exitcode" -eq 0 ]; then
197+ status="no_drift"
198+ elif [ "$exitcode" -eq 2 ]; then
199+ status="drift_detected"
200+ elif [ "$exitcode" -eq 1 ]; then
201+ status="error"
202+ fi
203+
204+ if [ "$first" = false ]; then
205+ drift_summary+=", "
206+ fi
207+ drift_summary+="\"${version}\": \"${status}\""
208+ first=false
209+ done
210+ drift_summary+="}"
211+
212+ first=true
213+ # Loop through acceptance artifacts
214+ for file in artifacts/acceptance-results-*/result-acceptance-*.json; do
215+ version=$(jq -r .version < "$file")
216+ result=$(jq -r .result < "$file")
217+
218+ if [ "$first" = false ]; then
219+ acc_summary+=", "
220+ fi
221+ acc_summary+="\"${version}\": \"${result}\""
222+ first=false
223+ done
224+ acc_summary+="}"
225+
226+ echo "payload="$(jq -n \
227+ --arg wf "${{ github.workflow }}" \
228+ --arg branch "${{ github.ref_name }}" \
229+ --arg runid "${{ github.run_id }}" \
230+ --arg url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
231+ --argjson tested_versions '["0.15.5","0.14.11","1.1.2","1.5.3"]' \
232+ --argjson drift_summary "$drift_summary" \
233+ --argjson acceptance_summary "$acc_summary" \
234+ '{workflow: $wf, branch: $branch, run_id: $runid, github_url: $url, tested_versions: $tested_versions, drift_summary: $drift_summary, acceptance_summary: $acceptance_summary }') \
235+ >> $GITHUB_OUTPUT
143236 - name : Trigger Power Automate Flow
144- uses : fjogeleit/http-request-action@v1.16.3
237+ uses : fjogeleit/http-request-action@v1.16.3
145238 with :
146239 url : ${{ secrets.POWER_AUTOMATE_HOOK_URL }}
147240 method : ' POST'
148241 contentType : ' application/json'
149242 data : |
150- {
151- "status": "${{ (needs.drift.result == 'failure' || needs.acceptance.result == 'failure') && 'FAILED' || 'PASSED' }}",
152- "branch": "main",
153- "drift_exitcode": "${{ needs.drift.outputs.drifted }}",
154- "acceptance_outcome": "${{ needs.acceptance.outputs.accepted }}",
155- "workflow": "${{ github.workflow }}",
156- "run_id": "${{ github.run_id }}",
157- "github_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
158- "tested_versions": ["0.15.5","0.14.11","1.1.2","1.5.3"]
159- }
243+ ${{ steps.build_payload.outputs.payload }}
0 commit comments