-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (204 loc) · 7.65 KB
/
Copy pathrelease.yml
File metadata and controls
242 lines (204 loc) · 7.65 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
name: Release
on:
push:
branches:
- master
- main
permissions:
contents: write
packages: write
jobs:
semantic-release:
name: Semantic Release
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run semantic-release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get current tags
BEFORE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
# Run semantic-release
npx semantic-release 2>&1 | tee release-output.log
# Check if a new tag was created
AFTER_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
if [ "$BEFORE_TAG" != "$AFTER_TAG" ] && [ "$AFTER_TAG" != "none" ]; then
echo "new_release_published=true" >> $GITHUB_OUTPUT
VERSION=$(echo "$AFTER_TAG" | sed 's/^v//')
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Release published: $VERSION"
else
echo "new_release_published=false" >> $GITHUB_OUTPUT
echo "ℹ️ No release published"
fi
- name: Output release info
run: |
echo "New release published: ${{ steps.semantic.outputs.new_release_published }}"
echo "New release version: ${{ steps.semantic.outputs.new_release_version }}"
build:
name: Build ${{ matrix.target }}
needs: semantic-release
if: needs.semantic-release.outputs.new_release_published == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-x86_64
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-x86_64-musl
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
artifact_name: tmpltool
asset_name: tmpltool-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
artifact_name: tmpltool
asset_name: tmpltool-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact_name: tmpltool.exe
asset_name: tmpltool-windows-x86_64.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.semantic-release.outputs.new_release_version }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (Linux ARM)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Install musl tools (Linux musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build (cross)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cross build --release --target ${{ matrix.target }}
- name: Build (cargo)
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary (Linux/macOS)
if: matrix.os != 'windows-latest'
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} || true
- name: Create archive (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
mv ${{ matrix.asset_name }}.tar.gz ../../..
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ../../../${{ matrix.asset_name }}.zip
- name: Upload artifact (Linux/macOS)
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.tar.gz
- name: Upload artifact (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.zip
upload-release-assets:
name: Upload Release Assets
needs: [semantic-release, build]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure
run: ls -R artifacts
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.semantic-release.outputs.new_release_version }}
files: artifacts/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Build and Push Docker Image
needs: [semantic-release, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.semantic-release.outputs.new_release_version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=semver,pattern={{major}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max