Skip to content

Commit d39094d

Browse files
committed
Switch to PR workflow for nominations
1 parent 2de26b1 commit d39094d

4 files changed

Lines changed: 139 additions & 3 deletions

File tree

.github/workflows/nomination.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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" "$PR_TITLE" "$ANNOUNCEMENT_ISSUE_NUMBER"
27+
env:
28+
REPOSITORY: ${{ github.repository }}
29+
PR_NUMBER: ${{ github.event.pull_request.number }}
30+
PR_TITLE: ${{ github.event.pull_request.title }}
31+
ANNOUNCEMENT_ISSUE_NUMBER: "${{
32+
github.repository_owner == 'NixOS' && 35 ||
33+
github.repository_owner == 'infinisil-test-org' && 30 ||
34+
'NO_ISSUE_NUMBER'
35+
}}"
36+
GH_TOKEN: ${{ github.token }}
37+
PROD: "1"

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ 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. Create an empty `members/<GITHUB_HANDLE>` file ([direct GitHub link](/../../new/main/members?filename=%3CGITHUB_HANDLE%3E))
14+
2. Create a PR with the change with the motivation in the PR description
15+
16+
Such nominations are also automatically announced in [this issue](https://github.com/NixOS/nixpkgs/issues/999999), which you can subscribe to for updates.
17+
18+
You can see all current nominations [here](/../../issues?q=state%3Aopen%20label%3Anomination)
1119

1220
## Semi-automatic synchronisation
1321

scripts/README.md

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

4242
Check that it synchronises the files in the `members` 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. Make sure that the nomination label is not present on the PR
51+
1. Run the script while simulating that a non-nomination PR was opened:
52+
```bash
53+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 "Removed ghost" 30 <<< "removed members/ghost"
54+
```
55+
56+
Ensure that it exits with 0 and wouldn't run any effects.
57+
1. Run the script while simulating that multiple users were nominated together:
58+
```bash
59+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 "Added foo and bar" 30 <<< "removed members/foo"$'\n'"added members/bar"
60+
```
61+
62+
Ensure that it exits with non-0 and wouldn't run any effects.
63+
1. Run the script while simulating that the nominated user is not mentioned in the title
64+
```bash
65+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 "Added somebody" 30 <<< "added members/ghost"
66+
```
67+
68+
Ensure that it exits with non-0 and wouldn't run any effects.
69+
1. Run the script simulating a successful nomination
70+
```bash
71+
scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 "Added ghost" 30 <<< "added members/ghost"
72+
```
73+
74+
Ensure that it exits with 0 and would run effects to label the PR and post a comment in the issue.
75+
1. Rerun with effects
76+
```bash
77+
PROD=1 scripts/nomination.sh members infinisil-test-org/nixpkgs-committers 33 "Added ghost" 30 <<< "added members/ghost"
78+
```
79+
80+
## Testing `retire.sh`
4581

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

scripts/nomination.sh

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

0 commit comments

Comments
 (0)