Repository navigation
ci: shadow test selection for three paths #23035
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
404131d
a51396f
66b33b0
1cd08b9
94aa629
b36df34
149eade
6b7eb28
e35d0a6
a440690
79e71e0
376eef3
e41dc2a
f2c753b
ef53809
78c0031
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: Dispatcher plan | ||
|
|
||
| # Called by the test workflows. Prints the plan and returns, for each | ||
| # GitHub Actions job, whether the dispatcher would start it. | ||
| # The label ci-dispatcher-enforce is what makes a caller obey that answer. | ||
| # Without the label the caller keeps starting jobs the way it does today. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| outputs: | ||
| enforce: | ||
| description: true when the pull request has ci-dispatcher-enforce | ||
| value: ${{ jobs.plan.outputs.enforce }} | ||
| jobs: | ||
| description: JSON object of job id to whether the dispatcher would start it | ||
| value: ${{ jobs.plan.outputs.jobs }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| plan: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| enforce: ${{ steps.out.outputs.enforce }} | ||
| jobs: ${{ steps.out.outputs.jobs }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # ratchet:actions/checkout@v7.0.0 | ||
|
|
||
| - name: Install PyYAML | ||
| run: | | ||
| python3 -m venv "${RUNNER_TEMP}/selector" | ||
| "${RUNNER_TEMP}/selector/bin/pip" install 'PyYAML==6.0.3' | ||
|
|
||
| - name: Plan GitHub Actions jobs | ||
| id: out | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }} | ||
| DRAFT: ${{ github.event.pull_request.draft }} | ||
| FORK: ${{ github.event.pull_request.head.repo.fork }} | ||
| ENFORCE: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') }} | ||
| run: | | ||
| set -euo pipefail | ||
| py="${RUNNER_TEMP}/selector/bin/python" | ||
| flags=() | ||
| if [[ "${DRAFT}" == "true" ]]; then flags+=(--draft); fi | ||
| if [[ "${FORK}" == "true" ]]; then flags+=(--fork); fi | ||
| if [[ "${ENFORCE}" == "true" ]]; then flags+=(--enforce); fi | ||
|
|
||
| files="$(mktemp)" | ||
| if ! gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" --paginate --jq '.[].filename' > "${files}"; then | ||
| echo "Could not list changed files. Showing the run-everything result." | ||
| : > "${files}" | ||
| elif [[ "$(wc -l < "${files}")" -ge 3000 ]]; then | ||
| echo "3000 or more changed files. Showing the run-everything result." | ||
| : > "${files}" | ||
| fi | ||
|
|
||
| common=( | ||
| "${py}" ci/exploration/dispatcher.py | ||
| --mapping ci/test-domains.toml | ||
| --defaults ci/exploration/gha_defaults.yaml | ||
| --labels "${LABELS}" | ||
| "${flags[@]}" | ||
| ) | ||
|
|
||
| "${common[@]}" --title "This pull request" - < "${files}" | ||
| "${common[@]}" --format json - < "${files}" > "${RUNNER_TEMP}/plan.json" | ||
|
|
||
| python3 - << 'PY' | ||
| import json | ||
| import os | ||
|
|
||
| plan = json.load(open(os.environ["RUNNER_TEMP"] + "/plan.json")) | ||
| selected = {item["job"]: bool(item["would_run"]) for item in plan["jobs"]} | ||
| with open(os.environ["GITHUB_OUTPUT"], "a") as handle: | ||
| handle.write(f"enforce={os.environ['ENFORCE']}\n") | ||
| handle.write("jobs<<EOF\n") | ||
| json.dump(selected, handle, separators=(",", ":")) | ||
| handle.write("\nEOF\n") | ||
| PY |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,7 @@ on: | |||||||||||||||||||||||
| - '.github/workflows/emailsender-central-compatibility.yaml' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||
| types: [opened, synchronize, reopened, ready_for_review] | ||||||||||||||||||||||||
| types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled] | ||||||||||||||||||||||||
|
Contributor
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. I think we only need to run this when the label is added, not when it's removed.
Suggested change
|
||||||||||||||||||||||||
| paths: | ||||||||||||||||||||||||
| - 'central/notifiers/email/**' | ||||||||||||||||||||||||
| - 'central/notifiers/acscsemail/**' | ||||||||||||||||||||||||
|
|
@@ -24,15 +24,33 @@ concurrency: | |||||||||||||||||||||||
| cancel-in-progress: true | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||
| plan: | ||||||||||||||||||||||||
| if: github.event_name == 'pull_request' | ||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||
| pull-requests: read | ||||||||||||||||||||||||
| uses: ./.github/workflows/dispatcher-plan.yaml | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| e2e-test-on-kind: | ||||||||||||||||||||||||
| timeout-minutes: 60 | ||||||||||||||||||||||||
| name: "Test on kind cluster" | ||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||
| if: ${{ !github.event.pull_request.head.repo.fork }} # do not run for PRs from forks | ||||||||||||||||||||||||
| needs: plan | ||||||||||||||||||||||||
| # Forks stay off. The dispatcher does not get to start a job from an untrusted fork. | ||||||||||||||||||||||||
| if: >- | ||||||||||||||||||||||||
| always() && !cancelled() && !github.event.pull_request.head.repo.fork && ( | ||||||||||||||||||||||||
| (github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce')) | ||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result == 'success' && fromJSON(needs.plan.outputs.jobs)['e2e-test-on-kind'] | ||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
+40
to
+45
Contributor
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. Simplified:
Suggested change
|
||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||
| id-token: write | ||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||
| - name: Fail closed when the dispatcher plan did not succeed | ||||||||||||||||||||||||
| if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||
| run: echo "The dispatcher plan did not succeed, so this job is not running its tests." && exit 1 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Login to Quay.io | ||||||||||||||||||||||||
| uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # ratchet:docker/login-action@v4 | ||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,18 +12,36 @@ on: | |||||||||||||||||||||||
| - opened | ||||||||||||||||||||||||
| - reopened | ||||||||||||||||||||||||
| - synchronize | ||||||||||||||||||||||||
| - labeled | ||||||||||||||||||||||||
| - unlabeled | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||
| detect-changes: | ||||||||||||||||||||||||
| uses: ./.github/workflows/detect-changes.yml | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| plan: | ||||||||||||||||||||||||
| if: github.event_name == 'pull_request' | ||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||
| pull-requests: read | ||||||||||||||||||||||||
| uses: ./.github/workflows/dispatcher-plan.yaml | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| db-integration-tests: | ||||||||||||||||||||||||
| needs: detect-changes | ||||||||||||||||||||||||
| if: ${{ !needs.detect-changes.outputs.ui_only }} | ||||||||||||||||||||||||
| needs: [detect-changes, plan] | ||||||||||||||||||||||||
| if: >- | ||||||||||||||||||||||||
| always() && !cancelled() && needs.detect-changes.result == 'success' && ( | ||||||||||||||||||||||||
| (github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce')) && !needs.detect-changes.outputs.ui_only | ||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result == 'success' && fromJSON(needs.plan.outputs.jobs)['db-integration-tests'] | ||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
+31
to
+36
Contributor
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. Simpler:
Suggested change
|
||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||
| container: | ||||||||||||||||||||||||
| image: quay.io/stackrox-io/apollo-ci:scanner-test-0.5.11@sha256:cea78f2b3a5a38c9ccda678712daaed90b7c372d6b5df963feb758b32dccebe1 # ratchet:quay.io/stackrox-io/apollo-ci:scanner-test-0.5.11 | ||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||
| - name: Fail closed when the dispatcher plan did not succeed | ||||||||||||||||||||||||
|
Contributor
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. [nit]: I'd word this differently
Suggested change
|
||||||||||||||||||||||||
| if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||
| run: echo "The dispatcher plan did not succeed, so this job is not running its tests." && exit 1 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - name: Checkout | ||||||||||||||||||||||||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # ratchet:actions/checkout@v7.0.0 | ||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,15 +7,35 @@ on: | |||||||||||||||||||||||||||||||||||
| - opened | ||||||||||||||||||||||||||||||||||||
| - reopened | ||||||||||||||||||||||||||||||||||||
| - synchronize | ||||||||||||||||||||||||||||||||||||
| - labeled | ||||||||||||||||||||||||||||||||||||
| - unlabeled | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||
| plan: | ||||||||||||||||||||||||||||||||||||
| if: github.event_name == 'pull_request' | ||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||
| pull-requests: read | ||||||||||||||||||||||||||||||||||||
| uses: ./.github/workflows/dispatcher-plan.yaml | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| scanner-ft-images: | ||||||||||||||||||||||||||||||||||||
| name: Wait for images | ||||||||||||||||||||||||||||||||||||
| if: > | ||||||||||||||||||||||||||||||||||||
| github.event_name != 'pull_request' | ||||||||||||||||||||||||||||||||||||
| || contains(github.event.pull_request.labels.*.name, 'scanner-functional-tests') | ||||||||||||||||||||||||||||||||||||
| needs: plan | ||||||||||||||||||||||||||||||||||||
| if: >- | ||||||||||||||||||||||||||||||||||||
| always() && !cancelled() && ( | ||||||||||||||||||||||||||||||||||||
| (github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce')) && ( | ||||||||||||||||||||||||||||||||||||
| github.event_name != 'pull_request' | ||||||||||||||||||||||||||||||||||||
| || contains(github.event.pull_request.labels.*.name, 'scanner-functional-tests') | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result == 'success' && fromJSON(needs.plan.outputs.jobs)['scanner-ft-images'] | ||||||||||||||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+32
Contributor
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. Simpler:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||
| - name: Fail closed when the dispatcher plan did not succeed | ||||||||||||||||||||||||||||||||||||
|
Contributor
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. [nit]
Suggested change
|
||||||||||||||||||||||||||||||||||||
| if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||||||||||||||
| run: echo "The dispatcher plan did not succeed, so this job is not running its tests." && exit 1 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| - name: Checkout repo | ||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # ratchet:actions/checkout@v7.0.0 | ||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||
|
|
@@ -36,6 +56,15 @@ jobs: | |||||||||||||||||||||||||||||||||||
| name: Deploy and run | ||||||||||||||||||||||||||||||||||||
| needs: | ||||||||||||||||||||||||||||||||||||
| - scanner-ft-images | ||||||||||||||||||||||||||||||||||||
| - plan | ||||||||||||||||||||||||||||||||||||
| if: >- | ||||||||||||||||||||||||||||||||||||
| always() && !cancelled() && ( | ||||||||||||||||||||||||||||||||||||
| needs.scanner-ft-images.result == 'success' && ( | ||||||||||||||||||||||||||||||||||||
| (github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce')) | ||||||||||||||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result == 'success' && fromJSON(needs.plan.outputs.jobs)['scanner-ft-run'] | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||
| SCANNER_E2E_QUAY_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RO_USERNAME }} | ||||||||||||||||||||||||||||||||||||
|
|
@@ -44,6 +73,10 @@ jobs: | |||||||||||||||||||||||||||||||||||
| SCANNER_E2E_REDHAT_USERNAME: ${{ secrets.REDHAT_USERNAME }} | ||||||||||||||||||||||||||||||||||||
| SCANNER_E2E_REDHAT_PASSWORD: ${{ secrets.REDHAT_PASSWORD }} | ||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||
| - name: Fail closed when the dispatcher plan did not succeed | ||||||||||||||||||||||||||||||||||||
|
Contributor
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. [nit]
Suggested change
|
||||||||||||||||||||||||||||||||||||
| if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-dispatcher-enforce') && needs.plan.result != 'success' | ||||||||||||||||||||||||||||||||||||
| run: echo "The dispatcher plan did not succeed, so this job is not running its tests." && exit 1 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| - name: Checkout | ||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # ratchet:actions/checkout@v7.0.0 | ||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
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.
Can be simplified to
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.
Thank you for looking at it. This is my playground with dirty code :) It would be a pitty to waste cycles on reviewing it in this state. You can however get a rough direction that in which I am going (still not sure this is the right one).
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.
Agree on watching out not to spam the CI with flipping the labels too frequently. However, there are some situations in which we may want to react to labels changing. We need to think about this.