-
Notifications
You must be signed in to change notification settings - Fork 27
329 lines (285 loc) · 13.2 KB
/
release.yml
File metadata and controls
329 lines (285 loc) · 13.2 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Manual Release
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.version.outputs.new_version }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
tag_sha: ${{ steps.tag_sha.outputs.tag_sha }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
# Install cargo-edit for version bumping
- name: Install cargo-edit
run: cargo install cargo-edit
# Bump version in Cargo.toml
- name: Bump version
id: version
run: |
cargo set-version --bump ${{ github.event.inputs.version_type }}
NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
echo "new_version=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: v$NEW_VERSION"
# Run tests before release
- name: Run tests
run: cargo test
# Install Nix for flake.nix updates
- name: Install Nix
uses: cachix/install-nix-action@v27
# Update flake.nix with new version and hashes
- name: Update flake.nix
run: |
NEW_VERSION=$(echo "${{ steps.version.outputs.new_version }}" | sed 's/^v//')
# Update version in flake.nix
sed -i "s/version = \"[0-9.]\+\"/version = \"$NEW_VERSION\"/" flake.nix
# Calculate hash for source
nix flake prefetch --json github:unhappychoice/gittype/${{ steps.version.outputs.new_version }} > /tmp/prefetch.json || true
# Note: Hashes will be calculated after tag is pushed, so we'll use a placeholder for now
# The actual hash update will happen in a separate job after the tag is created
echo "Version updated in flake.nix to $NEW_VERSION"
# Create temporary tag for changelog generation
- name: Create temporary tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Cargo.toml Cargo.lock flake.nix
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}"
git tag ${{ steps.version.outputs.new_version }}
# Generate CHANGELOG.md (now with the new tag available)
- name: Generate Changelog
run: |
chmod +x generate_changelog.sh
./generate_changelog.sh
# Commit changelog and push everything
- name: Commit changelog and push
run: |
git add CHANGELOG.md
git commit --amend --no-edit
git tag -f ${{ steps.version.outputs.new_version }}
git push origin main
git push origin ${{ steps.version.outputs.new_version }}
# Resolve the exact commit SHA for the newly created tag (used by Homebrew)
- name: Resolve tag commit SHA
id: tag_sha
run: |
TAG_SHA=$(git rev-list -n 1 ${{ steps.version.outputs.new_version }})
echo "tag_sha=$TAG_SHA" >> $GITHUB_OUTPUT
echo "Tag commit SHA: $TAG_SHA"
# Extract release notes from CHANGELOG.md
- name: Extract Release Notes
id: extract_notes
run: |
VERSION=$(echo "${{ steps.version.outputs.new_version }}" | sed 's/^v//')
# Extract the section for the current version from CHANGELOG.md
awk "/## \[$VERSION\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md > release_notes.md
if [ ! -s release_notes.md ]; then
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
echo "See the full changelog for details." >> release_notes.md
fi
# Store the release notes for use in the next step
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
cat release_notes.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Create GitHub Release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.new_version }}
release_name: Release ${{ steps.version.outputs.new_version }}
body: ${{ steps.extract_notes.outputs.RELEASE_NOTES }}
draft: false
prerelease: false
build-and-upload:
name: Build and Upload
needs: release
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.new_version }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build
run: cargo build --release --target ${{ matrix.target }}
env:
OPENSSL_VENDORED: 1
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
AR_aarch64_unknown_linux_gnu: aarch64-linux-gnu-ar
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Create archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar -czf ../../../gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz gittype
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path gittype.exe -DestinationPath ../../../gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
- name: Upload Release Asset (Unix)
if: matrix.os != 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz
asset_name: gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.tar.gz
asset_content_type: application/gzip
- name: Upload Release Asset (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
asset_name: gittype-${{ needs.release.outputs.new_version }}-${{ matrix.target }}.zip
asset_content_type: application/zip
publish-crates:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [release, build-and-upload]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.new_version }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
update-flake-hashes:
name: Update flake.nix Hashes
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: cachix/install-nix-action@v27
- name: Calculate and update hashes
run: |
VERSION=${{ needs.release.outputs.new_version }}
# Ensure we have the latest main
git pull origin main
# Calculate source hash
SRC_HASH=$(nix flake prefetch --json github:unhappychoice/gittype/$VERSION 2>/dev/null | jq -r .hash)
echo "Source hash: $SRC_HASH"
# Update source hash in flake.nix
sed -i "s|hash = \"sha256-[A-Za-z0-9+/=]\+\"|hash = \"$SRC_HASH\"|" flake.nix
# Try to build to get cargoHash (it will fail but show the correct hash)
nix build .#default 2>&1 | tee /tmp/build.log || true
CARGO_HASH=$(grep -oP "got:\s+\Ksha256-[A-Za-z0-9+/=]+" /tmp/build.log | head -1 || echo "")
if [ -n "$CARGO_HASH" ]; then
echo "Cargo hash: $CARGO_HASH"
sed -i "s|cargoHash = \"sha256-[A-Za-z0-9+/=]\+\"|cargoHash = \"$CARGO_HASH\"|" flake.nix
else
echo "Warning: Could not determine cargo hash"
fi
# Commit and push the updated flake.nix
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add flake.nix
git commit -m "chore: update flake.nix hashes for $VERSION" || echo "No changes to commit"
git push origin main
update-homebrew:
name: Update Homebrew Formula
runs-on: ubuntu-latest
needs: [release, build-and-upload]
steps:
- name: Checkout homebrew tap
uses: actions/checkout@v4
with:
repository: unhappychoice/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Update Homebrew formula
run: |
VERSION=${{ needs.release.outputs.new_version }}
# Calculate SHA256 for each binary release
MACOS_INTEL_URL="https://github.com/unhappychoice/gittype/releases/download/$VERSION/gittype-$VERSION-x86_64-apple-darwin.tar.gz"
MACOS_INTEL_SHA=$(curl -sL "$MACOS_INTEL_URL" | sha256sum | cut -d' ' -f1)
MACOS_ARM_URL="https://github.com/unhappychoice/gittype/releases/download/$VERSION/gittype-$VERSION-aarch64-apple-darwin.tar.gz"
MACOS_ARM_SHA=$(curl -sL "$MACOS_ARM_URL" | sha256sum | cut -d' ' -f1)
LINUX_INTEL_URL="https://github.com/unhappychoice/gittype/releases/download/$VERSION/gittype-$VERSION-x86_64-unknown-linux-gnu.tar.gz"
LINUX_INTEL_SHA=$(curl -sL "$LINUX_INTEL_URL" | sha256sum | cut -d' ' -f1)
LINUX_ARM_URL="https://github.com/unhappychoice/gittype/releases/download/$VERSION/gittype-$VERSION-aarch64-unknown-linux-gnu.tar.gz"
LINUX_ARM_SHA=$(curl -sL "$LINUX_ARM_URL" | sha256sum | cut -d' ' -f1)
echo "Calculated SHAs:"
echo "macOS Intel: $MACOS_INTEL_SHA"
echo "macOS ARM: $MACOS_ARM_SHA"
echo "Linux Intel: $LINUX_INTEL_SHA"
echo "Linux ARM: $LINUX_ARM_SHA"
cd homebrew-tap
# Use sed to update each architecture's URL and SHA
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-x86_64-apple-darwin.tar.gz|$MACOS_INTEL_URL|g" Formula/gittype.rb
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-aarch64-apple-darwin.tar.gz|$MACOS_ARM_URL|g" Formula/gittype.rb
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-x86_64-unknown-linux-gnu.tar.gz|$LINUX_INTEL_URL|g" Formula/gittype.rb
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-aarch64-unknown-linux-gnu.tar.gz|$LINUX_ARM_URL|g" Formula/gittype.rb
# Update SHA values in the same order they appear in the file
# macOS Intel
FIRST_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -1 | cut -d: -f1)
sed -i "${FIRST_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$MACOS_INTEL_SHA\"/" Formula/gittype.rb
# macOS ARM
SECOND_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -2 | tail -1 | cut -d: -f1)
sed -i "${SECOND_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$MACOS_ARM_SHA\"/" Formula/gittype.rb
# Linux Intel
THIRD_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -3 | tail -1 | cut -d: -f1)
sed -i "${THIRD_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$LINUX_INTEL_SHA\"/" Formula/gittype.rb
# Linux ARM
FOURTH_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -4 | tail -1 | cut -d: -f1)
sed -i "${FOURTH_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$LINUX_ARM_SHA\"/" Formula/gittype.rb
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Formula/gittype.rb
git commit -m "chore: update gittype to $VERSION"
git push