-
Notifications
You must be signed in to change notification settings - Fork 0
246 lines (214 loc) · 7.5 KB
/
build_release.yml
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
name: Build and Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
determine_release:
name: Determine if release is needed
runs-on: ubuntu-latest
outputs:
SHOULD_RELEASE: ${{ steps.release_check.outputs.SHOULD_RELEASE }}
NEW_TAG: ${{ steps.release_check.outputs.NEW_TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine if release is needed
id: release_check
shell: bash
run: |
git fetch --tags
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -n1 | awk -F\" '{print $2}')
echo "Current version: $CURRENT_VERSION"
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag v$CURRENT_VERSION already exists. No release needed."
echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "No existing tag for version $CURRENT_VERSION. Release is needed."
echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT
echo "NEW_TAG=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi
test_coverage:
name: Lint and test
runs-on: ubuntu-latest
needs: determine_release
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Install llvm-tools-preview
run: rustup component add llvm-tools-preview
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Install grcov
run: cargo install grcov
- name: Run tests with coverage
run: ./scripts/coverage.sh
- name: Codecov upload lcov.info
uses: codecov/codecov-action@v4
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build
runs-on: ${{ matrix.runs-on }}
needs: determine_release
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
strategy:
matrix:
include:
- name: linux_x86_64
runs-on: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: grimoire_css-linux-x86_64
artifact_path: target/x86_64-unknown-linux-gnu/release/grimoire_css
- name: macos_x86_64
runs-on: macos-latest
target: x86_64-apple-darwin
artifact_name: grimoire_css-macos-x86_64
artifact_path: target/x86_64-apple-darwin/release/grimoire_css
- name: macos_arm64
runs-on: macos-12
target: aarch64-apple-darwin
artifact_name: grimoire_css-macos-arm64
artifact_path: target/aarch64-apple-darwin/release/grimoire_css
- name: windows_x86_64
runs-on: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: grimoire_css-windows-x86_64.exe
artifact_path: target/x86_64-pc-windows-msvc/release/grimoire_css.exe
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo git
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-build-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ matrix.target }}-
- name: Build project
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifact
run: |
mkdir -p artifacts
cp "${{ matrix.artifact_path }}" "artifacts/${{ matrix.artifact_name }}"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: artifacts/${{ matrix.artifact_name }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [determine_release, build]
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo git
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }}
cargo publish
release:
name: Release
runs-on: ubuntu-latest
needs: [determine_release, publish]
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Create and push tag
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a "${{ needs.determine_release.outputs.NEW_TAG }}" -m "Release ${{ needs.determine_release.outputs.NEW_TAG }}"
git push origin "${{ needs.determine_release.outputs.NEW_TAG }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.determine_release.outputs.NEW_TAG }}
files: ./artifacts/**/*
body: "Release of Grimoire CSS version ${{ needs.determine_release.outputs.NEW_TAG }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}