Skip to content

Commit e05962b

Browse files
committed
affected test workflow runs on PR
1 parent 0f747f5 commit e05962b

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

.github/workflows/affected-tests.yml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
name: Affected Go Tests
22

33
on:
4-
workflow_run:
5-
workflows: ["build"]
6-
types: [completed]
4+
pull_request:
5+
types: [opened, reopened, synchronize, ready_for_review]
76

87
permissions:
98
contents: read
109

1110
jobs:
1211
test-affected:
13-
# Only run if the build-test workflow succeeded and it's not a draft PR
14-
if: |
15-
github.event.workflow_run.conclusion == 'success' &&
16-
github.event.workflow_run.event == 'pull_request' &&
17-
github.event.workflow_run.pull_requests[0].draft == false
12+
if: github.event.pull_request.draft == false
1813
runs-on: ubuntu-latest
1914
timeout-minutes: 30
2015
steps:
2116
- name: Checkout
2217
uses: actions/checkout@v4
2318
with:
24-
# Check out the PR merge commit
25-
ref: ${{ github.event.workflow_run.head_sha }}
2619
fetch-depth: 0
2720

2821
- name: Setup Go
@@ -46,30 +39,20 @@ jobs:
4639
go test -c -o /dev/null "$pkg" || exit 1
4740
done < <(go list ./...)
4841
49-
- name: Get PR Base SHA
42+
- name: Compute base ref
5043
id: pr-info
51-
env:
52-
GH_TOKEN: ${{ github.token }}
5344
run: |
54-
# Get the PR number from the workflow run
55-
PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
56-
echo "PR Number: ${PR_NUMBER}"
57-
58-
# Get the base SHA for this PR
59-
BASE_SHA=$(gh pr view ${PR_NUMBER} --json baseRefOid -q .baseRefOid)
60-
echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_OUTPUT"
61-
echo "Base SHA: ${BASE_SHA}"
45+
echo "BASE_REF=origin/${{ github.base_ref }}" >> "$GITHUB_OUTPUT"
46+
echo "Base ref: origin/${{ github.base_ref }}"
6247
6348
# 2) Detect relevant unit packages and e2e tests
6449
- name: Compute affected packages
6550
id: affected
66-
env:
67-
BASE_SHA: ${{ steps.pr-info.outputs.BASE_SHA }}
6851
run: |
6952
set -euo pipefail
70-
echo "Base SHA: ${BASE_SHA}"
53+
echo "Base: ${{ steps.pr-info.outputs.BASE_REF }}"
7154
# Generate affected package list to a file for reuse in subsequent steps
72-
go run ./scripts/affected-packages.go -base "${BASE_SHA}" > /tmp/affected.txt
55+
go run ./scripts/affected-packages.go -base "${{ steps.pr-info.outputs.BASE_REF }}" > /tmp/affected.txt
7356
echo "Affected packages:" || true
7457
if [ -s /tmp/affected.txt ]; then
7558
cat /tmp/affected.txt
@@ -85,11 +68,9 @@ jobs:
8568
8669
- name: Compute affected e2e tests
8770
id: affected_e2e
88-
env:
89-
BASE_SHA: ${{ steps.pr-info.outputs.BASE_SHA }}
9071
run: |
9172
set -euo pipefail
92-
go run ./scripts/affected-packages.go -mode=suites -base "${BASE_SHA}" > /tmp/affected-e2e.txt
73+
go run ./scripts/affected-packages.go -mode=suites -base "${{ steps.pr-info.outputs.BASE_REF }}" > /tmp/affected-e2e.txt
9374
awk -F: '$1=="preflight"{print $2}' /tmp/affected-e2e.txt > /tmp/preflight-tests.txt
9475
awk -F: '$1=="support-bundle"{print $2}' /tmp/affected-e2e.txt > /tmp/support-tests.txt
9576
if [ -s /tmp/preflight-tests.txt ] || [ -s /tmp/support-tests.txt ]; then

.github/workflows/build-test-deploy.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,10 @@ jobs:
152152
# this job will validate that the validation did not fail and that all pr-tests succeed
153153
# it is used for the github branch protection rule
154154
validate-success:
155-
if: github.event_name == 'push'
155+
if: ${{ always() && github.event_name == 'push' }}
156156
runs-on: ubuntu-latest
157157
needs:
158158
- validate-pr-tests
159-
if: always()
160159
steps:
161160
# https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
162161
# if the validate-pr-tests job was not successful, this job will fail

0 commit comments

Comments
 (0)