Skip to content

Commit caa4406

Browse files
wip
1 parent f780f9f commit caa4406

7 files changed

Lines changed: 178 additions & 42 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# General: "needs-robot-testing" and "robot-tested" should be the default values of two inputs.
2-
# 1. It should check if "needs-robot-testing" label is present.
3-
# 2. It should check if "robot-tested" label is present.
4-
# 3. If "needs-robot-testing" is present and "robot-tested" is not present, it should fail with an error message saying "PR needs robot testing but is not marked as robot-tested."
1+
# General: "test-robot-needed" and "test-robot-done" should be the default values of two inputs.
2+
# 1. It should check if "test-robot-needed" label is present.
3+
# 2. It should check if "test-robot-done" label is present.
4+
# 3. If "test-robot-needed" is present and "test-robot-done" is not present, it should fail with an error message saying "PR needs robot testing but is not marked as test-robot-done."
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
# General: "robot-tested" should be the default value of an input.
2-
# 1. It should check if "robot-tested" label is present.
3-
# 2. If present, it should add a comment saying "PR is marked as robot-tested.". it should also include the commit sha, (only if available), it was marked for.
4-
# 3.
1+
name: "Test Label"
2+
description: "Checks if the test-robot-done label is present on the PR and adds a confirming comment."
3+
4+
inputs:
5+
label-test-robot-done:
6+
description: 'Label name indicating the PR has been test-robot-done'
7+
required: false
8+
default: 'test-robot-done'
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Check test-robot-done label and add comment
14+
shell: bash
15+
env:
16+
GH_TOKEN: ${{ github.token }}
17+
PR_NUMBER: ${{ github.event.pull_request.number }}
18+
REPO: ${{ github.repository }}
19+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
20+
LABEL_ROBOT_TESTED: ${{ inputs.label-test-robot-done }}
21+
run: |
22+
LABELS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '.labels[].name')
23+
24+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TESTED"; then
25+
if [ -n "$COMMIT_SHA" ]; then
26+
COMMENT="PR is marked as \`${LABEL_ROBOT_TESTED}\`. (commit: \`${COMMIT_SHA}\`)"
27+
else
28+
COMMENT="PR is marked as \`${LABEL_ROBOT_TESTED}\`."
29+
fi
30+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$COMMENT"
31+
fi
Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
# General: "needs-robot-testing" and "robot-tested" should be the default values of two inputs.
2-
# 1. It should check if "needs-robot-testing" label is present.
3-
# 2. It should check if "robot-tested" label is present.
4-
# 3. If present, it should remove the label.
5-
# 4. If removed, it should add a comment saying the label is removed and also include the commit sha, (only if available), it was removed for. If "needs-robot-testing" was not present, it should also include a warning that the label was removed without "needs-robot-testing" being present.
1+
name: "Test Unlabel"
2+
description: "Removes the test-robot-done label from the PR if present and adds a comment."
3+
4+
inputs:
5+
label-test-robot-needed:
6+
description: 'Label name indicating the PR needs robot testing'
7+
required: false
8+
default: 'test-robot-needed'
9+
label-test-robot-done:
10+
description: 'Label name indicating the PR has been test-robot-done'
11+
required: false
12+
default: 'test-robot-done'
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Remove test-robot-done label and add comment
18+
shell: bash
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
PR_NUMBER: ${{ github.event.pull_request.number }}
22+
REPO: ${{ github.repository }}
23+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
24+
LABEL_ROBOT_TESTED: ${{ inputs.label-test-robot-done }}
25+
LABEL_ROBOT_TEST_NEEDED: ${{ inputs.label-test-robot-needed }}
26+
run: |
27+
LABELS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '.labels[].name')
28+
29+
NEEDS_TESTING=false
30+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TEST_NEEDED"; then
31+
NEEDS_TESTING=true
32+
fi
33+
34+
if echo "$LABELS" | grep -qx "$LABEL_ROBOT_TESTED"; then
35+
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$LABEL_ROBOT_TESTED"
36+
37+
if [ -n "$COMMIT_SHA" ]; then
38+
COMMENT="Label \`${LABEL_ROBOT_TESTED}\` has been removed. (commit: \`${COMMIT_SHA}\`)"
39+
else
40+
COMMENT="Label \`${LABEL_ROBOT_TESTED}\` has been removed."
41+
fi
42+
43+
if [ "$NEEDS_TESTING" = "false" ]; then
44+
COMMENT="${COMMENT}\n\n> [!WARNING]\n> Label \`${LABEL_ROBOT_TESTED}\` was removed without \`${LABEL_ROBOT_TEST_NEEDED}\` being present."
45+
fi
46+
47+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$(printf "%b" "$COMMENT")"
48+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
15+
jobs:
16+
test-robot-label:
17+
if: github.event.label.name == 'test-robot-done'
18+
name: Job
19+
uses: ./.github/workflows/test-robot-label.yaml
20+
with:
21+
label-test-robot-done: test-robot-done

.github/workflows/pull-request.yml

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: PR
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened, labeled]
5+
types: [opened, synchronize, reopened]
66

77
concurrency:
88
group: ${{ github.workflow }}-${{ github.ref }}
@@ -11,35 +11,19 @@ concurrency:
1111
permissions:
1212
contents: read
1313
packages: write
14-
15-
env:
16-
LABEL_ROBOT_TEST_NEEDED: needs-robot-testing
17-
LABEL_ROBOT_TESTED: robot-tested
14+
pull-requests: write
1815

1916
jobs:
20-
test-label:
21-
if: github.event.label.name == env.LABEL_ROBOT_TESTED
22-
name: Test Label
23-
runs-on: ubuntu-latest
24-
steps:
25-
- name: Test Label Added
26-
uses: ./.github/actions/test-unlabel
27-
with:
28-
label-robot-tested: ${{ env.LABEL_ROBOT_TESTED }}
29-
30-
test-unlabel:
17+
test-robot-unlabel:
3118
if: github.event.action == 'synchronize'
32-
name: Test Unlabel
33-
runs-on: ubuntu-latest
34-
steps:
35-
- name: Remove Test Label
36-
uses: ./.github/actions/test-label
37-
with:
38-
label-robot-tested: ${{ env.LABEL_ROBOT_TESTED }}
39-
label-robot-test-needed: ${{ env.LABEL_ROBOT_TEST_NEEDED }}
40-
41-
build:
42-
needs: test-remove-labels
43-
if: always() && github.event.action != 'labeled'
4419
name: Job
45-
uses: ./.github/workflows/build.yaml
20+
uses: ./.github/workflows/test-robot-unlabel.yaml
21+
with:
22+
label-test-robot-done: test-robot-done
23+
label-test-robot-needed: test-robot-needed
24+
25+
# build:
26+
# needs: test-robot-unlabel
27+
# if: always() && needs.test-robot-unlabel.result != 'failure'
28+
# name: Job
29+
# uses: ./.github/workflows/build.yaml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test Robot Label
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
label-test-robot-done:
7+
description: 'Label name indicating the PR has been test-robot-done'
8+
type: string
9+
required: false
10+
default: 'test-robot-done'
11+
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
16+
jobs:
17+
test-robot-label:
18+
if: github.event.action == 'labeled' &&
19+
github.event.label.name == inputs['label-test-robot-done']
20+
name: Test Robot Label
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Test Robot Label
26+
uses: ./.github/actions/test-label
27+
with:
28+
label-test-robot-done: ${{ inputs.label-test-robot-done }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test Robot Unlabel
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
label-test-robot-done:
7+
description: 'Label name indicating the PR has been test-robot-done'
8+
type: string
9+
required: false
10+
default: 'test-robot-done'
11+
label-test-robot-needed:
12+
description: 'Label name indicating the PR needs robot testing'
13+
type: string
14+
required: false
15+
default: 'test-robot-needed'
16+
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
21+
jobs:
22+
test-robot-unlabel:
23+
if: contains(github.event.pull_request.labels.*.name, inputs.label-test-robot-needed)
24+
name: Test Robot Unlabel
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Remove Robot Unlabel
30+
uses: ./.github/actions/test-unlabel
31+
with:
32+
label-test-robot-done: ${{ inputs.label-test-robot-done }}
33+
label-test-robot-needed: ${{ inputs.label-test-robot-needed }}

0 commit comments

Comments
 (0)