-
Notifications
You must be signed in to change notification settings - Fork 1
244 lines (235 loc) · 7.87 KB
/
workflow.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
name: Scotty Workflow
on:
push:
branches:
- main
paths-ignore:
- "**.md"
- "docs/**"
pull_request:
paths-ignore:
- "**.md"
- "docs/**"
jobs:
commit-msg:
# Commitsar has nothing to check when run directly on master
if: github.ref != 'refs/heads/master'
name: Commit Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check commit message format (necessary to generate release changelogs)
uses: docker://commitsar/commitsar:latest
build-lint:
name: Build, Formatter & Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
# Cache all the things!
- uses: Swatinem/rust-cache@v1
with:
key: v1
# Check if the code meets formatting guidelines
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
# Build to see if the code can compile
- uses: actions-rs/cargo@v1
with:
command: build
args: --all-targets --all-features
# Check if the code has no linter recommendations (clippy can reuse build artifacts, but not the other way around)
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D clippy::all
test:
name: Test Matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable, nightly]
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
# Cache all the things!
- uses: Swatinem/rust-cache@v1
with:
key: v1
# Run the tests
- uses: actions-rs/cargo@v1
with:
command: test
args: --all
# If we tag a release, publish the result to crates.io
publish_crate:
if: startsWith(github.ref, 'refs/tags/v')
name: Publish on crates.io
needs: [publish_binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cargo login $CRATES_IO_TOKEN
- run: cargo publish
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
# If we tag a release, build binaries for supported platforms
build_binaries:
if: startsWith(github.ref, 'refs/tags/v')
name: Build release binaries
needs: [test]
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: scotty-x86_64-unknown-linux-gnu.tar.gz
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
name: scotty-x86_64-unknown-linux-musl.tar.gz
- target: x86_64-apple-darwin
os: macOS-latest
name: scotty-x86_64-apple-darwin.tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
name: scotty-x86_64-pc-windows-msvc.zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Install musl tools
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get install -y musl-tools
- name: Build target
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Prepare build artifacts [Windows]
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
strip scotty.exe
7z a ../../../${{ matrix.name }} scotty.exe
cd -
- name: Prepare build artifacts [-nix]
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
strip scotty
tar czvf ../../../${{ matrix.name }} scotty
cd -
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
publish_binaries:
if: startsWith(github.ref, 'refs/tags/v')
name: Create GitHub Release
needs: [build_binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download releases from github_build
uses: actions/download-artifact@v2
with:
name: scotty-x86_64-unknown-linux-gnu.tar.gz
path: .
- name: Download releases from github_build
uses: actions/download-artifact@v2
with:
name: scotty-x86_64-unknown-linux-musl.tar.gz
path: .
- name: Download releases from github_build
uses: actions/download-artifact@v2
with:
name: scotty-x86_64-apple-darwin.tar.gz
path: .
- name: Download releases from github_build
uses: actions/download-artifact@v2
with:
name: scotty-x86_64-pc-windows-msvc.zip
path: .
- name: Generate checksums
run: for file in scotty-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done
- name: Install go (needed for changelog tool)
uses: actions/setup-go@v2
with:
go-version: 1.14
- name: Generate changelog
run: |
export PATH=${PATH}:$(go env GOPATH)/bin
GO111MODULE=on go get github.com/git-chglog/git-chglog/cmd/git-chglog
git-chglog -c .github/chglog/config.yml $(git describe --tags) > CHANGELOG.md
- name: Create GitHub release ${{ matrix.target }}
uses: softprops/action-gh-release@v1
with:
files: |
scotty-x86_64-unknown-linux-gnu.tar.gz
scotty-x86_64-unknown-linux-gnu.tar.gz.sha256
scotty-x86_64-unknown-linux-musl.tar.gz
scotty-x86_64-unknown-linux-musl.tar.gz.sha256
scotty-x86_64-apple-darwin.tar.gz
scotty-x86_64-apple-darwin.tar.gz.sha256
scotty-x86_64-pc-windows-msvc.zip
scotty-x86_64-pc-windows-msvc.zip.sha256
body_path: CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create homebrew release
uses: actions/github-script@v3
with:
github-token: ${{secrets.HOMEBREW_REPO_TOKEN}}
script: |
const fs = require('fs')
const macAmd64Sha = fs.readFileSync("scotty-x86_64-apple-darwin.tar.gz.sha256", {encoding: "utf8"}).trim()
const macArm64Sha = fs.readFileSync("scotty-arm64-apple-darwin.tar.gz.sha256", {encoding: "utf8"}).trim()
const linuxAmd64Sha = fs.readFileSync("scotty-x86_64-unknown-linux-gnu.tar.gz.sha256", {encoding: "utf8"}).trim()
github.actions.createWorkflowDispatch({
owner: "wdullaer",
repo: "homebrew-scotty",
workflow_id: "workflow.yaml",
ref: "master",
inputs: {
"version": context.ref.substring(10), // "refs/tags/".length == 10
"mac-amd64-sha": macAmd64Sha,
"mac-arm64-sha": macArm64Sha,
"linux-amd64-sha": linuxAmd64Sha
}
})