-
-
Notifications
You must be signed in to change notification settings - Fork 2
251 lines (215 loc) · 7.83 KB
/
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
247
248
249
250
251
name: 🧪 Release
on:
push:
branches:
- main
- feat/ssg
pull_request:
branches:
- feat/ssg
release:
types: [created]
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
# Build the project for all the targets and generate artifacts.
build:
# This job builds the project for all the targets and generates a
# release artifact that contains the binaries for all the targets.
name: ❯ Build 🛠
# Only run this job on the main branch when a commit is pushed.
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# Set up the job environment variables.
env:
BUILD_ID: ${{ github.run_id }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OS: ${{ matrix.platform.os }}
TARGET: ${{ matrix.platform.target }}
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
runs-on: ${{ matrix.platform.os }}
steps:
# Check out the repository code.
- name: Checkout sources
id: checkout
uses: actions/checkout@v4
# Install the stable Rust toolchain.
- name: Install stable toolchain
id: install-toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
# Cache dependencies to speed up subsequent builds.
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
# Install the targets for the cross-compilation toolchain
- name: Install target
id: install-target
run: rustup target add ${{ env.TARGET }}
# Build the targets
- name: Build targets
id: build-targets
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --workspace --release --target ${{ env.TARGET }}
# Package the binary for each target
- name: Package the binary
id: package-binary
run: |
mkdir -p target/package
tar czf target/package/${{ env.TARGET }}.tar.gz -C target/${{ env.TARGET }}/release .
echo "${{ env.TARGET }}.tar.gz=target/package/${{ env.TARGET }}.tar.gz" >> $GITHUB_ENV
# Upload the binary for each target
- name: Upload the binary
id: upload-binary
uses: actions/upload-artifact@v4
with:
name: ${{ env.TARGET }}.tar.gz
path: target/package/${{ env.TARGET }}.tar.gz
# Release the binary to GitHub Releases
release:
name: ❯ Release 🚀
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: build
runs-on: ubuntu-latest
steps:
# Check out the repository code
- name: Checkout sources
uses: actions/checkout@v4
# Install the stable Rust toolchain
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
# Update the version number based on the Cargo.toml file
- name: Update version number
run: |
NEW_VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2)
echo "VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
shell: /bin/bash -e {0}
# Cache dependencies to speed up subsequent builds
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
# Download the artifacts from the build job
- name: Download artifacts
run: |
for target in ${{ env.TARGET }}; do
echo "Downloading $target artifact"
name="${target}.tar.gz"
echo "Artifact name: $name"
mkdir -p target/package
curl -sSL -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" -L "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${BUILD_ID}/artifacts/${name}" -o "target/package/${name}"
done
env:
VERSION: ${{ env.VERSION }}
TARGET: ${{ env.TARGET }}
OS: ${{ env.OS }}
# Generate the changelog based on the git log
- name: Generate Changelog
id: generate-changelog
env:
BUILD_ID: ${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_URL: https://github.com/sebastienrousseau/ssg/releases
TARGET: ${{ env.TARGET }}
run: |
if [[ ! -f CHANGELOG.md ]]; then
# Set path to changelog file
changelog_file="${{ github.workspace }}/CHANGELOG.md"
# Get version from Cargo.toml
version=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2)
# Append version information to changelog
echo "## Release v${version} - $(date +'%Y-%m-%d')" >> "${changelog_file}"
# Copy content of template file to changelog
cat TEMPLATE.md >> "${changelog_file}"
# Append git log to changelog
echo "$(git log --pretty=format:'%s' --reverse HEAD)" >> "${changelog_file}"
# Append empty line to changelog
echo "" >> "${changelog_file}"
fi
shell: bash
# Create the release on GitHub releases
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
with:
tag_name: v${{ env.VERSION }}
release_name: Shokunin (SSG) 🦀 v${{ env.VERSION }}
body_path: ${{ github.workspace }}/CHANGELOG.md
draft: true
prerelease: false
# Publish the release to Crates.io automatically
crate:
name: ❯ Crate.io 🦀
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: release
runs-on: ubuntu-latest
steps:
# Check out the repository code
- name: Checkout
uses: actions/checkout@v4
# Install the stable Rust toolchain
- name: Install stable toolchain
id: install-toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
# Cache dependencies to speed up subsequent builds
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: /home/runner/.cargo/registry/index/
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-index-
# Update the version number based on the Cargo.toml file
- name: Update version number
id: update-version
run: |
NEW_VERSION=$(grep version Cargo.toml | sed -n 2p | cut -d '"' -f 2)
echo "VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
shell: /bin/bash -e {0}
# Log in to crates.io
- name: Log in to crates.io
id: login-crate-io
run: cargo login ${{ secrets.CARGO_API_TOKEN }}
# Publish the Rust library to Crate.io
- name: Publish Library to Crate.io
id: publish-library
uses: actions-rs/cargo@v1
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_TOKEN }}
with:
command: publish
args: "--no-verify --allow-dirty"
use-cross: false