Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/auto-approve-bot-prs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ jobs:

This PR has been automatically approved by the auto-approve workflow.

/override ci/prow/e2e-ocp-helm

**Labels Added:** \`lgtm\`, \`approved\`"
42 changes: 42 additions & 0 deletions .github/workflows/e2e-ocp-gate-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: E2E OCP Gate Tests

on:
pull_request:
paths:
- "scripts/e2e-gate/**"
- ".github/workflows/e2e-ocp-gate-tests.yaml"

permissions:
contents: read

jobs:
test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false

- name: Set up Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version-file: ".nvmrc"

- name: Run gate rule tests
run: node --test "scripts/e2e-gate/*.test.mts"
78 changes: 78 additions & 0 deletions .github/workflows/pr-podman-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ jobs:
contents: read
issues: write
pull-requests: write
outputs:
pr_number: ${{ steps.get-pr-info.outputs.pr_number }}
is_skipped: ${{ steps.check-skip.outputs.is_skipped }}
# Outcome of the push itself; later comment steps can fail the job after
# the image was published.
push_outcome: ${{ steps.push.outcome }}

steps:
- name: Get PR number from workflow run
Expand Down Expand Up @@ -256,6 +262,7 @@ jobs:
} >> "$GITHUB_OUTPUT"

- name: Push Images
id: push
if: ${{ github.event.workflow_run.conclusion == 'success' && steps.check-skip.outputs.is_skipped != 'true' }}
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
env:
Expand Down Expand Up @@ -364,3 +371,74 @@ jobs:
repo: context.repo.repo,
body: body
})

# Decides whether the PR needs the e2e-ocp-helm Prow job, which claims an
# ephemeral OpenShift cluster on every run. See scripts/e2e-gate/README.md.
#
# Runs only trusted code: the gate scripts come from the default branch and
# the PR is read through the API, never checked out.
e2e-ocp-gate:
name: Decide e2e-ocp-helm
needs: podman-push
# Also runs when the build was cancelled, publishing failed or the PR
# number is unknown, so the PR gets a failing status instead of none. A
# build cancelled by a newer push is ignored because the PR head moved.
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
statuses: write

steps:
# No `ref`: in a workflow_run job, checkout uses the default branch head
# (GITHUB_SHA), never the PR.
- name: Checkout gate scripts from the default branch
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
with:
persist-credentials: false
sparse-checkout: |
scripts/e2e-gate
.nvmrc
sparse-checkout-cone-mode: false

- name: Set up Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version-file: ".nvmrc"

- name: Decide and report
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# rhdh-bot is an org member, so Prow accepts its /test comments.
RHDH_BOT_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
PR_NUMBER: ${{ needs.podman-push.outputs.pr_number }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
BUILD_CONCLUSION: ${{ github.event.workflow_run.conclusion }}
PUBLISH_RESULT: ${{ needs.podman-push.outputs.push_outcome }}
IMAGE_SKIPPED: ${{ needs.podman-push.outputs.is_skipped }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: node scripts/e2e-gate/gate.mts

# Prow no longer starts e2e-ocp-helm on push, so if any step above fails,
# set an error status rather than leave Tide waiting with no message.
# Uses only gh, so it works even when checkout or Node setup failed.
- name: Report a gate failure
if: ${{ failure() }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
# A Prow result stands; only the gate's own statuses are replaced.
prow=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/statuses?per_page=100" \
--jq '[.[] | select(.context == "ci/prow/e2e-ocp-helm" and .creator.login != "github-actions[bot]")] | length')
if [ "$prow" -gt 0 ]; then
echo "Prow already reported for this commit; leaving it."
exit 0
fi
gh api "repos/${GITHUB_REPOSITORY}/statuses/${HEAD_SHA}" \
-f state=error \
-f context=ci/prow/e2e-ocp-helm \
-f description="The e2e-ocp-helm gate failed. Re-run it, or comment /test e2e-ocp-helm" \
-f target_url="$RUN_URL"
11 changes: 8 additions & 3 deletions docs/e2e-tests/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ When a new Pull Request (PR) is opened at [rhdh](https://github.com/redhat-devel

### Automatic Triggering of Tests

- **Code Changes Affecting Tests:** PR tests are triggered automatically if the changes include code modifications that could impact tests. This means that for PRs involving code that affects functionality or test suites, the CI will automatically initiate the testing process.
- **Documentation-Only Changes:** PRs that involve only documentation updates will skip the tests to conserve CI resources, as they do not affect the codebase or functionality.
The mandatory `e2e-ocp-helm` check claims an ephemeral OpenShift cluster on every run, so Prow does not start it on push. After the PR image is built and published, the **Decide e2e-ocp-helm** job in `pr-podman-push.yaml` decides what the PR needs (see [the gate README](../../scripts/e2e-gate/README.md)):

- **Code Changes Affecting Tests:** rhdh-bot comments `/test e2e-ocp-helm` and the job runs against the PR image.
- **Changes That Do Not Need a Cluster:** For PRs that only change docs, repository tooling, AI agent config, the cluster-free e2e harness or CI for other platforms, the gate marks `ci/prow/e2e-ocp-helm` as passed without claiming a cluster. The same applies to rhdh-bot PRs tagged `[skip-e2e]`.
- **Dependency Bot PRs:** For Renovate and Dependabot PRs, the check stays pending until a reviewer comments `/test e2e-ocp-helm`, so rebases do not each claim a cluster.
- **Draft PRs:** The check stays pending while the PR is a draft. Marking it ready for review does not start it: comment `/test e2e-ocp-helm`, or push again.
- **Image Build Problems:** If the PR image fails to build or publish, the check fails with the reason instead of waiting for an image that will not appear.

### Manual Triggering of Tests

Expand Down Expand Up @@ -50,7 +55,7 @@ If the initial automatically triggered tests fail, OpenShift-CI will add a comme

- **Purpose:** Validate new PRs for code quality, functionality, and integration.
- **Trigger:**
- **Automatic:** When a PR includes code changes affecting tests (excluding doc-only changes), tests are automatically triggered.
- **Automatic:** The e2e-ocp-helm gate comments `/test e2e-ocp-helm` once the PR image is published, for PRs whose changes need a cluster. Other PRs get the status from the gate without a cluster.
- **Manual:** When `/ok-to-test` is commented by an `openshift` and `redhat-developer` org member for external contributors or when `/test`, `/test images`, or `/test e2e-ocp-helm` is commented after validation.
- **Environment:** Runs on ephemeral OpenShift clusters managed by Hive. Kubernetes jobs use ephemeral EKS and AKS clusters on spot instances managed by [Mapt](https://github.com/redhat-developer/mapt). GKE uses a long-running cluster.
- **Configurations:**
Expand Down
56 changes: 56 additions & 0 deletions scripts/e2e-gate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# e2e-ocp-helm gate

The `ci/prow/e2e-ocp-helm` PR check claims an ephemeral OpenShift cluster on
every run, and a large share of those claims were avoidable (RHIDP-16423):
Renovate rebases, rhdh-bot `[skip-e2e]` PRs, PRs that changed no product code,
and runs that sat on a cluster waiting for the PR image.

Prow no longer starts the job on push. The **Decide e2e-ocp-helm** job in
[`pr-podman-push.yaml`](../../.github/workflows/pr-podman-push.yaml) runs once the PR
image is published and decides what the PR needs.

## What the gate decides

| Decision | When | What happens |
| -------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `skip` | Every changed file matches a no-cluster rule, or rhdh-bot opened a `[skip-e2e]` PR | Sets `ci/prow/e2e-ocp-helm` to success with the reason, marked `[prow:skip-retest]` |
| `fail` | The image build failed, publishing failed, or `[skip-build]` left no image for a product change | Sets the status to failure with the reason |
| `wait` | Renovate or Dependabot PR, an author Prow does not trust, or a draft PR | Sets the status to pending, asking for `/test e2e-ocp-helm` (and `/ok-to-test` for untrusted authors) |
| `run` | Anything else | Sets the status to pending, then rhdh-bot comments `/test e2e-ocp-helm` and Prow runs the job |

Rules are checked in this order. They live in [`rules.mts`](rules.mts); the
order is in [`decide.mts`](decide.mts).

## Design decisions

| Decision | Why |
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Decide in GitHub Actions, after the image | Prow claims the cluster before any job step runs, so a check inside the job is too late. |
| Unknown paths run | A missing rule costs a cluster, never a skipped test. A renamed file counts under its old and new path. GitHub lists at most 3000 files, so a PR with that many never skips. |
| Skips carry `[prow:skip-retest]` | Tide counts a required job as passed only when a ProwJob exists or a success status carries this marker. Without it, Tide would start the job itself before merging a skipped PR. |
| Image problems before any `wait` | A PR with no image gets `fail`, not "comment `/test`", which would claim a cluster and wait 60 minutes for nothing. |
| `[skip-build]` directories mirror Prow | When the image build is skipped, the Prow step tests the `next` image only if every change is under its `DIRECTORIES_TO_CHECK`. `PREBUILT_IMAGE_OK_PATHS` must match it; anything else fails. |
| Renovate and Dependabot wait | They rebase many times before merge, and each rebase used to claim a cluster. |
| Trust matches Prow | rhdh-bot's `/test` bypasses `/ok-to-test`, so the gate only runs PRs from org members (private ones too, checked with rhdh-bot's token), collaborators, or PRs with `ok-to-test`. |
| Drafts wait; marking ready does nothing | Re-running on `ready_for_review` would rebuild the image and need the trigger backported to every release branch. Comment `/test` or push instead. |
| Prow results win | Once Prow reports on a commit, the gate never overwrites it or requests a second run. A hidden marker in rhdh-bot's `/test` comment stops duplicate requests on re-runs. |
| Cancelled builds fail | A build cancelled for the current head fails the check, so the PR shows why it cannot merge. A build cancelled by a newer push is ignored because the head moved. |
| Gate errors set `error` | If any gate step fails, a final `gh` step sets `error` with a link to the run (unless Prow already reported), so Tide never waits on a status that will not arrive. A failed org membership check is an error, not "untrusted". |
| Still required for merge | openshift/release sets `require_manually_triggered_jobs: true`, so Tide waits for the status even though Prow no longer starts the job. |
| One copy of the rules | `workflow_run` jobs run from `main`, so `main` decides for every release branch. A PR cannot test its own gate changes. |
| Plain `node` and `fetch`, no installs | The job holds `RHDH_BOT_TOKEN`, so no third-party packages run in it. Node 24 runs the `.mts` files directly, like the other scripts in `scripts/`. `actions/github-script` would add Octokit but has no clean way to use a second token. |
| Never checks out PR code | The job checks out only the default branch and reads the PR through the API. |

## Running the job by hand

Comment `/test e2e-ocp-helm` at any time; a Prow run replaces any status the
gate set. Use it for dependency PRs before merging, drafts or PRs just marked
ready, PRs whose image build was skipped, or a skipped change you still want
tested on a cluster.

## Changing the rules

1. Edit `rules.mts` and add a case to `decide.test.mts`.
2. Run `node --test "scripts/e2e-gate/*.test.mts"` (Node from `.nvmrc`, no
install).
3. The rules take effect once merged to `main`.
Loading
Loading