-
-
Notifications
You must be signed in to change notification settings - Fork 14
Automated scheduled releases with changelogs [WIP] #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
infinisil
wants to merge
1
commit into
main
Choose a base branch
from
changelogs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
|
|
||
|
|
||
| - [x] This change is user-facing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Changelog | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| # Includes "edited" such that we can detect changes to the description | ||
| types: [opened, synchronize, reopened, edited] | ||
|
|
||
| permissions: | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| # We need to fetch the parents of the HEAD commit (which is a merge), | ||
| # because we need to compare the PR against the base branch | ||
| # to check whether it added a changelog | ||
| fetch-depth: 2 | ||
|
|
||
| - name: check changelog | ||
| run: scripts/check-changelog.sh . ${{ github.event.pull_request.number }} | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Regular Version | ||
| on: | ||
| workflow_dispatch: # Allows triggering manually | ||
| schedule: | ||
| - cron: '47 14 * * 2' # runs every Tuesday at 14:47 UTC (chosen somewhat randomly) | ||
|
|
||
| jobs: | ||
| version: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| repository: infinixbot/nixpkgs-check-by-name | ||
| ref: release | ||
|
|
||
| - name: Create Pull Request | ||
| run: | | ||
| # no-maintainer-edit because manually added commits would get overridden | ||
| # when the release branch updates again (which is a force push). | ||
| # Instead maintainers should push any fixes to the main branch. | ||
| gh pr create \ | ||
| --repo ${{ github.repository }} \ | ||
| --title "$(git log -1 --format=%s HEAD)" \ | ||
| --no-maintainer-edit \ | ||
| --body "Automated release PR. | ||
|
|
||
| - [x] This change is user-facing | ||
| " | ||
| env: | ||
| # Needed so that CI triggers | ||
| GH_TOKEN: ${{ secrets.MACHINE_USER_PAT }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
| shopt -s nullglob | ||
|
|
||
| root=$1 | ||
| prNumber=$2 | ||
|
|
||
| # The PR template has this, selected by default | ||
| userFacingString="- [x] This change is user-facing" | ||
| nonUserFacingString="- [ ] This change is user-facing" | ||
|
|
||
| # Run this first to validate files | ||
| for file in "$root"/changes/unreleased/*/*; do | ||
| if [[ "$(basename "$file")" == ".gitkeep" ]]; then | ||
| continue | ||
| fi | ||
| if [[ $file != *.md ]]; then | ||
| echo "File $file: Must be a markdown file with file ending .md" | ||
| exit 1 | ||
| fi | ||
| if [[ "$(sed -n '/^#/=' "$file")" != "1" ]]; then | ||
| echo "File $file: The first line must start with #, while all others must not start with #" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| body=$(gh api \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| /repos/NixOS/nixpkgs-check-by-name/pulls/"$prNumber" | | ||
| jq -r '.body') | ||
|
|
||
| if grep -F -- "$userFacingString" <<< "$body" > /dev/null; then | ||
| echo "User-facing change, changelog necessary" | ||
| elif grep -F -- "$nonUserFacingString" <<< "$body" > /dev/null; then | ||
| echo "Not a user-facing change, no changelog necessary" | ||
| exit 0 | ||
| else | ||
| echo "Depending on whether this PR has a user-facing change, add one of these lines to the PR description:" | ||
| printf "%s\n" "$userFacingString" | ||
| printf "%s\n" "$nonUserFacingString" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # This checks whether the most recent commit changed any files in changes/unreleased | ||
| # This works well for PR's CI because there it runs on the merge commit, | ||
| # where HEAD^ is the first parent commit, which is the base branch. | ||
| if [[ -z "$(git -C "$root" log HEAD^..HEAD --name-only "$root"/changes/unreleased)" ]]; then | ||
| echo "If this PR contains a user-facing change, add a changelog in ./changes/unreleased" | ||
| echo "Otherwise, check the checkbox:" | ||
| printf "%s\n" "$nonUserFacingString" | ||
| exit 1 | ||
| else | ||
| echo "A changelog exists" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
| shopt -s nullglob | ||
|
|
||
| root=$1 | ||
| currentPrNumber=${2:-} | ||
|
|
||
| [[ "$(toml get --raw "$root"/Cargo.toml package.version)" =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]] | ||
| splitVersion=("${BASH_REMATCH[@]:1}") | ||
|
|
||
| majorChanges=("$root"/changes/unreleased/major/*.md) | ||
| mediumChanges=("$root"/changes/unreleased/medium/*.md) | ||
| minorChanges=("$root"/changes/unreleased/minor/*.md) | ||
|
|
||
| if ((${#majorChanges[@]} > 0)); then | ||
| # If we didn't have `|| true` this would exit the program due to `set -e`, | ||
| # because (( ... )) returns the incremental value, which is treated as the exit code.. | ||
| ((splitVersion[0]++)) || true | ||
| splitVersion[1]=0 | ||
| splitVersion[2]=0 | ||
| elif ((${#mediumChanges[@]} > 0)); then | ||
| ((splitVersion[1]++)) || true | ||
| splitVersion[2]=0 | ||
| elif ((${#minorChanges[@]} > 0)); then | ||
| ((splitVersion[2]++)) || true | ||
| else | ||
| echo >&2 "No changes" | ||
| exit 0 | ||
| fi | ||
|
|
||
| next=${splitVersion[0]}.${splitVersion[1]}.${splitVersion[2]} | ||
| releaseFile=$root/changes/released/${next}.md | ||
| mkdir -p "$(dirname "$releaseFile")" | ||
|
|
||
| echo "# Version $next ($(date --iso-8601 --utc))" > "$releaseFile" | ||
| echo "" >> "$releaseFile" | ||
|
|
||
| # shellcheck disable=SC2016 | ||
| for file in "${majorChanges[@]}" "${mediumChanges[@]}" "${minorChanges[@]}"; do | ||
| commit=$(git -C "$root" log -1 --format=%H -- "$file") | ||
| if ! gh api graphql \ | ||
| -f sha="$commit" \ | ||
| -f query=' | ||
| query ($sha: String) { | ||
| repository(owner: "NixOS", name: "nixpkgs-check-by-name") { | ||
| commit: object(expression: $sha) { | ||
| ... on Commit { | ||
| associatedPullRequests(first: 100) { | ||
| nodes { | ||
| merged | ||
| baseRefName | ||
| baseRepository { nameWithOwner } | ||
| number | ||
| author { login } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }' | | ||
| jq --exit-status -r ${currentPrNumber:+--argjson currentPrNumber "$currentPrNumber"} --arg file "$file" ' | ||
| .data.repository.commit.associatedPullRequests?.nodes?[]? | ||
| | select( | ||
| # We need to make sure to get the right PR, there can be many | ||
| (.merged or .number == $ARGS.named.currentPrNumber) and | ||
| .baseRepository.nameWithOwner == "NixOS/nixpkgs-check-by-name" and | ||
| .baseRefName == "main") | ||
| | "\(.number) \(.author.login) \($ARGS.named.file)"'; then | ||
| echo >&2 "Couldn't get PR for file $file" | ||
| exit 1 | ||
| fi | ||
| done | | ||
| sort -n | | ||
| while read -r number author file; do | ||
| # Replace the first line `# <title>` by `- <title> by @author in #number` | ||
| # All other non-empty lines are indented with 2 spaces to make the markdown formatting work | ||
| sed "$file" \ | ||
| -e "1s|#[[:space:]]\(.*\)|- \1 by [@$author](https://github.com/$author) in [#$number](https://github.com/NixOS/nixpkgs-check-by-name/pull/$number)|" \ | ||
| -e '2,$s/^\(.\)/ \1/' >> "$releaseFile" | ||
|
|
||
| rm "$file" | ||
| done | ||
|
|
||
| cargo set-version --manifest-path "$root"/Cargo.toml "$next" | ||
| echo "$next" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.