Skip to content

Commit 16993ad

Browse files
getdevopspro-cibotjobcespedes
authored andcommitted
feat(ci): add test gating
1 parent 33da296 commit 16993ad

16 files changed

Lines changed: 826 additions & 996 deletions

.eslintignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Robot Test Check Labels"
2+
description: "Fails if test-robot-needed is present but test-robot-done is not."
3+
4+
inputs:
5+
label-test-robot-needed:
6+
description: 'Label indicating the PR needs robot testing'
7+
required: false
8+
default: 'test-robot-needed'
9+
label-test-robot-done:
10+
description: 'Label indicating the PR has been robot-tested'
11+
required: false
12+
default: 'test-robot-done'
13+
token:
14+
description: 'GitHub token or PAT used to post comments (defaults to github.token)'
15+
required: false
16+
default: ''
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Check robot test labels
22+
uses: actions/github-script@v7
23+
with:
24+
github-token: ${{ inputs.token || github.token }}
25+
script: |
26+
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
27+
const labelDone = '${{ inputs.label-test-robot-done }}';
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
30+
31+
const postComment = async (body) => {
32+
try {
33+
await github.rest.issues.createComment({ ...repo, issue_number: pr, body });
34+
} catch (err) {
35+
core.warning(`Could not post comment: ${err.message}`);
36+
}
37+
};
38+
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
41+
42+
if (!has.has(labelNeeded)) {
43+
core.info(`\`${labelNeeded}\` not present — no robot testing required.`);
44+
return;
45+
}
46+
47+
if (has.has(labelDone)) {
48+
core.info(`\`${labelDone}\` present — robot testing confirmed.`);
49+
return;
50+
}
51+
52+
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
53+
await postComment(
54+
`### ❌ Robot Testing Required\n\n` +
55+
`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added. This PR cannot be merged until robot testing is complete.${shaLine}\n\n` +
56+
`> [!IMPORTANT]\n> Add \`${labelDone}\` once robot testing is complete.`
57+
);
58+
core.setFailed(`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added — robot testing must be completed before merging.`);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Robot Test Label"
2+
description: "When the test-robot-done label is added, posts a comment confirming the robot test status."
3+
4+
inputs:
5+
label-test-robot-needed:
6+
description: 'Label indicating the PR needs robot testing'
7+
required: false
8+
default: 'test-robot-needed'
9+
label-test-robot-done:
10+
description: 'Label indicating the PR has been robot-tested'
11+
required: false
12+
default: 'test-robot-done'
13+
token:
14+
description: 'GitHub token or PAT used to post comments (defaults to github.token)'
15+
required: false
16+
default: ''
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Comment on label added
22+
uses: actions/github-script@v7
23+
with:
24+
github-token: ${{ inputs.token || github.token }}
25+
script: |
26+
const labelDone = '${{ inputs.label-test-robot-done }}';
27+
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
30+
31+
const postComment = async (body) => {
32+
try {
33+
await github.rest.issues.createComment({ ...repo, issue_number: pr, body });
34+
} catch (err) {
35+
core.warning(`Could not post comment: ${err.message}`);
36+
}
37+
};
38+
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
41+
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
42+
43+
if (!has.has(labelDone)) {
44+
if (has.has(labelNeeded)) {
45+
core.warning(`\`${labelDone}\` not found — \`${labelNeeded}\` is present but testing is not confirmed.`);
46+
await postComment(
47+
`### ⚠️ Robot Testing Incomplete\n\n` +
48+
`\`${labelNeeded}\` is present but \`${labelDone}\` has not been added yet.${shaLine}\n\n` +
49+
`> [!WARNING]\n> Add \`${labelDone}\` once robot testing is complete.`
50+
);
51+
} else {
52+
core.info(`\`${labelDone}\` not present — nothing to do.`);
53+
}
54+
return;
55+
}
56+
57+
core.info(`\`${labelDone}\` found — posting confirmation comment.`);
58+
await postComment(
59+
`### ✅ Robot Test Complete\n\n` +
60+
`\`${labelDone}\` has been added — robot testing has been confirmed for this PR.${shaLine}`
61+
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Robot Test Unlabel"
2+
description: "On new commits, removes the test-robot-done label if present and posts a comment."
3+
4+
inputs:
5+
label-test-robot-needed:
6+
description: 'Label indicating the PR needs robot testing'
7+
required: false
8+
default: 'test-robot-needed'
9+
label-test-robot-done:
10+
description: 'Label indicating the PR has been robot-tested'
11+
required: false
12+
default: 'test-robot-done'
13+
token:
14+
description: 'GitHub token or PAT used to remove labels and post comments (defaults to github.token)'
15+
required: false
16+
default: ''
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Remove label and comment
22+
uses: actions/github-script@v7
23+
with:
24+
github-token: ${{ inputs.token || github.token }}
25+
script: |
26+
const labelDone = '${{ inputs.label-test-robot-done }}';
27+
const labelNeeded = '${{ inputs.label-test-robot-needed }}';
28+
const { number: pr, head: { sha } } = context.payload.pull_request;
29+
const repo = context.repo;
30+
31+
const postComment = async (body) => {
32+
try {
33+
await github.rest.issues.createComment({ ...repo, issue_number: pr, body });
34+
} catch (err) {
35+
core.warning(`Could not post comment: ${err.message}`);
36+
}
37+
};
38+
39+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ ...repo, issue_number: pr });
40+
const has = new Set(labels.map(l => l.name));
41+
42+
if (!has.has(labelDone)) {
43+
core.info(`\`${labelDone}\` not present — nothing to do.`);
44+
return;
45+
}
46+
47+
await github.rest.issues.removeLabel({ ...repo, issue_number: pr, name: labelDone });
48+
core.info(`\`${labelDone}\` removed.`);
49+
50+
const shaLine = sha ? `\n\n**Commit:** \`${sha}\`` : '';
51+
const warning = !has.has(labelNeeded)
52+
? `\n\n> [!WARNING]\n> \`${labelDone}\` was removed but \`${labelNeeded}\` was not present — this PR may not be queued for robot testing.`
53+
: '';
54+
55+
await postComment(
56+
`### 🔄 Robot Test Label Removed\n\n` +
57+
`New commits were pushed. \`${labelDone}\` has been removed and robot testing must be repeated.${shaLine}${warning}`
58+
);

.github/workflows/all-green.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: All Green
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
all-green:
8+
name: All Green
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: All Green
14+
uses: getdevopspro/github-actions/all-green@v6.1.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
build:
1212
name: Build
13-
uses: getdevopspro/github-actions/.github/workflows/build.yml@v6.0.4
13+
uses: getdevopspro/github-actions/.github/workflows/build.yml@v6.1.1
1414
with:
1515
version-package: package.json
1616
version-package-lock: package-lock.json
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PR - Label
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
actions: write
15+
16+
jobs:
17+
test-robot-label:
18+
name: Job
19+
uses: ./.github/workflows/test-robot-label.yml
20+
with:
21+
label-test-robot-done: test-robot-done
22+
label-test-robot-needed: test-robot-needed
23+
secrets:
24+
token: ${{ secrets.BOT_PR_TOKEN }}

.github/workflows/pull-request.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,34 @@ concurrency:
1111
permissions:
1212
contents: read
1313
packages: write
14+
pull-requests: write
1415

1516
jobs:
17+
test-robot-unlabel:
18+
if: github.event.action == 'synchronize'
19+
name: Job
20+
uses: ./.github/workflows/test-robot-unlabel.yml
21+
with:
22+
label-test-robot-done: test-robot-done
23+
label-test-robot-needed: test-robot-needed
24+
secrets:
25+
token: ${{ secrets.BOT_PR_TOKEN }}
26+
1627
build:
28+
needs: test-robot-unlabel
29+
if: ${{ !failure() && !cancelled() && needs.test-robot-unlabel.result != 'failure' }}
30+
name: Job
31+
uses: ./.github/workflows/build.yml
32+
33+
test-robot-check:
34+
needs: build
35+
name: Job
36+
uses: ./.github/workflows/test-robot-check.yml
37+
with:
38+
label-test-robot-done: test-robot-done
39+
label-test-robot-needed: test-robot-needed
40+
41+
all-green:
42+
needs: test-robot-check
1743
name: Job
18-
uses: ./.github/workflows/build.yaml
44+
uses: ./.github/workflows/all-green.yml

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ permissions:
1919
jobs:
2020
build:
2121
name: Job
22-
uses: ./.github/workflows/build.yaml
22+
uses: ./.github/workflows/build.yml
2323

2424
promote:
2525
name: Job
2626
needs: build
27-
uses: getdevopspro/github-actions/.github/workflows/promote.yml@v6.0.4
27+
uses: getdevopspro/github-actions/.github/workflows/promote.yml@v6.1.1
2828
secrets:
2929
# To bypass ruleset enforcing checks
3030
checkout-token: ${{ secrets.BOT_RELEASE_CHECKOUT_TOKEN }}

0 commit comments

Comments
 (0)