Skip to content

Commit ecc399e

Browse files
authored
Merge pull request #34 from NixOS/pr-workflow
Switch to PR-based process
2 parents a64b82d + 50673a7 commit ecc399e

File tree

7 files changed

+171
-34
lines changed

7 files changed

+171
-34
lines changed

.github/workflows/nomination.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: nomination
2+
3+
on:
4+
pull_request_target:
5+
types: [edited, opened, synchronize, reopened]
6+
7+
# We don't need to use the GitHub App for this workflow,
8+
# because it's all localised to this repo
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
process:
15+
name: Check
16+
runs-on: ubuntu-latest
17+
if: ${{ ! contains(github.event.pull_request.labels.*.name, 'nomination') && github.event.pull_request.head.ref != 'create-pull-request/sync' }}
18+
steps:
19+
- name: Fetch source
20+
uses: actions/checkout@v4
21+
- name: Process nomination
22+
run: |
23+
set -o pipefail
24+
gh api "repos/$REPOSITORY/pulls/$PR_NUMBER/files" \
25+
--jq '.[] | "\(.status) \(.filename)"' \
26+
| scripts/nomination.sh members "$REPOSITORY" "$PR_NUMBER" "$ANNOUNCEMENT_ISSUE_NUMBER"
27+
env:
28+
REPOSITORY: ${{ github.repository }}
29+
PR_NUMBER: ${{ github.event.pull_request.number }}
30+
ANNOUNCEMENT_ISSUE_NUMBER: "${{
31+
github.repository_owner == 'NixOS' && 35 ||
32+
github.repository_owner == 'infinisil-test-org' && 30 ||
33+
'NO_ISSUE_NUMBER'
34+
}}"
35+
GH_TOKEN: ${{ github.token }}
36+
PROD: "1"

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ whose members have write access to [Nixpkgs](https://github.com/nixos/nixpkgs).
66

77
The [Nixpkgs commit delegators](https://github.com/orgs/NixOS/teams/commit-bit-delegation)
88
maintain the member list in this repository.
9-
While it's in principle possible to request Nixpkgs commit permissions by creating a PR,
10-
please nominate yourself in [this issue](https://github.com/NixOS/nixpkgs/issues/321665) instead.
9+
10+
## Nominations
11+
12+
To nominate yourself or somebody else:
13+
1. Check [open nominations](/../../issues?q=state%3Aopen%20label%3Anomination) to make sure the user hasn't been nominated already.
14+
1. [Click this link](/../../new/main/members?filename=%3CGITHUB_HANDLE%3E) to create a new file in the [`members` directory](./members).
15+
1. Leave the file contents empty and replace `<GITHUB_HANDLE>` with the handle (without `@`) of the user you'd like to nominate .
16+
1. Click on "Commit changes..." and follow the steps to create a PR.
17+
1. State your motivation for the nomination in the PR description.
18+
19+
Such nominations are also automatically announced in [this issue](/../../issues/35), which you can subscribe to for updates.
1120

1221
## Semi-automatic synchronisation
1322

scripts/README.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,41 @@ scripts/sync.sh infinisil-test-org actors members-test
4141

4242
Check that it synchronises the files in the `members-test` directory with the team members of the `actors` team.
4343

44-
## `retire.sh`
44+
## Testing `nomination.sh`
45+
46+
This script does not depend on the current repository, but has some external effects.
47+
For testing, we'll use [PR #33](https://github.com/infinisil-test-org/nixpkgs-committers/pull/33) and [issue #30](https://github.com/infinisil-test-org/nixpkgs-committers/issues/30).
48+
49+
To test:
50+
1. Delete all labels of the PR and reset the title:
51+
```bash
52+
gh api --method DELETE /repos/infinisil-test-org/nixpkgs-committers/issues/33/labels
53+
gh api --method PATCH /repos/infinisil-test-org/nixpkgs-committers/pulls/33 -f title="A non-conforming title"
54+
```
55+
1. Run the script while simulating that a non-nomination PR was opened:
56+
```bash
57+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 30 <<< "removed members/infinisil"
58+
```
59+
60+
Ensure that it exits with 0 and wouldn't run any effects.
61+
1. Run the script while simulating that multiple users were nominated together:
62+
```bash
63+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 30 <<< "removed members/foo"$'\n'"added members/bar"
64+
```
65+
66+
Ensure that it exits with non-0 and wouldn't run any effects.
67+
1. Run the script simulating a successful nomination
68+
```bash
69+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 30 <<< "added members/infinisil"
70+
```
71+
72+
Ensure that it exits with 0 and would run effects to label the PR, change the title and post a comment in the issue.
73+
1. Rerun with effects
74+
```bash
75+
PROD=1 scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 30 <<< "added members/infinisil"
76+
```
77+
78+
## Testing `retire.sh`
4579

4680
This script has external effects and as such needs a bit more care when testing.
4781

@@ -76,7 +110,7 @@ The following sequence tests all code paths:
76110
```
77111

78112
Check that no PR would be opened.
79-
2. Run the script with the `empty` repo argument to simulate CI running with inactive users:
113+
1. Run the script with the `empty` repo argument to simulate CI running with inactive users:
80114

81115
```bash
82116
scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago' now
@@ -90,27 +124,27 @@ The following sequence tests all code paths:
90124

91125
Check that it created the PR appropriately, including assigning the "retirement" label.
92126
You can undo this step by closing the PR.
93-
3. Run it again to simulate CI running again later:
127+
1. Run it again to simulate CI running again later:
94128
```bash
95129
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago' now
96130
```
97131
Check that no other PR is opened.
98-
4. Run it again with `now` as the notice cutoff date to simulate the time interval passing:
132+
1. Run it again with `now` as the notice cutoff date to simulate the time interval passing:
99133
```bash
100134
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now now
101135
```
102136
Check that it undrafted the previous PR and posted an appropriate comment.
103-
5. Run it again to simulate CI running again later:
137+
1. Run it again to simulate CI running again later:
104138
```bash
105139
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now now
106140
```
107141
Check that no other PR is opened.
108-
6. Reset by marking the PR as a draft again, then run it again with the `active` repo argument to simulate activity during the time interval:
142+
1. Reset by marking the PR as a draft again, then run it again with the `active` repo argument to simulate activity during the time interval:
109143
```bash
110144
PROD=1 scripts/retire.sh infinisil-test-org active nixpkgs-committers members-test now now
111145
```
112146
Check that it gets undrafted with a comment listing the new activity.
113-
8. Close the PR, then run the script again with no activity and for an earlier close cutoff, simulating that the retirement was delayed:
147+
1. Close the PR, then run the script again with no activity and for an earlier close cutoff, simulating that the retirement was delayed:
114148
```bash
115149
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now '1 day ago'
116150
```

scripts/common.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set -euo pipefail
2+
3+
log() {
4+
echo "$@" >&2
5+
}
6+
7+
trace() {
8+
log "Running:" "${@@Q}"
9+
"$@"
10+
}
11+
12+
effect() {
13+
log -en "\e[33m"
14+
if [[ -z "${PROD:-}" ]]; then
15+
log "Skipping effect:" "${@@Q}"
16+
# If there's stdin, show it
17+
if read -t 0 _; then
18+
sed "s/^/[stdin] /" >&2
19+
fi
20+
else
21+
trace "$@"
22+
fi
23+
log -en "\e[0m"
24+
}

scripts/nomination.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname -- "${BASH_SOURCE[0]}")"/common.sh
4+
5+
shopt -s nocasematch
6+
7+
usage() {
8+
log "Usage: $0 MEMBERS_DIR REPOSITORY PR_NUMBER ANNOUNCEMENT_ISSUE_NUMBER"
9+
exit 1
10+
}
11+
12+
MEMBERS_DIR=${1:-$(usage)}
13+
REPOSITORY=${2:-$(usage)}
14+
PR_NUMBER=${3:-$(usage)}
15+
ANNOUNCEMENT_ISSUE_NUMBER=${4:-$(usage)}
16+
17+
log "Waiting to get changed files on stdin.."
18+
readarray -t changedFiles
19+
declare -p changedFiles
20+
21+
regex="^added $MEMBERS_DIR/([^/]+)$"
22+
23+
nomineeHandle=
24+
for statusFilename in "${changedFiles[@]}"; do
25+
if [[ "$statusFilename" =~ $regex ]]; then
26+
nomineeHandle=${BASH_REMATCH[1]}
27+
break
28+
fi
29+
done
30+
31+
if [[ -z "$nomineeHandle" ]]; then
32+
log "Not a nomination PR"
33+
exit 0
34+
elif (( "${#changedFiles[@]}" > 1 )); then
35+
log "Only one person can be nominated per PR"
36+
exit 1
37+
fi
38+
39+
effect gh api \
40+
--method PATCH \
41+
"/repos/$REPOSITORY/pulls/$PR_NUMBER" \
42+
-f title="Nominate @$nomineeHandle" \
43+
44+
effect gh api \
45+
--method POST \
46+
"/repos/$REPOSITORY/issues/$ANNOUNCEMENT_ISSUE_NUMBER/comments" \
47+
-F "body=@-" << EOF
48+
The user @$nomineeHandle has been nominated. Endorsements and discussions should be held in the corresponding nomination PR: #$PR_NUMBER
49+
EOF
50+
51+
effect gh api \
52+
--method POST \
53+
"/repos/$REPOSITORY/issues/$PR_NUMBER/labels" \
54+
-f "labels[]=nomination"

scripts/retire.sh

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
3-
shopt -s nullglob
42

5-
log() {
6-
echo "$@" >&2
7-
}
3+
source "$(dirname -- "${BASH_SOURCE[0]}")"/common.sh
84

9-
trace() {
10-
log "Running:" "${@@Q}"
11-
"$@"
12-
}
13-
14-
effect() {
15-
log -en "\e[33m"
16-
if [[ -z "${PROD:-}" ]]; then
17-
log "Skipping effect:" "${@@Q}"
18-
# If there's stdin, show it
19-
if read -t 0 _; then
20-
sed "s/^/[stdin] /" >&2
21-
fi
22-
else
23-
trace "$@"
24-
fi
25-
log -en "\e[0m"
26-
}
5+
shopt -s nullglob
276

287
usage() {
298
log "Usage: $0 ORG ACTIVITY_REPO MEMBER_REPO DIR NOTICE_CUTOFF CLOSE_CUTOFF"

scripts/sync.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
2+
3+
source "$(dirname -- "${BASH_SOURCE[0]}")"/common.sh
34

45
usage() {
5-
echo >&2 "Usage: $0 ORG TEAM DIR"
6+
log "Usage: $0 ORG TEAM DIR"
67
exit 1
78
}
89

0 commit comments

Comments
 (0)