Skip to content

Commit a3d9c86

Browse files
Filter e2e gov tests. Run e2e gov in a separate job
1 parent 2bf0314 commit a3d9c86

File tree

4 files changed

+210
-19
lines changed

4 files changed

+210
-19
lines changed

.github/workflows/tests-selectable.yaml

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Tests-selectable
22

33
# This workflow is for running tests based on PR labels
4+
# NOTE:
5+
# The label filter app is used to select tests based on GitHub PR labels
6+
# Tests in the ./int directory are considered an integration test and executed in a separate job
7+
# Tests in the ./e2e directory are considered an end-to-end test and executed in a separate job
8+
# Tests in the ./e2e directory are considered a GOV test ONLY IF their labels contain "atlas-gov" and executed in a separate job
49

510
on:
611
pull_request:
@@ -82,9 +87,11 @@ jobs:
8287
./bin/ginkgo-labels > result.json
8388
echo "Int tests to execute $(cat result.json | jq -c .int)"
8489
echo "E2E tests to execute $(cat result.json | jq -c .e2e)"
90+
echo "E2E GOV tests to execute $(cat result.json | jq -c .e2e_gov)"
8591
8692
echo "int_matrix=$(cat result.json | jq -c .int)" >> $GITHUB_OUTPUT
8793
echo "e2e_matrix=$(cat result.json | jq -c .e2e)" >> $GITHUB_OUTPUT
94+
echo "e2e_gov_matrix=$(cat result.json | jq -c .e2e_gov)" >> $GITHUB_OUTPUT
8895
8996
compute:
9097
needs: detect-tests
@@ -318,27 +325,12 @@ jobs:
318325
run: |
319326
devbox run -- 'kubectl apply -f deploy/crds'
320327
321-
- name: Select environment to run E2E test
322-
id: select-env
323-
run: |
324-
if [[ "${{ matrix.test }}" == *"atlas-gov"* ]]; then
325-
echo "ENV=https://cloud-qa.mongodbgov.com" >> $GITHUB_OUTPUT
326-
echo "ORG_ID=${{ secrets.ATLAS_GOV_ORG_ID }}" >> $GITHUB_OUTPUT
327-
echo "PUBLIC_KEY=${{ secrets.ATLAS_GOV_PUBLIC_KEY }}" >> $GITHUB_OUTPUT
328-
echo "PRIVATE_KEY=${{ secrets.ATLAS_GOV_PRIVATE_KEY }}" >> $GITHUB_OUTPUT
329-
else
330-
echo "ENV=https://cloud-qa.mongodb.com" >> $GITHUB_OUTPUT
331-
echo "ORG_ID=${{ secrets.ATLAS_ORG_ID }}" >> $GITHUB_OUTPUT
332-
echo "PUBLIC_KEY=${{ secrets.ATLAS_PUBLIC_KEY }}" >> $GITHUB_OUTPUT
333-
echo "PRIVATE_KEY=${{ secrets.ATLAS_PRIVATE_KEY }}" >> $GITHUB_OUTPUT
334-
fi
335-
336328
- name: Run E2E test
337329
env:
338-
MCLI_PUBLIC_API_KEY: "${{ steps.select-env.outputs.PUBLIC_KEY }}"
339-
MCLI_PRIVATE_API_KEY: "${{ steps.select-env.outputs.PRIVATE_KEY }}"
340-
MCLI_ORG_ID: "${{ steps.select-env.outputs.ORG_ID }}"
341-
MCLI_OPS_MANAGER_URL: "${{ steps.select-env.outputs.ENV }}"
330+
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
331+
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }}
332+
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}}
333+
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
342334
IMAGE_URL: "${{ env.GHCR_REPO }}:${{ steps.prepare.outputs.tag }}"
343335
IMAGE_PULL_SECRET_REGISTRY: ghcr.io
344336
IMAGE_PULL_SECRET_USERNAME: $
@@ -367,3 +359,65 @@ jobs:
367359
with:
368360
name: logs
369361
path: output/**
362+
363+
run-e2e-gov-tests:
364+
needs: [detect-tests, prepare-e2e, prepare-e2e-bundle, compute]
365+
environment: gov-test
366+
if: ${{ needs.detect-tests.outputs.e2e_gov_matrix != '[]' && fromJSON(needs.detect-tests.outputs.e2e_gov_matrix) != '[]' }}
367+
strategy:
368+
fail-fast: false
369+
matrix:
370+
test: ${{ fromJSON(needs.detect-tests.outputs.e2e_gov_matrix) }}
371+
runs-on: ubuntu-latest
372+
name: "e2e gov: ${{ matrix.test }}"
373+
steps:
374+
- name: Get repo files from cache
375+
id: get-repo-files-from-cache
376+
uses: actions/cache@v4
377+
with:
378+
path: ./*
379+
key: ${{ github.sha }}
380+
381+
- name: Checkout if cache repo files missed
382+
if: steps.get-repo-files-from-cache.outputs.cache-hit != 'true'
383+
uses: actions/checkout@v4
384+
with:
385+
ref: ${{github.event.pull_request.head.sha}}
386+
submodules: true
387+
fetch-depth: 0
388+
389+
- name: Create k8s Kind Cluster
390+
if: ${{ !env.ACT }}
391+
uses: helm/[email protected]
392+
with:
393+
version: v0.26.0
394+
config: test/helper/e2e/config/kind.yaml
395+
cluster_name: "atlas-gov-e2e-test"
396+
wait: 180s
397+
398+
- name: Install devbox
399+
uses: jetify-com/[email protected]
400+
with:
401+
enable-cache: 'true'
402+
403+
- name: Install CRDs
404+
run: devbox run -- 'make install'
405+
406+
- name: Run e2e test
407+
env:
408+
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_GOV_PUBLIC_KEY }}
409+
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_GOV_PRIVATE_KEY }}
410+
MCLI_ORG_ID: ${{ secrets.ATLAS_GOV_ORG_ID}}
411+
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodbgov.com/"
412+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
413+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
414+
AWS_ACCOUNT_ARN_LIST: ${{ secrets.AWS_ACCOUNT_ARN_LIST }}
415+
PAGER_DUTY_SERVICE_KEY: ${{ secrets.PAGER_DUTY_SERVICE_KEY }}
416+
TEST_NAME: "${{ matrix.test }}""
417+
run: devbox run -- ./scripts/launch-ci-e2e.sh
418+
- name: Upload operator logs
419+
if: ${{ failure() }}
420+
uses: actions/upload-artifact@v4
421+
with:
422+
name: logs
423+
path: output/**
3.12 MB
Binary file not shown.

tools/compute-test-labels/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ func MatchWildcards(labels []string, testLabels []string, testType string) []str
5858
return result
5959
}
6060

61+
func FilterLabelsDoNotContain(labels []string, substr string) []string {
62+
filtered := make([]string, 0, len(labels))
63+
for _, label := range labels {
64+
if !strings.Contains(label, substr) {
65+
filtered = append(filtered, label)
66+
}
67+
}
68+
return filtered
69+
}
70+
71+
func FilterLabelsContain(labels []string, substr string) []string {
72+
filtered := make([]string, 0, len(labels))
73+
for _, label := range labels {
74+
if strings.Contains(label, substr) {
75+
filtered = append(filtered, label)
76+
}
77+
}
78+
return filtered
79+
}
80+
6181
func main() {
6282
envPRLabels := os.Getenv("PR_LABELS")
6383
envIntLabels := os.Getenv("INT_LABELS")
@@ -83,17 +103,24 @@ func main() {
83103

84104
matchedIntTests := MatchWildcards(labels, intLabels, "int")
85105
matchedE2ETests := MatchWildcards(labels, e2eLabels, "e2e")
106+
// These have to be executed in their own environment )
107+
matchedE2EGovTests := FilterLabelsContain(matchedE2ETests, "atlas-gov")
108+
109+
matchedE2ETests = FilterLabelsDoNotContain(matchedE2ETests, "atlas-gov")
86110

87111
matchedIntTestsJSON, _ := json.Marshal(matchedIntTests)
88112
matchedE2ETestsJSON, _ := json.Marshal(matchedE2ETests)
113+
matchedE2EGovTestsJSON, _ := json.Marshal(matchedE2EGovTests)
89114

90115
if envUseJSON != "" {
91116
res := map[string]any{}
92117
res["int"] = matchedIntTests
93118
res["e2e"] = matchedE2ETests
119+
res["e2e_gov"] = matchedE2EGovTests
94120
fmt.Println(jsonDump(res))
95121
return
96122
}
97123
fmt.Printf("Matched Integration Tests: %s\n", matchedIntTestsJSON)
98124
fmt.Printf("Matched E2E Tests: %s\n", matchedE2ETestsJSON)
125+
fmt.Printf("Matched E2E GOV Tests: %s\n", matchedE2EGovTestsJSON)
99126
}

tools/compute-test-labels/main_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,116 @@ import (
1818
"testing"
1919
)
2020

21+
func TestFilterLabelsContain(t *testing.T) {
22+
tests := []struct {
23+
name string
24+
labels []string
25+
substr string
26+
expectedResult []string
27+
}{
28+
{
29+
name: "Single match",
30+
labels: []string{"atlas-gov", "atlas", "cloud"},
31+
substr: "gov",
32+
expectedResult: []string{"atlas-gov"},
33+
},
34+
{
35+
name: "Multiple matches",
36+
labels: []string{"atlas-gov", "atlas-gov-cloud", "cloud"},
37+
substr: "gov",
38+
expectedResult: []string{"atlas-gov", "atlas-gov-cloud"},
39+
},
40+
{
41+
name: "No matches",
42+
labels: []string{"atlas", "cloud"},
43+
substr: "gov",
44+
expectedResult: []string{},
45+
},
46+
{
47+
name: "Empty labels",
48+
labels: []string{},
49+
substr: "gov",
50+
expectedResult: []string{},
51+
},
52+
}
53+
54+
for _, tt := range tests {
55+
t.Run(tt.name, func(t *testing.T) {
56+
result := FilterLabelsContain(tt.labels, tt.substr)
57+
if len(result) != len(tt.expectedResult) {
58+
t.Errorf("Test %s failed: expected %v, got %v", tt.name, tt.expectedResult, result)
59+
}
60+
for _, label := range tt.expectedResult {
61+
found := false
62+
for _, res := range result {
63+
if res == label {
64+
found = true
65+
break
66+
}
67+
}
68+
if !found {
69+
t.Errorf("Test %s failed: expected %v to be in the result", tt.name, label)
70+
}
71+
}
72+
})
73+
}
74+
}
75+
76+
func TestFilterLabelsDoNotContain(t *testing.T) {
77+
tests := []struct {
78+
name string
79+
labels []string
80+
substr string
81+
expectedResult []string
82+
}{
83+
{
84+
name: "Single exclusion",
85+
labels: []string{"atlas-gov", "atlas", "cloud"},
86+
substr: "gov",
87+
expectedResult: []string{"atlas", "cloud"},
88+
},
89+
{
90+
name: "Multiple exclusions",
91+
labels: []string{"atlas-gov", "atlas-gov-cloud", "cloud"},
92+
substr: "gov",
93+
expectedResult: []string{"cloud"},
94+
},
95+
{
96+
name: "No exclusions",
97+
labels: []string{"atlas", "cloud"},
98+
substr: "gov",
99+
expectedResult: []string{"atlas", "cloud"},
100+
},
101+
{
102+
name: "Empty labels",
103+
labels: []string{},
104+
substr: "gov",
105+
expectedResult: []string{},
106+
},
107+
}
108+
109+
for _, tt := range tests {
110+
t.Run(tt.name, func(t *testing.T) {
111+
result := FilterLabelsDoNotContain(tt.labels, tt.substr)
112+
if len(result) != len(tt.expectedResult) {
113+
t.Errorf("Test %s failed: expected %v, got %v", tt.name, tt.expectedResult, result)
114+
}
115+
for _, label := range tt.expectedResult {
116+
found := false
117+
for _, res := range result {
118+
if res == label {
119+
found = true
120+
break
121+
}
122+
}
123+
if !found {
124+
t.Errorf("Test %s failed: expected %v to be in the result", tt.name, label)
125+
}
126+
}
127+
})
128+
}
129+
}
130+
21131
func TestMatchWildcards(t *testing.T) {
22132
tests := []struct {
23133
name string

0 commit comments

Comments
 (0)