Skip to content

Commit 8765838

Browse files
authored
revisit opt-in for PRs from forks (#1127)
1 parent 7ddf7bf commit 8765838

File tree

7 files changed

+71
-54
lines changed

7 files changed

+71
-54
lines changed

.github/actions/tests/pre_scala_test/action.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ runs:
3232
using: "composite"
3333
steps:
3434
- name: Check if static only
35+
uses: ./.github/actions/tests/skip_on_static
36+
id: check
37+
38+
- name: Skip if static only
39+
if: steps.check.outputs.skip == 'true'
3540
shell: bash
3641
run: |
37-
last_commit_msg=$(git log -1 --pretty=%B)
38-
echo "Last commit message: $last_commit_msg"
39-
if [[ "${{ github.event_name }}" == "pull_request"* ]] && [[ "$last_commit_msg" == *"[static]"* ]]; then
40-
echo "Only static tests should be running, skipping this job"
41-
echo "skip=true" >> "$GITHUB_ENV"
42-
else
43-
echo "Not static-test-only, continuing"
44-
fi
42+
echo "Only static tests should be running, skipping this job"
43+
echo "skip=true" >> "$GITHUB_ENV"
4544
4645
- name: Check if skip regex matches
4746
if: ${{ inputs.skip_if_regex != '' }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check for static tests only
2+
description: |
3+
This action checks if the current PR is only for static tests (via a commit flag ot a PR label).
4+
5+
outputs:
6+
skip:
7+
description: "Set to true if the job should be skipped"
8+
value: ${{ steps.check.outputs.skip }}
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Check if static only
14+
id: check
15+
shell: bash
16+
run: |
17+
last_commit_msg=$(git log -1 --pretty=%B)
18+
pr_labels='${{ toJSON(github.event.pull_request.labels) }}'
19+
static_label=$(echo "$pr_labels" | jq -r '.[] | select(.name == "static") | .name' | grep -c 'static' || true)
20+
echo "Last commit message: $last_commit_msg"
21+
if [[ "${{ github.event_name }}" == "pull_request"* ]]; then
22+
if [[ "$last_commit_msg" == *"[static]"* ]] || [[ "$static_label" -gt 0 ]]; then
23+
echo "Only static tests should be running"
24+
echo "Last commit message is: $last_commit_msg"
25+
echo "Static label count: $static_label (all labels: $pr_labels)"
26+
echo "skip=true" >> "$GITHUB_OUTPUT"
27+
else
28+
echo "Not static-test-only"
29+
echo "skip=false" >> "$GITHUB_OUTPUT"
30+
fi
31+
else
32+
echo "Not a pull_request or pull_request_target event, not checking for static-test-only flag"
33+
echo "skip=false" >> "$GITHUB_OUTPUT"
34+
fi

.github/workflows/build.daml_test.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,9 @@ jobs:
1919
with:
2020
ref: ${{ inputs.commit_sha }}
2121

22-
- name: Skip on [static]
22+
- name: Check if static only
23+
uses: ./.github/actions/tests/skip_on_static
2324
id: skip
24-
shell: bash
25-
run: |
26-
git fetch origin ${{ github.event.pull_request.head.sha }}
27-
last_commit_msg=$(git log -1 --pretty=%B ${{ github.event.pull_request.head.sha }})
28-
echo "Last commit message: $last_commit_msg"
29-
30-
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
31-
if [[ "$last_commit_msg" == *"[static]"* ]]; then
32-
echo "Skipping Daml tests because of [static] label"
33-
echo "skip=true" >> "$GITHUB_OUTPUT"
34-
fi
35-
fi
3625

3726
- name: Setup
3827
if: steps.skip.outputs.skip != 'true'

.github/workflows/build.ts_cli_tests.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,9 @@ jobs:
2626
with:
2727
ref: ${{ inputs.commit_sha }}
2828

29-
- name: Skip on [static]
29+
- name: Check if static only
30+
uses: ./.github/actions/tests/skip_on_static
3031
id: skip
31-
shell: bash
32-
run: |
33-
last_commit_msg=$(git log -1 --pretty=%B)
34-
echo "Last commit message: $last_commit_msg"
35-
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
36-
if [[ "$last_commit_msg" == *"[static]"* ]]; then
37-
echo "Skipping UI tests because of [static] label"
38-
echo "skip=true" >> "$GITHUB_OUTPUT"
39-
fi
40-
fi
4132

4233
- name: Setup
4334
id: setup

.github/workflows/build.ui_tests.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,9 @@ jobs:
2020
# Checkout the PR head commit to get the commit message first
2121
ref: ${{ github.event.pull_request.head.sha }}
2222

23-
- name: Skip on [static]
23+
- name: Check if static only
24+
uses: ./.github/actions/tests/skip_on_static
2425
id: skip
25-
shell: bash
26-
run: |
27-
last_commit_msg=$(git log -1 --pretty=%B)
28-
echo "Last commit message: $last_commit_msg"
29-
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
30-
if [[ "$last_commit_msg" == *"[static]"* ]]; then
31-
echo "Skipping UI tests because of [static] label"
32-
echo "skip=true" >> "$GITHUB_OUTPUT"
33-
fi
34-
fi
3526

3627
- name: Check out repository code
3728
uses: actions/checkout@v4

.github/workflows/build.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ jobs:
3535

3636
cancel_if_not_opt_in:
3737
runs-on: self-hosted-docker-tiny
38-
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
38+
# Note that we don't auto-cancel on merged commits (e.g. in a post-merge workflow), and on
39+
# pull_request_target events (which indicate that we are running from a fork).
40+
if: github.event_name == 'pull_request'
3941
name: Cancel if not opted in
4042
permissions:
4143
actions: write
4244
contents: read
4345
steps:
4446
- name: Checkout code
4547
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
48+
- name: Check if static only
49+
uses: ./.github/actions/tests/skip_on_static
50+
id: static_only
4651
- name: Cancel if not opted in
4752
shell: bash
4853
run: |
4954
git fetch origin ${{ github.event.pull_request.head.sha }}
5055
last_commit_msg=$(git log -1 --pretty=%B ${{ github.event.pull_request.head.sha }})
5156
echo "Last commit message: $last_commit_msg"
52-
if [[ $last_commit_msg != *"[ci]"* ]] && [[ "$last_commit_msg" != *"[static]"* ]] ; then
57+
if [[ $last_commit_msg != *"[ci]"* ]] && [[ "${{ steps.static_only.outputs.skip }}" == "false" ]] ; then
5358
echo "Cancelling the entire workflow because the current commit does not opt in for CI."
5459
curl -fsSL -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github+json" "${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
5560
else
@@ -301,6 +306,9 @@ jobs:
301306
steps:
302307
- name: Checkout code
303308
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
309+
- name: Check if static only
310+
uses: ./.github/actions/tests/skip_on_static
311+
id: static_only
304312
- name: Handle [force] and [static] labels
305313
shell: bash
306314
run: |
@@ -310,7 +318,7 @@ jobs:
310318
if [[ $last_commit_msg == *"[force]"* ]]; then
311319
echo "Skipping the check for job success because the current commit opts in for a forced run."
312320
echo "FORCE=true" >> "$GITHUB_ENV"
313-
elif [[ "$last_commit_msg" == *"[static]"* ]]; then
321+
elif [[ "${{ steps.static_only.outputs.skip }}" == "true" ]]; then
314322
echo "Only static tests are required"
315323
# shellcheck disable=SC2129
316324
echo "FORCE=false" >> "$GITHUB_ENV"

TESTING.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,24 @@ Splice code is tested in the following ways:
4848

4949
### Opting-in to CI
5050

51-
At the moment, CI is by default being cancelled on commits, unless explicitly opted in. (CI jobs will report
52-
the error `Build was canceled`.) To enable CI for your commit, please include the text `[ci]` in your commit
53-
message.
51+
For PRs using branches in this repo (as opposed to PRs from forks), CI is by default being cancelled on commits,
52+
unless explicitly opted in. (CI jobs will report the error `Build was canceled`.)
53+
To enable CI for your commit, please include the text `[ci]` in your commit message.
54+
55+
This is not required for PRs from forks, which are automatically opted-in for CI (but require a Contributor's approval to run).
56+
57+
### Running static tests only in CI
58+
59+
For changes e.g. in Pulumi deployment configurations, deployment scripts, etc., that would not affect
60+
integration tests, one can opt-in to running static tests only.
61+
To run only static tests (and skip e.g. integration tests) on your PR, either include the text `[static]`
62+
in your last commit message, or add a "static" GitHub label to the PR.
5463

5564
### Opting-out of CI
5665

5766
In certain cases, it may be valid to allow a PR to be merged without going through CI.
5867
While `[skip ci]` is supported, it does not allow the PR to be merged. To skip testing but
59-
stil allow the PR to be merged, please include the text `[force]` in your commit message.
60-
61-
Alternatively, to run only static tests (and skip e.g. integration tests) on your PR,
62-
include the text `[static]` in your commit message. This is recommended for, e.g. changes in
63-
Pulumi deployment configurations, deployment scripts, etc.
68+
still allow the PR to be merged, please include the text `[force]` in your last commit message.
6469

6570
### Requesting Cluster Tests
6671

0 commit comments

Comments
 (0)