Skip to content

Commit 88d238b

Browse files
committed
Run E2E tests in CI via e2e_tests.json
1 parent 8ca49fc commit 88d238b

File tree

2 files changed

+68
-15
lines changed

2 files changed

+68
-15
lines changed

.github/workflows/ci-cd.yml

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,72 @@ jobs:
5959
with:
6060
sarif_file: 'trivy-results.sarif'
6161

62+
e2e-tests-discovery:
63+
runs-on: ubuntu-latest
64+
outputs:
65+
matrix: ${{ steps.set-matrix.outputs.matrix }}
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v3
69+
- id: set-matrix
70+
name: Discover E2E tests
71+
run: |
72+
log_content() {
73+
local content="$1"
74+
local label="${2:-}"
75+
76+
if [[ -n "$label" ]]; then
77+
# Replace the beginning of each line with two spaces
78+
local indented_content="${content//$'\n'/$'\n' }"
79+
printf "%s:\n %s\n" "$label" "$indented_content"
80+
else
81+
echo "$content"
82+
fi
83+
}
84+
85+
log_output() {
86+
echo ::group::Set outputs
87+
log_content "$(cat "$GITHUB_OUTPUT")" "GITHUB_OUTPUT"
88+
log_content "$(cat "$GITHUB_ENV")" "GITHUB_ENV"
89+
echo ::endgroup::
90+
}
91+
92+
set_output() {
93+
local value="$1"
94+
local output_key="$2"
95+
local env_key="${3:-}"
96+
97+
if [ -z "$value" ] || [ -z "$output_key" ]; then
98+
echo "Missing essential arguments to set_output_and_env"
99+
return 1
100+
fi
101+
102+
# If env_key is empty, convert output_key to upper snake case
103+
if [ -z "$env_key" ]; then
104+
env_key=$(echo "$output_key" | awk '{print toupper($0)}' | sed 's/-/_/g')
105+
fi
106+
107+
echo "$output_key=$value" >> "$GITHUB_OUTPUT"
108+
echo "$env_key=$value" >> "$GITHUB_ENV"
109+
}
110+
set_output "{\"include\":$(jq -c '[.[]]' test/e2e_tests.json)}" "matrix"
111+
log_output
112+
62113
e2e-tests:
63-
needs: [ build ]
114+
needs: [ build, e2e-tests-discovery ]
64115
strategy:
65116
fail-fast: false
66-
matrix:
67-
data:
68-
- name: "return"
69-
script: |
70-
"return"
71-
expected: "return"
72-
73-
- name: "context"
74-
script: |
75-
Map.keys(context)
76-
expected: "[__struct__,action,actor,api_url,event_name,graphql_url,job,payload,ref,run_id,run_number,server_url,sha,workflow]"
117+
matrix: ${{fromJson(needs.e2e-tests-discovery.outputs.matrix)}}
77118
runs-on: ubuntu-latest
78-
name: "e2e tests (${{ matrix.data.name }})"
119+
name: "e2e tests (${{ matrix.name }})"
79120
steps:
80121
- uses: actions/checkout@v3
81122
- uses: ./.github/actions/load-tar-image
82123
- uses: ./.github/actions/run-e2e
83124
with:
84125
image-name: ${{ env.IMAGE_NAME }}
85-
script: ${{ matrix.data.script }}
86-
expected: ${{ matrix.data.expected }}
126+
script: ${{ matrix.script }}
127+
expected: ${{ matrix.expected }}
87128

88129
push:
89130
needs: [ version, build, e2e-tests, vulnerability-scanner ]

test/e2e_tests.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"name": "return",
4+
"script": "return",
5+
"expected": "return"
6+
},
7+
{
8+
"name": "context",
9+
"script": "Map.keys(context)",
10+
"expected": "[__struct__,action,actor,api_url,event_name,graphql_url,job,payload,ref,run_id,run_number,server_url,sha,workflow]"
11+
}
12+
]

0 commit comments

Comments
 (0)