Skip to content

Commit 9bfab31

Browse files
committed
add a change log
- updates CI triggers - adds a workflow to bump version numbers and create a GitHub release The new changelog is hosted in docs, but it is not updated until bumping version numbers (and creating a release). The intention is to keep merge conflicts minimal among simultaneous PRs.
1 parent 7732676 commit 9bfab31

15 files changed

+511
-39
lines changed

.github/stale.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/binary-builds.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ permissions:
66
on:
77
push:
88
branches: [main]
9+
paths:
10+
- cpp-linter/**
11+
- Cargo.{toml,lock}
912
tags:
10-
- v[0-9]+.*
13+
- v*
1114
pull_request:
1215
branches: [main]
16+
paths:
17+
- cpp-linter/**
18+
- Cargo.{toml,lock}
1319

1420
env:
1521
CARGO_TERM_COLOR: always
@@ -124,7 +130,7 @@ jobs:
124130
path: cpp-linter-${{ matrix.target }}*
125131
if-no-files-found: error
126132

127-
create-release:
133+
publish:
128134
if: startswith(github.ref, 'refs/tags')
129135
runs-on: ubuntu-latest
130136
needs: [create-assets]
@@ -136,6 +142,9 @@ jobs:
136142
persist-credentials: false
137143
- name: Install Rust
138144
run: rustup update stable --no-self-update
145+
- uses: actions/setup-python@v5
146+
with:
147+
python-version: 3.x
139148
- name: Download built assets
140149
uses: actions/download-artifact@v4
141150
with:
@@ -147,7 +156,7 @@ jobs:
147156
GH_TOKEN: ${{ github.token }}
148157
run: |
149158
files=$(ls dist/cpp-linter*)
150-
gh release create ${{ github.ref_name }} ${{ contains(github.ref_name, 'rc') && '--prerelease' || '' }} --generate-notes $files
159+
gh release upload ${{ github.ref_name }} $files
151160
- run: cargo publish -p cpp-linter
152161
env:
153162
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/build-docs.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
name: Docs
22

3-
on: [push, workflow_dispatch]
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- docs/**
8+
- .github/workflows/build-docs.yml
9+
- cpp-linter**.rs
10+
- '**.md'
11+
pull_request:
12+
branches: [main]
13+
paths:
14+
- docs/**
15+
- .github/workflows/build-docs.yml
16+
- cpp-linter**.rs
17+
- '**.md'
18+
workflow_dispatch:
419

520
env:
621
CARGO_TERM_COLOR: always

.github/workflows/bump-n-release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Bump-n-Release
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "main"
10+
workflow_dispatch:
11+
inputs:
12+
component:
13+
type: choice
14+
required: true
15+
default: patch
16+
options:
17+
- major
18+
- minor
19+
- patch
20+
- rc
21+
22+
jobs:
23+
bump-release:
24+
if: github.event_name == 'workflow_dispatch'
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
token: ${{ secrets.BUMP_N_RELEASE }}
30+
fetch-depth: 0
31+
- uses: actions/setup-python@v5
32+
with:
33+
python-version: 3.x
34+
- uses: cargo-bins/cargo-binstall@main
35+
- run: cargo binstall -y git-cliff
36+
- name: Bump ${{ inputs.component }} verion
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.BUMP_N_RELEASE }}
39+
GH_TOKEN: ${{ secrets.BUMP_N_RELEASE }}
40+
run: python .github/workflows/bump_version.py ${{ inputs.component }}
41+
id: tagged
42+
43+
update-changelog:
44+
if: github.event_name != 'workflow_dispatch'
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
with:
49+
token: ${{ secrets.BUMP_N_RELEASE }}
50+
fetch-depth: 0
51+
- name: Generate a changelog
52+
uses: orhun/git-cliff-action@v4
53+
id: git-cliff
54+
with:
55+
config: cliff.toml
56+
args: --unreleased
57+
env:
58+
OUTPUT: ${{ runner.temp }}/changes.md
59+
GITHUB_REPO: ${{ github.repository }}
60+
GITHUB_TOKEN: ${{ secrets.BUMP_N_RELEASE }}
61+
- run: cat ${{ runner.temp }}/changes.md >> $GITHUB_STEP_SUMMARY
62+
# NOTE: The change log is updated upon release in `bump-release` job above

.github/workflows/bump_version.py

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
"""This script automated the release process for all of the packages in this repository.
2+
In order, this script does the following:
3+
4+
1. Bump version number in manifest files according to given required arg (see `--help`).
5+
This alters the Cargo.toml in repo root and the package.json files in node-binding.
6+
7+
Requires `yarn` (see https://yarnpkg.com) and `napi` (see https://napi.rs) installed
8+
to bump node-binding versions.
9+
10+
2. Updates the CHANGELOG.md
11+
12+
Requires `git-cliff` installed (see https://git-cliff.org)
13+
to regenerate the change logs from git history.
14+
15+
NOTE: `git cliff` uses GITHUB_TOKEN env var to access GitHub's REST API for
16+
fetching certain data (like PR labels and commit author's username).
17+
18+
3. Pushes the changes from above 2 steps to remote
19+
20+
4. Creates a GitHub Release and uses the section from the CHANGELOG about the new tag
21+
as a release description.
22+
23+
Requires `gh-cli` installed (see https://cli.github.com) to create the release and
24+
push the tag.
25+
26+
NOTE: This step also tags the commit from step 3.
27+
When a tag is pushed to the remote, the CI builds are triggered and
28+
29+
- release assets are uploaded to the Github Release corresponding to the new tag
30+
- packages are published for npm, pip and cargo
31+
32+
NOTE: In a CI run, the GH_TOKEN env var to authenticate access.
33+
Locally, you can use `gh login` to interactively authenticate the user account.
34+
"""
35+
136
import argparse
237
from pathlib import Path
338
import subprocess
@@ -8,6 +43,7 @@
843
)
944
VER_REPLACE = 'version = "%d.%d.%d%s" # auto'
1045
COMPONENTS = ("major", "minor", "patch", "rc")
46+
VERSION_LOG = re.compile(rb"^## \[\d+\.\d+\.\d+(?:\-rc)?\d*\]")
1147

1248

1349
class Updater:
@@ -40,10 +76,34 @@ def replace(match: re.Match[str]) -> str:
4076
return VER_REPLACE % (tuple(ver[:3]) + (rc_str,))
4177

4278

79+
def get_release_notes(tag: str = Updater.new_version):
80+
title, buf = ("", b"")
81+
log_file = Path(__file__).parent.parent.parent / "CHANGELOG.md"
82+
tag_buf = f"[{tag}]".encode(encoding="utf-8")
83+
with open(str(log_file), "rb") as log:
84+
found_notes = False
85+
for line in log.readlines():
86+
matched = VERSION_LOG.match(line)
87+
if matched is not None:
88+
if tag_buf in matched.group(0):
89+
title = tag + line[matched.end() :].decode(encoding="utf-8")
90+
found_notes = True
91+
else:
92+
found_notes = False
93+
elif line.startswith(b"[unreleased]: ") and found_notes:
94+
found_notes = False
95+
elif found_notes:
96+
buf += line
97+
elif line.startswith(tag_buf + b": "):
98+
buf += line.replace(tag_buf, b"Full commit diff", 1)
99+
return title.rstrip(), buf.strip()
100+
101+
43102
def main():
44103
parser = argparse.ArgumentParser()
45104
parser.add_argument("component", default="patch", choices=COMPONENTS)
46105
parser.parse_args(namespace=Updater)
106+
47107
cargo_path = Path("Cargo.toml")
48108
doc = cargo_path.read_text(encoding="utf-8")
49109
doc = VER_PATTERN.sub(Updater.replace, doc)
@@ -63,20 +123,34 @@ def main():
63123
)
64124
subprocess.run(["napi", "version"], cwd="node-binding", check=True)
65125
print("Updated version in node-binding/**package.json")
66-
tag = "v" + Updater.new_version
126+
127+
subprocess.run(["git", "cliff", "--tag", Updater.new_version], check=True)
128+
print("Updated CHANGELOG.md")
129+
67130
subprocess.run(["git", "add", "--all"], check=True)
68-
subprocess.run(["git", "commit", "-m", f"bump version to {tag}"], check=True)
131+
tag = "v" + Updater.new_version
132+
subprocess.run(["git", "commit", "-m", f"Bump version to {tag}"], check=True)
69133
try:
70134
subprocess.run(["git", "push"], check=True)
71135
except subprocess.CalledProcessError as exc:
72136
raise RuntimeError("Failed to push commit for version bump") from exc
73-
print("Pushed commit to 'bump version to", tag, "'")
74-
try:
75-
subprocess.run(["git", "tag", tag], check=True)
76-
except subprocess.CalledProcessError as exc:
77-
raise RuntimeError("Failed to create tag for commit") from exc
78-
print("Created tag", tag)
79-
print(f"Use 'git push origin refs/tags/{tag}' to publish a release")
137+
138+
title, notes = get_release_notes()
139+
print("Pushed commit to 'Bump version to", tag, "'")
140+
gh_cmd = [
141+
"gh",
142+
"release",
143+
"create",
144+
tag,
145+
"--title",
146+
title,
147+
"--notes",
148+
notes.decode("utf-8"),
149+
]
150+
if Updater.component == "rc":
151+
gh_cmd.append("--prerelease")
152+
subprocess.run(gh_cmd, check=True)
153+
print("Created tag", tag, "and corresponding GitHub Release")
80154

81155

82156
if __name__ == "__main__":

.github/workflows/node-js-packaging.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@ permissions:
88
id-token: write
99
on:
1010
push:
11-
branches:
12-
- main
11+
branches: [main]
12+
paths:
13+
- cpp-linter/**.{rs,toml}
14+
- node-binding/**
15+
- Cargo.{toml,lock}
16+
- '**package.json'
17+
- yarn.lock
18+
- .github/workflows/node-js-packaging.yml
1319
tags:
1420
- '*'
15-
paths-ignore:
16-
- '**/*.md'
17-
- LICENSE
18-
- '**/*.gitignore'
19-
- .editorconfig
20-
- docs/**
2121
pull_request:
22-
branches:
23-
- main
22+
branches: [main]
23+
paths:
24+
- cpp-linter/**.{rs,toml}
25+
- node-binding/**
26+
- Cargo.{toml,lock}
27+
- '**package.json'
28+
- yarn.lock
29+
- .github/workflows/node-js-packaging.yml
30+
2431
jobs:
2532
build:
2633
strategy:
@@ -218,3 +225,9 @@ jobs:
218225
env:
219226
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
220227
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
228+
# - name: Upload release assets
229+
# env:
230+
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
231+
# run:
232+
# files=$(ls ./npm/**cpp-linter.*.node)
233+
# gh release upload ${{ github.ref_name }} $files

.github/workflows/python-packaging.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ name: Python builds
1414

1515
on:
1616
push:
17-
branches:
18-
- main
17+
branches: [main]
18+
paths:
19+
- cpp-linter/**.{rs,toml}
20+
- py-binding/**
21+
- Cargo.{toml,lock}
22+
- .github/workflows/python-packaging.yml
1923
tags:
2024
- '*'
2125
pull_request:
22-
branches:
23-
- main
24-
workflow_dispatch:
26+
branches: [main]
27+
paths:
28+
- cpp-linter/**.{rs,toml}
29+
- py-binding/**
30+
- Cargo.{toml,lock}
31+
- .github/workflows/python-packaging.yml
2532

2633
permissions:
2734
contents: read
@@ -180,3 +187,9 @@ jobs:
180187
# This workflow is registered as a trusted publisher (for test-pypi and pypi).
181188
# A token should not be required (and actually is discouraged with trusted publishers).
182189
repository-url: ${{ contains(github.ref_name, 'rc') && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
190+
# - name: Upload release assets
191+
# env:
192+
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
193+
# run:
194+
# files=$(ls ./dist/cpp-linter*.{whl,atr.gz})
195+
# gh release upload ${{ github.ref_name }} $files

.github/workflows/run-dev-tests.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- "**.rs"
8-
- "*.toml"
9-
- "Cargo.lock"
10-
- ".github/workflows/run-dev-tests.yml"
7+
- cpp-linter**.{rs,toml}
8+
- Cargo.{toml,lock}"
9+
- .github/workflows/run-dev-tests.yml
1110
pull_request:
12-
# types: opened
1311
branches: [main]
1412
paths:
15-
- "**.rs"
16-
- "*.toml"
17-
- "Cargo.lock"
18-
- ".github/workflows/run-dev-tests.yml"
13+
- cpp-linter**.{rs,toml}
14+
- Cargo.{toml,lock}"
15+
- .github/workflows/run-dev-tests.yml
1916

2017
env:
2118
CARGO_TERM_COLOR: always

.github/workflows/stale.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Close stale issues'
2+
on:
3+
schedule:
4+
- cron: '30 1 * * *'
5+
permissions:
6+
issues: write
7+
8+
jobs:
9+
stale:
10+
uses: cpp-linter/.github/.github/workflows/stale.yml@main

0 commit comments

Comments
 (0)