Repository navigation
228 lines (197 loc) · 7.46 KB
/
Copy pathrelease.yml
File metadata and controls
228 lines (197 loc) · 7.46 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
name: Release
on:
push:
tags:
- 'v*'
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: true
type: string
# Restrict default permissions (OpenSSF Scorecard requirement)
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
BINARY_NAME: lonkero
jobs:
version-bump:
name: Bump Version
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@b9e0990d219a03df7633c93f6f005a8fecbcab22 # v4.3.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version in Cargo.toml
id: bump
run: |
VERSION="${{ inputs.version }}"
# Remove 'v' or 'V' prefix if present
VERSION="${VERSION#v}"
VERSION="${VERSION#V}"
echo "version=v${VERSION}" >> $GITHUB_OUTPUT
# Update Cargo.toml
sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
# Show the change
grep '^version = ' Cargo.toml
- name: Commit and tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml
git commit -m "chore: bump version to ${{ steps.bump.outputs.version }}" || echo "No changes to commit"
# Delete existing tag if present (re-release scenario)
git tag -d ${{ steps.bump.outputs.version }} 2>/dev/null || true
git push origin :refs/tags/${{ steps.bump.outputs.version }} 2>/dev/null || true
# Create and push new tag
git tag ${{ steps.bump.outputs.version }}
git push origin HEAD:${{ github.ref_name }}
git push origin ${{ steps.bump.outputs.version }}
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: [version-bump]
# Run on tag push, or after version-bump completes
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && needs.version-bump.result == 'success')
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact: lonkero-linux-x64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
artifact: lonkero-linux-arm64
cross: true
- target: x86_64-apple-darwin
os: macos-15-intel
artifact: lonkero-macos-x64
- target: aarch64-apple-darwin
os: macos-latest
artifact: lonkero-macos-arm64
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact: lonkero-windows-x64
steps:
- name: Checkout repository
uses: actions/checkout@b9e0990d219a03df7633c93f6f005a8fecbcab22 # v4.3.1
with:
ref: ${{ needs.version-bump.outputs.version || github.ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable
with:
targets: ${{ matrix.target }}
- name: Install system dependencies (Linux)
if: runner.os == 'Linux' && matrix.cross != true
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev libpq-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: brew install openssl@3 postgresql
- name: Install cross (for ARM builds)
if: matrix.cross == true
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build release binary
if: matrix.cross != true
run: cargo build --release --bin lonkero --target ${{ matrix.target }}
- name: Build release binary (cross)
if: matrix.cross == true
run: cross build --release --bin lonkero --target ${{ matrix.target }}
- name: Prepare artifact (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/lonkero dist/
cd dist && tar -czf ../${{ matrix.artifact }}.tar.gz lonkero
- name: Prepare artifact (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist
Copy-Item target/${{ matrix.target }}/release/lonkero.exe dist/
Compress-Archive -Path dist/lonkero.exe -DestinationPath ${{ matrix.artifact }}.zip
- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ matrix.artifact }}
path: |
${{ matrix.artifact }}.tar.gz
${{ matrix.artifact }}.zip
if-no-files-found: ignore
release:
name: Create Release
needs: [version-bump, build]
runs-on: ubuntu-latest
if: always() && needs.build.result == 'success'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@b9e0990d219a03df7633c93f6f005a8fecbcab22 # v4.3.1
with:
ref: ${{ needs.version-bump.outputs.version || github.ref }}
- name: Download all artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release-assets
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} release-assets/ \;
ls -la release-assets/
- name: Generate checksums
run: |
cd release-assets
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ needs.version-bump.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1
with:
tag_name: ${{ steps.version.outputs.version }}
name: Lonkero ${{ steps.version.outputs.version }}
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
generate_release_notes: true
files: |
release-assets/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
needs: [version-bump, release]
runs-on: ubuntu-latest
if: always() && needs.release.result == 'success'
steps:
- name: Checkout repository
uses: actions/checkout@b9e0990d219a03df7633c93f6f005a8fecbcab22 # v4.3.1
with:
ref: ${{ needs.version-bump.outputs.version || github.ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev libpq-dev
- name: Publish to crates.io
run: cargo publish --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}