Skip to content

Commit 706474e

Browse files
authored
fix(ci): Use environment variables in workflows (#2200)
1 parent 7c48fec commit 706474e

24 files changed

Lines changed: 889 additions & 435 deletions

.github/workflows/PR-build.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ jobs:
3535
filters: .github/config/file-filters.yml
3636

3737
- name: List all updated files
38+
env:
39+
BUILD_FILES: ${{ steps.filter.outputs.build_files }}
3840
run: |
39-
for file in ${{ steps.filter.outputs.build_files }}; do
41+
for file in $BUILD_FILES; do
4042
echo "$file"
4143
done
4244
@@ -142,7 +144,10 @@ jobs:
142144

143145
- name: Build
144146
if: steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true'
145-
run: make amazon-cloudwatch-agent-${{ matrix.family }}
147+
env:
148+
MATRIX_FAMILY: ${{ matrix.family }}
149+
shell: bash
150+
run: make "amazon-cloudwatch-agent-$MATRIX_FAMILY"
146151

147152
- name: Collect binary sizes
148153
if: steps.cached_binaries.outputs.cache-hit != 'true' && needs.changes.outputs.build == 'true' && matrix.family != 'darwin' && matrix.os != 'windows-latest' && github.event_name == 'pull_request'
@@ -221,16 +226,15 @@ jobs:
221226
if: ${{ !cancelled() }}
222227
steps:
223228
- name: Check Job Status
229+
env:
230+
NEEDS_JSON: ${{ toJSON(needs) }}
224231
run: |
225-
# Convert needs context to JSON and process with jq
226-
needs_json='${{ toJSON(needs) }}'
227-
228232
failed_jobs=()
229233
successful_jobs=()
230234
231235
# Loop through all jobs in needs context
232-
for job in $(echo "$needs_json" | jq -r 'keys[]'); do
233-
result=$(echo "$needs_json" | jq -r ".[\"$job\"].result")
236+
for job in $(echo "$NEEDS_JSON" | jq -r 'keys[]'); do
237+
result=$(echo "$NEEDS_JSON" | jq -r ".[\"$job\"].result")
234238
235239
if [[ "$result" == "failure" ]]; then
236240
failed_jobs+=("$job")

.github/workflows/PR-test.yml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ jobs:
4141
should_run: ${{ steps.check.outputs.has_label }}
4242
steps:
4343
- id: check
44+
env:
45+
PR_FORK: ${{ github.event.pull_request.head.repo.fork }}
46+
HAS_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'ready for testing') }}
4447
run: |
4548
# Fork PRs never receive secrets or id-token permissions, so the
4649
# integration tests cannot run even if the label is added. Maintainers
4750
# must push the branch to this repo to run them.
48-
if [[ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]]; then
51+
if [[ "$PR_FORK" == "true" ]]; then
4952
echo "Fork PR - integration tests cannot run (no access to secrets)."
5053
echo "has_label=false" >> $GITHUB_OUTPUT
51-
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'ready for testing') }}" == "true" ]]; then
54+
elif [[ "$HAS_LABEL" == "true" ]]; then
5255
echo "has_label=true" >> $GITHUB_OUTPUT
5356
else
5457
echo "has_label=false" >> $GITHUB_OUTPUT
@@ -88,11 +91,16 @@ jobs:
8891
echo "CWA_GITHUB_TEST_REPO_BRANCH=${CWA_GITHUB_TEST_REPO_BRANCH:-${{ env.CWA_GITHUB_TEST_REPO_BRANCH }}}" >> "$GITHUB_OUTPUT"
8992
9093
- name: Echo test variables
94+
env:
95+
GITHUB_SHA_VAL: ${{ github.sha }}
96+
OUT_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }}
97+
OUT_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}
98+
OUT_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}
9199
run: |
92-
echo "build_id: ${{ github.sha }}"
93-
echo "CWA_GITHUB_TEST_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }}"
94-
echo "CWA_GITHUB_TEST_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}"
95-
echo "CWA_GITHUB_TEST_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}"
100+
echo "build_id: $GITHUB_SHA_VAL"
101+
echo "CWA_GITHUB_TEST_REPO_NAME: $OUT_REPO_NAME"
102+
echo "CWA_GITHUB_TEST_REPO_URL: $OUT_REPO_URL"
103+
echo "CWA_GITHUB_TEST_REPO_BRANCH: $OUT_REPO_BRANCH"
96104
97105
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
98106
with:
@@ -169,9 +177,12 @@ jobs:
169177
run: |
170178
# GitHub Actions matrix limit is 256 jobs per workflow run.
171179
# Use 200 per page for headroom. Up to 5 pages supported (1000 tests).
172-
# The ec2_linux_matrix is @json-encoded (double-encoded), so decode first.
180+
# Read the filtered matrix from the file written by the "Generate matrix"
181+
# step instead of a step-level env var: the matrix can exceed the
182+
# kernel's ARG_MAX (~2 MiB) on execve, which would prevent bash from
183+
# starting for this step.
173184
PAGE_SIZE=200
174-
FULL_MATRIX=$(echo '${{ steps.set-matrix.outputs.ec2_linux_matrix }}' | jq -r '.')
185+
FULL_MATRIX=$(cat filtered_matrix.json)
175186
TOTAL=$(echo "$FULL_MATRIX" | jq 'length')
176187
PAGE_COUNT=$(( (TOTAL + PAGE_SIZE - 1) / PAGE_SIZE ))
177188
@@ -190,9 +201,12 @@ jobs:
190201
done
191202
192203
- name: Echo test plan matrix
204+
env:
205+
EC2_LINUX_PAGE_COUNT: ${{ steps.paginate-matrix.outputs.ec2_linux_matrix_page_count }}
206+
EC2_SELINUX_MATRIX: ${{ steps.set-matrix.outputs.ec2_selinux_matrix }}
193207
run: |
194-
echo "ec2_linux_matrix pages: ${{ steps.paginate-matrix.outputs.ec2_linux_matrix_page_count }}"
195-
echo "ec2_selinux_matrix: ${{ steps.set-matrix.outputs.ec2_selinux_matrix }}"
208+
echo "ec2_linux_matrix pages: $EC2_LINUX_PAGE_COUNT"
209+
echo "ec2_selinux_matrix: $EC2_SELINUX_MATRIX"
196210
197211
198212
EC2LinuxIntegrationTest-0:
@@ -355,23 +369,28 @@ jobs:
355369
runs-on: ubuntu-latest
356370
steps:
357371
- name: Check for ready for testing label
372+
env:
373+
PR_FORK: ${{ github.event.pull_request.head.repo.fork }}
374+
PR_DRAFT: ${{ github.event.pull_request.draft }}
375+
HAS_SKIP_TESTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip testing') }}
376+
HAS_READY_FOR_TESTING: ${{ contains(github.event.pull_request.labels.*.name, 'ready for testing') }}
358377
run: |
359-
if [[ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]]; then
378+
if [[ "$PR_FORK" == "true" ]]; then
360379
echo "Fork PR - integration tests skipped (no access to secrets). Push branch to this repo to run them."
361380
exit 0
362381
fi
363382
364-
if [[ "${{ github.event.pull_request.draft }}" == "true" ]]; then
383+
if [[ "$PR_DRAFT" == "true" ]]; then
365384
echo "Draft PR - skipping label check."
366385
exit 0
367386
fi
368387
369-
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'skip testing') }}" == "true" ]]; then
388+
if [[ "$HAS_SKIP_TESTING" == "true" ]]; then
370389
echo "'skip testing' label found - bypassing integration test requirement."
371390
exit 0
372391
fi
373392
374-
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'ready for testing') }}" != "true" ]]; then
393+
if [[ "$HAS_READY_FOR_TESTING" != "true" ]]; then
375394
echo "Missing 'ready for testing' label. Please add before merging."
376395
exit 1
377396
fi
@@ -388,16 +407,15 @@ jobs:
388407
if: always()
389408
steps:
390409
- name: Check Job Status
410+
env:
411+
NEEDS_JSON: ${{ toJSON(needs) }}
391412
run: |
392-
# Convert needs context to JSON and process with jq
393-
needs_json='${{ toJSON(needs) }}'
394-
395413
failed_jobs=()
396414
successful_jobs=()
397415
398416
# Loop through all jobs in needs context
399-
for job in $(echo "$needs_json" | jq -r 'keys[]'); do
400-
result=$(echo "$needs_json" | jq -r ".[\"$job\"].result")
417+
for job in $(echo "$NEEDS_JSON" | jq -r 'keys[]'); do
418+
result=$(echo "$NEEDS_JSON" | jq -r ".[\"$job\"].result")
401419
402420
if [[ "$result" == "failure" ]]; then
403421
failed_jobs+=("$job")

.github/workflows/application-signals-e2e-test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ jobs:
4040
echo "Build SHA does not match test SHA"
4141
exit 1
4242
fi
43-
- run: |
43+
- env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
INPUT_BUILD_RUN_ID: ${{ inputs.build_run_id }}
46+
run: |
4447
for i in {1..6}; do
45-
conclusion=$(gh run view ${{ inputs.build_run_id }} --repo $GITHUB_REPOSITORY --json conclusion -q '.conclusion')
48+
conclusion=$(gh run view "$INPUT_BUILD_RUN_ID" --repo "$GITHUB_REPOSITORY" --json conclusion -q '.conclusion')
4649
if [[ "$conclusion" == "success" ]]; then
4750
echo "Run succeeded"
4851
exit 0
@@ -55,8 +58,6 @@ jobs:
5558
done
5659
echo "Timed out waiting for workflow"
5760
exit 1
58-
env:
59-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6061
6162
java-eks-e2e-test:
6263
needs: CheckBuildTestArtifacts

.github/workflows/build-test-artifacts.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ jobs:
128128
permissions:
129129
actions: write
130130
steps:
131-
- run: gh workflow run integration-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_run_id=${{ github.run_id }} -f build_sha=${{ github.sha }}
132-
env:
131+
- env:
133132
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133+
REF_NAME: ${{ github.ref_name }}
134+
RUN_ID: ${{ github.run_id }}
135+
GITHUB_SHA_VAL: ${{ github.sha }}
136+
run: gh workflow run integration-test.yml --ref "$REF_NAME" --repo "$GITHUB_REPOSITORY" -f "build_run_id=$RUN_ID" -f "build_sha=$GITHUB_SHA_VAL"
134137

135138
StartApplicationSignalsE2ETests:
136139
needs: [ BuildAndUploadPackages, BuildAndUploadITAR, BuildAndUploadCN, BuildDocker, BuildDistributor ]
@@ -140,9 +143,12 @@ jobs:
140143
permissions:
141144
actions: write
142145
steps:
143-
- run: gh workflow run application-signals-e2e-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_run_id=${{ github.run_id }} -f build_sha=${{ github.sha }}
144-
env:
146+
- env:
145147
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
REF_NAME: ${{ github.ref_name }}
149+
RUN_ID: ${{ github.run_id }}
150+
GITHUB_SHA_VAL: ${{ github.sha }}
151+
run: gh workflow run application-signals-e2e-test.yml --ref "$REF_NAME" --repo "$GITHUB_REPOSITORY" -f "build_run_id=$RUN_ID" -f "build_sha=$GITHUB_SHA_VAL"
146152

147153
StartEKSE2ETests:
148154
needs: [ BuildAndUploadPackages, BuildAndUploadITAR, BuildAndUploadCN, BuildDocker, BuildDistributor ]
@@ -151,9 +157,11 @@ jobs:
151157
permissions:
152158
actions: write
153159
steps:
154-
- run: gh workflow run e2e-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_sha=${{ github.sha }}
155-
env:
160+
- env:
156161
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162+
REF_NAME: ${{ github.ref_name }}
163+
GITHUB_SHA_VAL: ${{ github.sha }}
164+
run: gh workflow run e2e-test.yml --ref "$REF_NAME" --repo "$GITHUB_REPOSITORY" -f "build_sha=$GITHUB_SHA_VAL"
157165

158166
StartWorkloadDiscoveryIntegrationTests:
159167
needs: [ BuildAndUploadPackages, BuildAndUploadITAR, BuildAndUploadCN, BuildDocker, BuildDistributor ]
@@ -162,6 +170,9 @@ jobs:
162170
permissions:
163171
actions: write
164172
steps:
165-
- run: gh workflow run wd-integration-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_run_id=${{ github.run_id }} -f build_sha=${{ github.sha }}
166-
env:
173+
- env:
167174
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175+
REF_NAME: ${{ github.ref_name }}
176+
RUN_ID: ${{ github.run_id }}
177+
GITHUB_SHA_VAL: ${{ github.sha }}
178+
run: gh workflow run wd-integration-test.yml --ref "$REF_NAME" --repo "$GITHUB_REPOSITORY" -f "build_run_id=$RUN_ID" -f "build_sha=$GITHUB_SHA_VAL"

.github/workflows/clean-aws-resources.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ jobs:
138138

139139
- name: Clean old host
140140
working-directory: tool/clean
141-
run: go run ./clean_host/clean_host.go ${{ matrix.region }}
141+
env:
142+
MATRIX_REGION: ${{ matrix.region }}
143+
run: go run ./clean_host/clean_host.go "$MATRIX_REGION"
142144

143145
clean-hosts-china:
144146
runs-on: ubuntu-latest

.github/workflows/e2e-test.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,20 @@ jobs:
123123
echo "::set-output name=ECR_TARGET_ALLOCATOR_REPO::$(echo "${{ vars.ECR_TARGET_ALLOCATOR_STAGING_REPO }}" | awk -F'/' '{print $NF}')"
124124
125125
- name: Echo test variables
126+
env:
127+
OUT_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }}
128+
OUT_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}
129+
OUT_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}
130+
OUT_ECR_INTEGRATION_TEST_REPO: ${{ steps.set-outputs.outputs.ECR_INTEGRATION_TEST_REPO }}
131+
OUT_ECR_OPERATOR_REPO: ${{ steps.set-outputs.outputs.ECR_OPERATOR_REPO }}
132+
OUT_ECR_TARGET_ALLOCATOR_REPO: ${{ steps.set-outputs.outputs.ECR_TARGET_ALLOCATOR_REPO }}
126133
run: |
127-
echo "CWA_GITHUB_TEST_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }}"
128-
echo "CWA_GITHUB_TEST_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}"
129-
echo "CWA_GITHUB_TEST_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}"
130-
echo "ECR_INTEGRATION_TEST_REPO: ${{ steps.set-outputs.outputs.ECR_INTEGRATION_TEST_REPO }}"
131-
echo "ECR_OPERATOR_REPO: ${{ steps.set-outputs.outputs.ECR_OPERATOR_REPO }}"
132-
echo "ECR_TARGET_ALLOCATOR_REPO: ${{ steps.set-outputs.outputs.ECR_TARGET_ALLOCATOR_REPO }}"
134+
echo "CWA_GITHUB_TEST_REPO_NAME: $OUT_REPO_NAME"
135+
echo "CWA_GITHUB_TEST_REPO_URL: $OUT_REPO_URL"
136+
echo "CWA_GITHUB_TEST_REPO_BRANCH: $OUT_REPO_BRANCH"
137+
echo "ECR_INTEGRATION_TEST_REPO: $OUT_ECR_INTEGRATION_TEST_REPO"
138+
echo "ECR_OPERATOR_REPO: $OUT_ECR_OPERATOR_REPO"
139+
echo "ECR_TARGET_ALLOCATOR_REPO: $OUT_ECR_TARGET_ALLOCATOR_REPO"
133140
134141
GenerateTestMatrix:
135142
needs: [BuildAgent, BuildOperator]
@@ -156,8 +163,10 @@ jobs:
156163
echo "::set-output name=eks_e2e_jmx_matrix::$(echo $(cat generator/resources/eks_e2e_jmx_complete_test_matrix.json))"
157164
158165
- name: Echo test plan matrix
166+
env:
167+
EKS_E2E_JMX_MATRIX: ${{ steps.set-matrix.outputs.eks_e2e_jmx_matrix }}
159168
run: |
160-
echo "eks_e2e_jmx_matrix: ${{ steps.set-matrix.outputs.eks_e2e_jmx_matrix }}"
169+
echo "eks_e2e_jmx_matrix: $EKS_E2E_JMX_MATRIX"
161170
162171
EKSE2EJVMTomcatTestHelm:
163172
needs: [ GetLatestOperatorCommitSHA, GenerateTestMatrix, OutputEnvVariables ]

0 commit comments

Comments
 (0)