close
Skip to content

Commit 6cd6d70

Browse files
authored
feat: refine changelog creation for releases (#51) (#52)
This change refines the way changelogs are calculated. The resulting behavior is such that a release includes the commits that were made on main since the previous release was minted and any commits made on the specific release branch (such as targeted fixes or backports). Prerelease is a running log of changes made to main since the most recent release was minted.
1 parent 0c4c4b4 commit 6cd6d70

8 files changed

Lines changed: 210 additions & 101 deletions
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
# This script identifies the commits that have been made to the current
3+
# branch since the release before this branch. It formats them according
4+
# to a format specifier.
5+
#
6+
# Usage:
7+
# compile-changelog outfile
8+
#
9+
# outfile: the file location to write the changelog to
10+
11+
module Git
12+
def self.one_line_format(repository_url)
13+
"[<code>%h</code>](#{repository_url}/commit/%h) %s (%an)"
14+
end
15+
16+
def self.current_branch
17+
`git rev-parse --abbrev-ref HEAD`.strip
18+
end
19+
20+
def self.default_branch
21+
`git rev-parse --abbrev-ref origin/HEAD`.strip
22+
end
23+
24+
def self.default_branch_head
25+
`git rev-parse origin/HEAD`.strip
26+
end
27+
28+
def self.initial_commit
29+
`git rev-list --max-parents=0 #{default_branch}`.strip
30+
end
31+
32+
def self.release_branches
33+
`git branch --list -r origin/release/*`.split("\n").map(&:strip)
34+
end
35+
36+
def self.commit_date(commit)
37+
`git show -s --format=%ct #{commit}`.strip
38+
end
39+
40+
def self.merge_base_from(branch1, branch2)
41+
`git merge-base #{branch1} #{branch2}`.strip
42+
end
43+
44+
# Returns the commit where the given branch forked from the default git branch.
45+
# If the given branch is the default git branch, the branch commit is the initial
46+
# commit in the repo.
47+
def self.merge_base(branch)
48+
if branch == Git::default_branch_head
49+
Git::initial_commit()
50+
else
51+
Git::merge_base_from(Git::default_branch, branch)
52+
end
53+
end
54+
55+
def self.formatted_commits_between(low, high, format)
56+
`git log --pretty="format:#{format}" --no-merges #{low}..#{high}`
57+
end
58+
end
59+
60+
outfile = ARGV[0]
61+
repository_url = "https://github.com/#{ENV['GITHUB_REPOSITORY']}"
62+
commit_upper_bound = Git::current_branch
63+
commit_lower_bound = Git::release_branches
64+
.map { |branch| Git::merge_base(branch) }
65+
.reject { |commit| Git::commit_date(commit) >= Git::commit_date(commit_upper_bound) }
66+
.sort_by { |commit| Git::commit_date(commit) }
67+
.reverse
68+
.first
69+
70+
changelog = Git::formatted_commits_between(
71+
commit_lower_bound || Git::initial_commit,
72+
commit_upper_bound,
73+
Git::one_line_format(repository_url))
74+
75+
File.open(outfile, 'a') do |file|
76+
file.puts changelog
77+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Creates or updates a 'prerelease' release whenever main is
2+
# changed. Attaches a built PDF to that release.
3+
name: On Main Branch Change
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build_draft_pdf:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Git repository
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set origin HEAD
19+
run: git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
20+
21+
- name: Compile document
22+
uses: xu-cheng/latex-action@v2
23+
with:
24+
root_file: ifc.tex
25+
working_directory: ltx
26+
27+
- name: Compile changelog
28+
run: |
29+
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
30+
ruby ./.github/workflows/compile-changelog.rb $GITHUB_ENV
31+
echo 'EOF' >> $GITHUB_ENV
32+
33+
- name: Create prerelease
34+
uses: ncipollo/release-action@v1
35+
with:
36+
token: "${{ secrets.GITHUB_TOKEN }}"
37+
allowUpdates: true
38+
name: Prerelease
39+
prerelease: true
40+
tag: prerelease
41+
body: |
42+
This release is a prerelease. The contents of this release are likely to change.
43+
# Changelog
44+
${{ env.CHANGELOG }}
45+
artifacts: |
46+
ltx/ifc.pdf
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Creates or updates a release's generated PDF when a change occurs
2+
# to a release branch
3+
name: On Release Branch Change
4+
on:
5+
push:
6+
branches:
7+
- "release/*"
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Git repository
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Set origin HEAD
19+
run: git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
20+
21+
- name: Extract branch name
22+
shell: bash
23+
run: echo "RELEASE_NAME=$(echo ${GITHUB_REF#refs/heads/release/})" >> $GITHUB_ENV
24+
25+
- name: Compile document
26+
uses: xu-cheng/latex-action@v2
27+
with:
28+
root_file: ifc.tex
29+
working_directory: ltx
30+
31+
- name: Compile changelog
32+
run: |
33+
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
34+
ruby ./.github/workflows/compile-changelog.rb $GITHUB_ENV
35+
echo 'EOF' >> $GITHUB_ENV
36+
37+
- name: Update release
38+
uses: ncipollo/release-action@v1
39+
with:
40+
token: "${{ secrets.GITHUB_TOKEN }}"
41+
allowUpdates: true
42+
name: ${{ env.RELEASE_NAME }}
43+
prerelease: false
44+
tag: ${{ env.RELEASE_NAME }}
45+
body: |
46+
# Changelog
47+
${{ env.CHANGELOG }}
48+
artifacts: |
49+
ltx/ifc.pdf
50+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Creates a release branch whenever a release is created.
2+
3+
name: On Release Created
4+
on:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
create_branch:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: peterjgrainger/action-create-branch@v2.0.1
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
with:
17+
branch: 'release/${{ github.event.release.tag_name }}'
18+
19+
build_latex:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Set up Git repository
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Compile document
28+
uses: xu-cheng/latex-action@v2
29+
with:
30+
root_file: ifc.tex
31+
working_directory: ltx
32+
33+
- name: Add PDF to Release
34+
uses: softprops/action-gh-release@v0.1.13
35+
if: startsWith(github.ref, 'refs/tags/')
36+
with:
37+
files: ltx/ifc.pdf

‎.github/workflows/produce-branch-pdf.yml‎

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

‎.github/workflows/produce-prerelease.yaml‎

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

‎.github/workflows/produce-release-branch.yml‎

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

‎.github/workflows/produce-release-pdf.yml‎

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

0 commit comments

Comments
 (0)