-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (191 loc) · 6.08 KB
/
release.yml
File metadata and controls
218 lines (191 loc) · 6.08 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
dry_run:
description: 'Dry run (no publish, no git push, no release)'
required: false
default: false
type: boolean
jobs:
version:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
permissions:
contents: write
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
id: current
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: bump
env:
CURRENT_VERSION: ${{ steps.current.outputs.version }}
BUMP_TYPE: ${{ inputs.bump }}
run: |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
case "$BUMP_TYPE" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
echo "version=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT
- name: Update Cargo.toml
env:
NEW_VERSION: ${{ steps.bump.outputs.version }}
run: |
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
- name: Update Cargo.lock
run: cargo update --workspace
- name: Show changes (dry run)
if: inputs.dry_run
run: |
echo "=== DRY RUN MODE ==="
echo "Would bump to version: ${{ steps.bump.outputs.version }}"
echo ""
echo "=== Cargo.toml changes ==="
git diff Cargo.toml
echo ""
echo "=== Would create tag: ${{ steps.bump.outputs.version }} ==="
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml Cargo.lock
git commit -m "Release ${{ steps.bump.outputs.version }}"
git tag "${{ steps.bump.outputs.version }}"
git push origin HEAD --tags
build:
needs: version
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: k8sql-linux-x86_64
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
name: k8sql-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
name: k8sql-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: k8sql-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: k8sql-windows-x86_64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.dry_run && github.ref || needs.version.outputs.version }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Rename binary (Unix)
if: runner.os != 'Windows'
run: mv target/${{ matrix.target }}/release/k8sql ${{ matrix.name }}
- name: Rename binary (Windows)
if: runner.os == 'Windows'
run: mv target/${{ matrix.target }}/release/k8sql.exe ${{ matrix.name }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
publish:
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.dry_run && github.ref || needs.version.outputs.version }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io (dry run)
if: inputs.dry_run
run: cargo publish --dry-run
- name: Publish to crates.io
if: ${{ !inputs.dry_run }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
release:
needs: [version, build, publish]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.version.outputs.version }}
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate SHA256 checksums
run: |
cd artifacts
for file in k8sql-*; do
sha256sum "$file" > "$file.sha256"
echo "Generated checksum for $file:"
cat "$file.sha256"
done
cd ..
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.version }}
generate_release_notes: true
files: artifacts/*
dry-run-summary:
needs: [version, build, publish]
if: inputs.dry_run
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate SHA256 checksums
run: |
cd artifacts
for file in k8sql-*; do
sha256sum "$file" > "$file.sha256"
done
cd ..
- name: Summary
run: |
echo "=== DRY RUN COMPLETE ==="
echo ""
echo "Version: ${{ needs.version.outputs.version }}"
echo ""
echo "Built artifacts:"
ls -la artifacts/
echo ""
echo "Checksums:"
cat artifacts/*.sha256
echo ""
echo "To perform a real release, run without dry_run checked."