-
Notifications
You must be signed in to change notification settings - Fork 94
CLOUDP-296897: Allow to select tests to run #2240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6b496af
a23253c
a8aece8
41bb7ff
5fc2f0e
eae0b48
6b44871
e6a53ce
b8ed469
a20b2c4
611a6ae
fce5736
045926d
c60e90c
28f7fa8
af5111b
a40acf6
de0784a
492730e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ jobs: | |
fi | ||
|
||
BRANCH_NAME=ako-helm-update-"${jobname}" | ||
COMMIT_MSG="[autogenerated] update AKO helm-charts ${jobname}" | ||
COMMIT_MSG="[autogenerated] update AKO helm-charts ${jobname} by @${{ github.event.pull_request.user.login }}" | ||
echo "Changes detected. Creating PR" | ||
|
||
git config --local user.email "[email protected]" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,345 @@ | ||
name: Tests-selectable | ||
|
||
# This workflow is for running tests based on PR labels | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, labeled, unlabeled] | ||
workflow_dispatch: | ||
inputs: | ||
testLabels: | ||
description: 'Test labels to run' | ||
required: false | ||
default: '[]' | ||
branchName: | ||
description: 'The branch name to checkout' | ||
required: false | ||
default: 'main' | ||
|
||
jobs: | ||
detect-tests: | ||
name: "Select tests to run" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
int_matrix: ${{ steps.set-matrix.outputs.int_matrix }} | ||
e2e_matrix: ${{ steps.set-matrix.outputs.e2e_matrix }} | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.branchName || github.head_ref }} | ||
|
||
- name: Setup GO | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.23 | ||
|
||
- name: Install Ginkgo | ||
run: go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
|
||
- name: Get test labels from PR or input | ||
env: | ||
TEST_LABELS: ${{ github.event.inputs.testLabels }} | ||
id: get-labels | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
if (context.eventName === 'pull_request') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment: remember this if |
||
prLabels = context.payload.pull_request.labels.map(label => label.name); | ||
console.log("PR Labels:", prLabels); | ||
return prLabels; | ||
} | ||
|
||
if (context.eventName === "workflow_dispatch") { | ||
inputLabels = process.env.TEST_LABELS; | ||
console.log("Input labels:", inputLabels); | ||
return inputLabels.split(",").map(label => label.trim()).filter(label => label !== ""); | ||
} | ||
console.log("Not a PullRequest or WorkflowDispatch event skipping"); | ||
return []; | ||
|
||
- name: List available Ginkgo test labels | ||
id: fetch-labels | ||
run: | | ||
INT_LABELS=$(cd ./test/int && ginkgo labels | sed 's/^int: //' | jq -s -c '.[0]') | ||
E2E_LABELS=$(cd ./test/e2e && ginkgo labels | sed 's/^e2e: //' | jq -s -c '.[0]') | ||
|
||
echo "int_labels=$INT_LABELS" >> $GITHUB_ENV | ||
echo "e2e_labels=$E2E_LABELS" >> $GITHUB_ENV | ||
|
||
echo "Available Integration Tests: $INT_LABELS" | ||
echo "Available E2E Tests: $E2E_LABELS" | ||
|
||
- name: Compute Test Matrix | ||
id: set-matrix | ||
env: | ||
PR_LABELS: ${{ steps.get-labels.outputs.result }} | ||
INT_LABELS: ${{ env.int_labels }} | ||
E2E_LABELS: ${{ env.e2e_labels }} | ||
USE_JSON: true | ||
run: | | ||
make compute-labels | ||
./bin/ginkgo-labels > result.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also possible, but I decided to go with the |
||
echo "Int tests to execute $(cat result.json | jq -c .int)" | ||
echo "E2E tests to execute $(cat result.json | jq -c .e2e)" | ||
|
||
echo "int_matrix=$(cat result.json | jq -c .int)" >> $GITHUB_OUTPUT | ||
echo "e2e_matrix=$(cat result.json | jq -c .e2e)" >> $GITHUB_OUTPUT | ||
Comment on lines
+82
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment: we'll need to take this into account when we split helm chart tests from e2e |
||
|
||
compute: | ||
needs: detect-tests | ||
name: "Compute test matrix for k8s versions" | ||
runs-on: ubuntu-latest | ||
outputs: | ||
test_matrix: ${{ steps.test.outputs.matrix }} | ||
steps: | ||
- id: test | ||
name: Compute test matrix for k8s versions | ||
run: | | ||
# Note the use of external single quotes to allow for double quotes at inline YAML array | ||
matrix='["v1.30.10-kind"]' | ||
if [ "${{ github.ref }}" == "refs/heads/main" ];then | ||
matrix='["v1.30.10-kind", "v1.32.2-kind"]' | ||
fi | ||
echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}" | ||
cat "${GITHUB_OUTPUT}" | ||
|
||
prepare-e2e: | ||
needs: detect-tests | ||
name: Prepare E2E configuration and image | ||
if: ${{ needs.detect-tests.outputs.e2e_matrix != '[]' }} | ||
environment: release | ||
runs-on: ubuntu-latest | ||
env: | ||
REPOSITORY: ${{ github.repository_owner }}/mongodb-atlas-kubernetes-operator-prerelease | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{github.event.pull_request.head.sha}} | ||
submodules: true | ||
fetch-depth: 0 | ||
|
||
- name: Prepare tag | ||
id: prepare | ||
uses: ./.github/actions/set-tag | ||
|
||
- name: Log in to ghcr.io registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: Build and Push image | ||
uses: ./.github/actions/build-push-image | ||
with: | ||
file: fast.Dockerfile | ||
repository: ghcr.io/${{ env.REPOSITORY }} | ||
version: ${{ steps.prepare.outputs.tag }} | ||
tags: ghcr.io/${{ env.REPOSITORY }}:${{ steps.prepare.outputs.tag }} | ||
platforms: linux/amd64 | ||
push_to_docker: false | ||
|
||
- name: Do preflight-check on test image | ||
uses: ./.github/actions/certify-openshift-images | ||
with: | ||
registry: ghcr.io | ||
registry_password: ${{ secrets.GITHUB_TOKEN }} | ||
repository: ${{ env.REPOSITORY }} | ||
version: ${{ steps.prepare.outputs.tag }} | ||
rhcc_token: ${{ secrets.RH_CERTIFICATION_PYXIS_API_TOKEN }} | ||
rhcc_project: ${{ secrets.RH_CERTIFICATION_OSPID }} | ||
submit: false | ||
|
||
prepare-e2e-bundle: | ||
needs: detect-tests | ||
name: Prepare E2E Bundle configuration and image | ||
if: ${{ needs.detect-tests.outputs.e2e_matrix != '[]' }} | ||
runs-on: ubuntu-latest | ||
env: | ||
GHCR_REPO: ghcr.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease | ||
GHCR_BUNDLES_REPO: ghcr.io/mongodb/mongodb-atlas-kubernetes-bundles-prerelease | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{github.event.pull_request.head.sha}} | ||
submodules: true | ||
fetch-depth: 0 | ||
|
||
- name: Prepare tag | ||
id: prepare | ||
uses: ./.github/actions/set-tag | ||
- name: Generate configuration for the tests | ||
uses: ./.github/actions/gen-install-scripts | ||
with: | ||
IMAGE_URL: ${{ env.GHCR_REPO }}:${{ steps.prepare.outputs.tag }} | ||
VERSION: ${{ steps.prepare.outputs.tag }} | ||
ENV: dev | ||
|
||
- name: Change URL for the test | ||
run: | | ||
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml | ||
|
||
- name: Cache repo files | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
./* | ||
key: ${{ github.sha }} | ||
|
||
- name: Prepare docker tag | ||
id: prepare-docker-bundle-tag | ||
run: | | ||
REPOSITORY=${{ env.GHCR_BUNDLES_REPO }} | ||
TAG=${{ steps.prepare.outputs.tag }} | ||
TAGS="${REPOSITORY}:${TAG}" | ||
echo "tags=$TAGS" >> $GITHUB_OUTPUT | ||
|
||
- name: Log in to ghcr.io registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: Build and Push image | ||
uses: ./.github/actions/build-push-image | ||
with: | ||
file: fast.Dockerfile | ||
repository: ${{ env.GHCR_BUNDLES_REPO }} | ||
version: ${{ steps.prepare.outputs.tag }} | ||
tags: ${{ env.GHCR_BUNDLES_REPO }}:${{ steps.prepare.outputs.tag }} | ||
platforms: linux/amd64 | ||
push_to_docker: false | ||
|
||
run-integration-tests: | ||
environment: test | ||
needs: detect-tests | ||
if: ${{ needs.detect-tests.outputs.int_matrix != '[]' && fromJSON(needs.detect-tests.outputs.int_matrix) != '[]' }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
test: ${{ fromJSON(needs.detect-tests.outputs.int_matrix) }} | ||
target: [ "test/int" ] | ||
nodes: [12] | ||
runs-on: ubuntu-latest | ||
name: "integration: ${{ matrix.test }}" | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Install devbox | ||
uses: jetify-com/[email protected] | ||
with: | ||
enable-cache: 'true' | ||
|
||
- name: Run integration test | ||
env: | ||
ATLAS_ORG_ID: ${{ secrets.ATLAS_ORG_ID }} | ||
ATLAS_PUBLIC_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }} | ||
ATLAS_PRIVATE_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }} | ||
GINKGO_FILTER_LABEL: ${{ matrix.test }} | ||
GINKGO_NODES: ${{ matrix.nodes }} | ||
GO111MODULE: on | ||
GINKGO_EDITOR_INTEGRATION: "true" | ||
run: | | ||
devbox run -- 'make ${{ matrix.target }}' | ||
|
||
run-e2e-tests: | ||
needs: [detect-tests, prepare-e2e, prepare-e2e-bundle, compute] | ||
environment: test | ||
if: ${{ needs.detect-tests.outputs.e2e_matrix != '[]' && fromJSON(needs.detect-tests.outputs.e2e_matrix) != '[]' }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
test: ${{ fromJSON(needs.detect-tests.outputs.e2e_matrix) }} | ||
k8s: ${{ fromJSON(needs.compute.outputs.test_matrix) }} | ||
runs-on: ubuntu-latest | ||
name: "e2e: ${{ matrix.test }}" | ||
steps: | ||
- name: Get repo files from cache | ||
id: get-repo-files-from-cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./* | ||
key: ${{ github.sha }} | ||
|
||
- name: Checkout if cache repo files missed | ||
if: steps.get-repo-files-from-cache.outputs.cache-hit != 'true' | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{github.event.pull_request.head.sha}} | ||
submodules: true | ||
fetch-depth: 0 | ||
|
||
- name: Install devbox | ||
uses: jetify-com/[email protected] | ||
with: | ||
enable-cache: 'true' | ||
|
||
- name: Prepare tag | ||
id: prepare | ||
uses: ./.github/actions/set-tag | ||
- name: Set properties | ||
id: properties | ||
run: | | ||
version=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $1}') | ||
platform=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $2}') | ||
echo "k8s_version=$version" >> $GITHUB_OUTPUT | ||
echo "k8s_platform=$platform" >> $GITHUB_OUTPUT | ||
|
||
- name: Generate configuration for the tests | ||
uses: ./.github/actions/gen-install-scripts | ||
with: | ||
IMAGE_URL: ${{ env.GHCR_REPO }}:${{ steps.prepare.outputs.tag }} | ||
VERSION: ${{ steps.prepare.outputs.tag }} | ||
ENV: dev | ||
|
||
- name: Change path for the test | ||
run: | | ||
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml | ||
|
||
- name: Create k8s Kind Cluster | ||
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }} | ||
uses: helm/[email protected] | ||
with: | ||
version: v0.26.0 | ||
config: test/helper/e2e/config/kind.yaml | ||
node_image: kindest/node:${{ steps.properties.outputs.k8s_version }} | ||
cluster_name: ${{ matrix.test }} | ||
wait: 180s | ||
|
||
- name: Print kubectl version | ||
run: | | ||
devbox run -- 'kubectl version' | ||
|
||
- name: Print kubectl version | ||
run: | | ||
devbox run -- 'kubectl version' | ||
|
||
- name: Install CRDs if needed | ||
if: ${{ !( matrix.test == 'helm-update' || matrix.test == 'helm-wide' || matrix.test == 'helm-ns' || matrix.test == 'bundle-test' ) }} | ||
run: | | ||
devbox run -- 'kubectl apply -f deploy/crds' | ||
|
||
- name: Run E2E test | ||
env: | ||
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }} | ||
MCLI_PRIVATE_API_KEY: ${{ secrets.ATLAS_PRIVATE_KEY }} | ||
MCLI_ORG_ID: ${{ secrets.ATLAS_ORG_ID}} | ||
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/" | ||
IMAGE_URL: "${{ env.GHCR_REPO }}:${{ steps.prepare.outputs.tag }}" | ||
IMAGE_PULL_SECRET_REGISTRY: ghcr.io | ||
IMAGE_PULL_SECRET_USERNAME: $ | ||
IMAGE_PULL_SECRET_PASSWORD: "${{ secrets.GITHUB_TOKEN }}" | ||
BUNDLE_IMAGE: "${{ env.GHCR_BUNDLES_REPO}}:${{ steps.prepare.outputs.tag }}" | ||
K8S_PLATFORM: "${{ steps.properties.outputs.k8s_platform }}" | ||
K8S_VERSION: "${{ steps.properties.outputs.k8s_version }}" | ||
TEST_NAME: "${{ matrix.test }}" | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_ACCOUNT_ARN_LIST: ${{ secrets.AWS_ACCOUNT_ARN_LIST }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | ||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | ||
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} | ||
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
GCP_SA_CRED: ${{ secrets.GCP_SA_CRED }} | ||
DATADOG_KEY: ${{ secrets.DATADOG_KEY }} | ||
PAGER_DUTY_SERVICE_KEY: ${{ secrets.PAGER_DUTY_SERVICE_KEY }} | ||
run: devbox run -- ./scripts/launch-ci-e2e.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,12 @@ help: ## Show this help screen | |
.PHONY: all | ||
all: manager ## Build all binaries | ||
|
||
|
||
.PHONY: compute-labels | ||
compute-labels: | ||
mkdir -p bin | ||
go build -o bin/ginkgo-labels tools/compute-test-labels/main.go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: Not for this PR, but a thought in general. Should we group all AKO dev tools in a single tool repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can think about that if there are good reasons for that. So far, nothing stops us for having tools in the |
||
|
||
.PHONY: build-licenses.csv | ||
build-licenses.csv: go.mod ## Track licenses in a CSV file | ||
@echo "Tracking licenses into file $@" | ||
|
@@ -196,6 +202,7 @@ envtest: envtest-assets | |
KUBEBUILDER_ASSETS=$(shell setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) -p path) | ||
|
||
envtest-assets: | ||
echo "Env: $(env)" | ||
mkdir -p $(ENVTEST_ASSETS_DIR) | ||
|
||
.PHONY: e2e | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: Note this will never work for external contributors. For security reasons, the
pull_request
event uses the credentials from the contributor's fork repo, not the AKO repo. For accepting external contributionspull_request_target
needs to be used instead, but in such case, when the contribution is external, a gating mechanism needs to be set in place to avoid external forks to access and peek or abuse AKO creds without us even been able to stop it (for instance, "if external, thesafe-to-test
label must also be present").BTW, one current issue I had when tying to fix these external workflows is that if you have
pull_request
&pull_request_target
both set, they will trigger and your workflows might duplicate. I guess the best way is, either make sure only one can fire at a time (pull_request
only for owners andpull_request_target
only for contributors) or use onlypull_request_target
with gating for non owners.q: Was intended to skip external contributions? It is fine, as the CI is still broken in general for that use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think we can drop the CI runs for PRs from forked repos for now. I'll create a follow up ticket