-
Notifications
You must be signed in to change notification settings - Fork 6
232 lines (228 loc) · 9.17 KB
/
release.yml
File metadata and controls
232 lines (228 loc) · 9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Release
on:
workflow_dispatch:
push:
branches:
- main
env:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN: 1.93
jobs:
spelling:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Spell Check Repo
uses: crate-ci/typos@v1.42.3
check-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup sccache
uses: ./.github/actions/setup-sccache
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
default: true
components: rustfmt
- name: Check formatting
run: cargo fmt --check
test-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup sccache
uses: ./.github/actions/setup-sccache
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
default: true
- name: Run rust tests
run: cargo test --locked -- --test-threads=1
create-release:
needs:
- spelling
- check-formatting
- test-rust
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # required for git write-tree and GitHub API commit operations
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup sccache
uses: ./.github/actions/setup-sccache
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
default: true
- name: Cache cargo-edit
id: cache-cargo-edit
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-set-version
key: cargo-edit-${{ runner.os }}-${{ env.RUST_TOOLCHAIN }}
- name: Install cargo-edit for version bumping
if: steps.cache-cargo-edit.outputs.cache-hit != 'true'
run: cargo install cargo-edit
- name: Bump version patch
run: |
# Bump version in all workspace crates
cargo set-version --workspace --bump patch
- name: Extract new version from Cargo.toml
id: extract_version
run: |
version=$(cargo metadata --no-deps --format-version 1 --manifest-path crates/cli/Cargo.toml | jq -r '.packages[0].version')
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Commit and push version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit - version might already be bumped"
else
git commit -m "chore: release v${{ steps.extract_version.outputs.version }}"
git push origin main
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo publish --manifest-path crates/foundation/Cargo.toml
cargo publish --manifest-path crates/core-invoice/Cargo.toml
cargo publish --manifest-path crates/render-typst/Cargo.toml
cargo publish --manifest-path crates/cli/Cargo.toml
- name: Create GitHub Release with verified tag
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.extract_version.outputs.version }}
name: klirr v${{ steps.extract_version.outputs.version }}
body_path: CHANGELOG.md
generate_release_notes: true
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload:
needs: create-release
permissions:
contents: write
id-token: write # Required for attestations
attestations: write # Required for attestations
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
asset_name: klirr-x86_64-unknown-linux-gnu
- target: aarch64-apple-darwin
os: macos-latest
asset_name: klirr-aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install system dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Setup sccache
uses: ./.github/actions/setup-sccache
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
default: true
target: ${{ matrix.target }}
- name: Build for ${{ matrix.target }} (Linux)
if: matrix.os == 'ubuntu-latest'
run: cargo build --release --target ${{ matrix.target }}
- name: Build for ${{ matrix.target }} (macOS)
if: matrix.os == 'macos-latest'
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare binary for upload
run: |
mkdir -p upload
cp target/${{ matrix.target }}/release/klirr upload/${{ matrix.asset_name }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: upload/${{ matrix.asset_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload binary for ${{ matrix.target }}
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.create-release.outputs.version }}
files: upload/${{ matrix.asset_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew:
needs:
- create-release
- build-and-upload
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries for checksums
run: |
curl -L -o klirr-x86_64-unknown-linux-gnu "https://github.com/Sajjon/klirr/releases/download/v${{ needs.create-release.outputs.version }}/klirr-x86_64-unknown-linux-gnu"
curl -L -o klirr-aarch64-apple-darwin "https://github.com/Sajjon/klirr/releases/download/v${{ needs.create-release.outputs.version }}/klirr-aarch64-apple-darwin"
- name: Generate SHA256 checksums
id: sha256
run: |
echo "sha_linux=$(shasum -a 256 klirr-x86_64-unknown-linux-gnu | awk '{ print $1 }')" >> $GITHUB_OUTPUT
echo "sha_macos=$(shasum -a 256 klirr-aarch64-apple-darwin | awk '{ print $1 }')" >> $GITHUB_OUTPUT
- name: Update Homebrew Formula
run: |
# Clone the tap repository
git clone https://x-access-token:${{ secrets.HOMEBREW_TAP_PUSH_TOKEN }}@github.com/Sajjon/homebrew-klirr.git
cd homebrew-klirr
# Set variables for cleaner code
FORMULA_FILE="Formula/klirr.rb"
VERSION="${{ needs.create-release.outputs.version }}"
SHA_LINUX="${{ steps.sha256.outputs.sha_linux }}"
SHA_MACOS="${{ steps.sha256.outputs.sha_macos }}"
# Create Formula directory if it doesn't exist
mkdir -p Formula
# Generate the formula content using printf for better control
printf 'class Klirr < Formula\n' > "$FORMULA_FILE"
printf ' desc "Generate invoice with auto invoice number setting & working days calc"\n' >> "$FORMULA_FILE"
printf ' homepage "https://github.com/Sajjon/klirr"\n' >> "$FORMULA_FILE"
printf ' url "https://github.com/Sajjon/klirr/releases/download/v%s/klirr-aarch64-apple-darwin"\n' "$VERSION" >> "$FORMULA_FILE"
printf ' sha256 "%s"\n\n' "$SHA_MACOS" >> "$FORMULA_FILE"
printf ' def install\n' >> "$FORMULA_FILE"
printf ' if OS.mac?\n' >> "$FORMULA_FILE"
printf ' bin.install "klirr-aarch64-apple-darwin" => "klirr"\n' >> "$FORMULA_FILE"
printf ' elsif OS.linux?\n' >> "$FORMULA_FILE"
printf ' url "https://github.com/Sajjon/klirr/releases/download/v%s/klirr-x86_64-unknown-linux-gnu"\n' "$VERSION" >> "$FORMULA_FILE"
printf ' sha256 "%s"\n' "$SHA_LINUX" >> "$FORMULA_FILE"
printf ' bin.install "klirr-x86_64-unknown-linux-gnu" => "klirr"\n' >> "$FORMULA_FILE"
printf ' end\n' >> "$FORMULA_FILE"
printf ' end\n\n' >> "$FORMULA_FILE"
printf ' test do\n' >> "$FORMULA_FILE"
printf ' system bin/"klirr", "--help"\n' >> "$FORMULA_FILE"
printf ' end\n' >> "$FORMULA_FILE"
printf 'end\n' >> "$FORMULA_FILE"
# Commit and push the changes
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$FORMULA_FILE"
git commit -m "klirr: update to $VERSION"
git push