Skip to content

Commit 9d9b3fc

Browse files
committed
Add release-plz automation for changelog and version management
- Add release-plz.yml workflow that creates release PRs with version bumps and changelog updates from conventional commits - Add release-binaries.yml workflow triggered on release publish to build and upload macOS/Linux binaries and DotSlash files - Update ci.yml to remove manual release logic (now handled by release-plz) and upgrade checkout actions to v4 - Add release-plz.toml config for changelog generation without crates.io publishing
1 parent 26b6753 commit 9d9b3fc

4 files changed

Lines changed: 118 additions & 118 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- name: Checkout sources
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
2727

2828
- name: Run cargo check
2929
run: cargo check
@@ -32,7 +32,7 @@ jobs:
3232
runs-on: ubuntu-latest
3333
steps:
3434
- name: Checkout sources
35-
uses: actions/checkout@v2
35+
uses: actions/checkout@v4
3636

3737
- name: Run cargo test with backtrace
3838
run: cargo test -- --nocapture
@@ -45,125 +45,10 @@ jobs:
4545
RUSTFLAGS: "-Dwarnings"
4646
steps:
4747
- name: Checkout sources
48-
uses: actions/checkout@v2
48+
uses: actions/checkout@v4
4949

5050
- name: Run cargo fmt
5151
run: cargo fmt --all -- --check
5252

5353
- name: Run cargo clippy
5454
run: cargo clippy --all-targets --all-features
55-
56-
release:
57-
runs-on: macos-latest
58-
needs:
59-
- test
60-
- lints
61-
- check
62-
outputs:
63-
new_version: ${{ steps.check_for_version_changes.outputs.new_version }}
64-
changed: ${{ steps.check_for_version_changes.outputs.changed }}
65-
if: github.ref == 'refs/heads/main'
66-
steps:
67-
- uses: actions/checkout@v3
68-
with:
69-
# https://stackoverflow.com/questions/65944700/how-to-run-git-diff-in-github-actions
70-
# TLDR – By default this action fetches no history.
71-
# We need a bit of history to be able to check if we've recently updated the version in Cargo.toml
72-
fetch-depth: 2
73-
- name: Toolchain info
74-
run: |
75-
cargo --version --verbose
76-
rustc --version
77-
cargo clippy --version
78-
- name: Build
79-
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
80-
- name: Check for version changes in Cargo.toml
81-
id: check_for_version_changes
82-
run: |
83-
# When there are no changes, VERSION_CHANGES will be empty
84-
# Without the echo, this command would exit with a 1, causing the GitHub Action to fail
85-
# Instead, we want it to succeed, but just evaluate `changed=false` in the other branch of the conditional
86-
VERSION_CHANGES=$(git diff HEAD~1 HEAD Cargo.toml | grep "\+version" || echo "")
87-
if [[ -n $VERSION_CHANGES ]]; then
88-
NEW_VERSION=$(echo $VERSION_CHANGES | awk -F'"' '{print $2}')
89-
echo "changed=true" >> $GITHUB_OUTPUT
90-
echo "new_version=v$NEW_VERSION" >> $GITHUB_OUTPUT
91-
else
92-
echo "changed=false" >> $GITHUB_OUTPUT
93-
fi
94-
95-
- name: Create GitHub Release if current commit has updated the version in Cargo.toml
96-
if: steps.check_for_version_changes.outputs.changed == 'true'
97-
run: |
98-
gh release create ${{steps.check_for_version_changes.outputs.new_version}} --target "${{ github.sha }}" --generate-notes
99-
env:
100-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101-
upload-mac-universal-bin:
102-
needs: release
103-
runs-on: macos-latest
104-
if: ${{needs.release.outputs.new_version}}
105-
steps:
106-
- uses: actions/checkout@v3
107-
- name: Build
108-
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
109-
110-
- name: Upload mac universal binary
111-
run: |
112-
# This combines the intel and m1 binaries into a single binary
113-
lipo -create -output target/pks target/aarch64-apple-darwin/release/pks target/x86_64-apple-darwin/release/pks
114-
115-
# Creates artifact for homebrew. -C means run from `target` directory
116-
tar -czf target/pks-mac.tar.gz -C target pks
117-
118-
# This tarball is a binary that is executable
119-
gh release upload $NEW_VERSION target/pks-mac.tar.gz
120-
121-
env:
122-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123-
NEW_VERSION: ${{ needs.release.outputs.new_version }}
124-
125-
upload-linux-bin:
126-
needs: release
127-
if: ${{needs.release.outputs.new_version}}
128-
runs-on: ubuntu-latest
129-
steps:
130-
- uses: actions/checkout@v4
131-
- name: Update local toolchain
132-
run: |
133-
cargo install cross
134-
- name: Build linux binaries
135-
run: |
136-
cross build --release --target x86_64-unknown-linux-gnu
137-
cross build --release --target aarch64-unknown-linux-gnu
138-
- name: Upload linux binaries
139-
run: |
140-
tar -czf target/x86_64-unknown-linux-gnu.tar.gz -C target/x86_64-unknown-linux-gnu/release pks
141-
tar -czf target/aarch64-unknown-linux-gnu.tar.gz -C target/aarch64-unknown-linux-gnu/release pks
142-
gh release upload $NEW_VERSION target/x86_64-unknown-linux-gnu.tar.gz
143-
gh release upload $NEW_VERSION target/aarch64-unknown-linux-gnu.tar.gz
144-
env:
145-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146-
NEW_VERSION: ${{ needs.release.outputs.new_version }}
147-
148-
generate-dotslash-files:
149-
name: Generating and uploading DotSlash files
150-
needs:
151-
- release
152-
- upload-linux-bin
153-
- upload-mac-universal-bin
154-
if: success() && ${{needs.release.outputs.new_version}}
155-
runs-on: ubuntu-latest
156-
157-
steps:
158-
- uses: facebook/dotslash-publish-release@v1
159-
# This is necessary because the action uses
160-
# `gh release upload` to publish the generated DotSlash file(s)
161-
# as part of the release.
162-
env:
163-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164-
with:
165-
# Additional file that lives in your repo that defines
166-
# how your DotSlash file(s) should be generated.
167-
config: .github/workflows/dotslash-config.json
168-
# Tag for the release to target.
169-
tag: ${{ needs.release.outputs.new_version }}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Release Binaries
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
upload-mac-universal-bin:
12+
runs-on: macos-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Build macOS binaries
17+
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
18+
19+
- name: Create universal binary and upload
20+
run: |
21+
# Combine intel and m1 binaries into a single universal binary
22+
lipo -create -output target/pks target/aarch64-apple-darwin/release/pks target/x86_64-apple-darwin/release/pks
23+
24+
# Create tarball for homebrew
25+
tar -czf target/pks-mac.tar.gz -C target pks
26+
27+
# Upload to release
28+
gh release upload ${{ github.event.release.tag_name }} target/pks-mac.tar.gz
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
upload-linux-bin:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Install cross
38+
run: cargo install cross
39+
40+
- name: Build linux binaries
41+
run: |
42+
cross build --release --target x86_64-unknown-linux-gnu
43+
cross build --release --target aarch64-unknown-linux-gnu
44+
45+
- name: Upload linux binaries
46+
run: |
47+
tar -czf target/x86_64-unknown-linux-gnu.tar.gz -C target/x86_64-unknown-linux-gnu/release pks
48+
tar -czf target/aarch64-unknown-linux-gnu.tar.gz -C target/aarch64-unknown-linux-gnu/release pks
49+
gh release upload ${{ github.event.release.tag_name }} target/x86_64-unknown-linux-gnu.tar.gz
50+
gh release upload ${{ github.event.release.tag_name }} target/aarch64-unknown-linux-gnu.tar.gz
51+
env:
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
54+
generate-dotslash-files:
55+
name: Generate DotSlash files
56+
needs:
57+
- upload-linux-bin
58+
- upload-mac-universal-bin
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- uses: facebook/dotslash-publish-release@v1
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
with:
67+
config: .github/workflows/dotslash-config.json
68+
tag: ${{ github.event.release.tag_name }}

.github/workflows/release-plz.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release-plz
2+
3+
permissions:
4+
pull-requests: write
5+
contents: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
release-plz:
14+
name: Release-plz
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Install Rust toolchain
23+
uses: dtolnay/rust-toolchain@stable
24+
25+
- name: Run release-plz
26+
uses: release-plz/action@v0.5
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release-plz.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[workspace]
2+
# Don't publish to crates.io - binaries are distributed via GitHub releases
3+
publish = false
4+
# Create GitHub releases when release PR is merged
5+
git_release_enable = true
6+
# Generate changelog from conventional commits
7+
changelog_update = true
8+
9+
[changelog]
10+
# Use conventional commits to generate changelog
11+
commit_parsers = [
12+
{ message = "^feat", group = "Features" },
13+
{ message = "^fix", group = "Bug Fixes" },
14+
{ message = "^docs", group = "Documentation" },
15+
{ message = "^perf", group = "Performance" },
16+
{ message = "^refactor", group = "Refactoring" },
17+
{ message = "^test", group = "Testing" },
18+
{ message = "^chore", group = "Miscellaneous" },
19+
]

0 commit comments

Comments
 (0)