-
Notifications
You must be signed in to change notification settings - Fork 5
198 lines (164 loc) · 5.54 KB
/
ci.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
on:
pull_request: {}
push:
branches:
- master
tags: [ 'v*.*.*' ]
name: CI
env:
CARGO_TERM_COLOR: always
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Cache rust dependencies
uses: Swatinem/rust-cache@v2
- name: Check that Cargo.lock is up-to-date
run: cargo metadata --format-version 1 --locked
- name: Run cargo fmt
run: cargo fmt --check
- name: Run cargo clippy
run: cargo clippy -- -D warnings
- name: Run cargo check
run: cargo check
test:
strategy:
matrix:
runner: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Cache rust dependencies
uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: cargo test
versions:
runs-on: ubuntu-latest
steps:
- uses: taiki-e/install-action@v2
with:
tool: cargo-hack,cargo-minimal-versions
- name: Checkout sources
uses: actions/checkout@v3
- name: Cache rust dependencies
uses: Swatinem/rust-cache@v2
# Check with minimal dependency versions and MSRV from Cargo.toml
- name: Check minimal versions
run: cargo minimal-versions check --rust-version --features vendored-openssl,vendored-libgit2
semver:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
flake:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install nix
uses: DeterminateSystems/nix-installer-action@v12
- name: Cache nix dependencies
uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Build
run: nix flake check
update-release-draft:
runs-on: ubuntu-latest
if: github.repository == 'coralogix/protofetch' && github.ref == 'refs/heads/master'
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package:
needs: [ lint, test, versions, semver ]
strategy:
fail-fast: false
matrix:
target:
- rust: aarch64-unknown-linux-musl
runner: ubuntu-latest
tar: tar
cross: true
ext:
- rust: x86_64-unknown-linux-musl
runner: ubuntu-latest
tar: tar
cross: true
ext:
- rust: aarch64-apple-darwin
runner: macos-14
# We use gtar to make sure compressed files are not detected as sparse
tar: gtar
cross: false
ext:
- rust: x86_64-apple-darwin
runner: macos-12
# We use gtar to make sure compressed files are not detected as sparse
tar: gtar
cross: false
ext:
- rust: x86_64-pc-windows-msvc
runner: windows-latest
tar: tar
cross: false
ext: '.exe'
runs-on: ${{ matrix.target.runner }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache rust dependencies
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target.rust }}
- name: Install cross
if: ${{ matrix.target.cross }}
run: cargo install --locked cross
- name: Build
run: ${{ matrix.target.cross && 'cross' || 'cargo' }} build --release --target ${{ matrix.target.rust }} --features vendored-openssl,vendored-libgit2
- name: Package
run: |
mv target/${{ matrix.target.rust }}/release bin/
${{ matrix.target.tar }} -czvf protofetch_${{ matrix.target.rust }}.tar.gz bin/protofetch${{ matrix.target.ext }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: packages
path: protofetch_${{ matrix.target.rust }}.tar.gz
release:
runs-on: ubuntu-latest
if: github.repository == 'coralogix/protofetch' && startsWith(github.ref, 'refs/tags/')
needs: [ package ]
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Publish cargo package
run: cargo publish --token ${{ env.CRATES_IO_TOKEN }}
- name: Publish npm package
run: |
VERSION=$(sed -n -e '/version/ s/.* = *//p' "Cargo.toml" | head -1 | tr -d '"')
export VERSION
# Tee had issue to write to the same file which is used for read so creating a temp package.json file
mv .github/npm/package.json .github/npm/package.json.temp
sed "s/VERSION#TO#REPLACE/${VERSION}/g" .github/npm/package.json.temp | tee .github/npm/package.json
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ".npmrc"
npm publish .github/npm
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: packages
- name: Upload release artifacts
uses: softprops/action-gh-release@v1
with:
files: |
protofetch_aarch64-unknown-linux-musl.tar.gz
protofetch_x86_64-unknown-linux-musl.tar.gz
protofetch_aarch64-apple-darwin.tar.gz
protofetch_x86_64-apple-darwin.tar.gz
protofetch_x86_64-pc-windows-msvc.tar.gz