generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 2
180 lines (169 loc) · 5.81 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
on:
push:
branches:
- main
tags:
- "*"
pull_request:
name: CI
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: "clippy, rustfmt"
- uses: Swatinem/rust-cache@v2
# make sure all code has been formatted with rustfmt and linted with clippy
- name: Check formatting
run: cargo fmt -- --check --color always
# run clippy to verify we have no warnings
- run: cargo fetch
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
# Some platforms are hostile to automation and are therefore tested without protoc
test-t2:
name: Test non-Linux
strategy:
matrix:
os: [windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-nextest
locked: true
- run: cargo fetch
- name: Build tests
run: cargo b --tests -r
- name: Run tests
run: cargo nextest run -r
coverage-check:
name: Check coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install protoc
run: |
curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v22.2/protoc-22.2-linux-x86_64.zip"
mkdir -p ~/.local
unzip protoc-22.2-linux-x86_64.zip -d ~/.local
export PATH="PATH:$HOME/.local/bin"
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-tarpaulin
locked: true
- name: Code coverage
run: cargo tarpaulin --profile release --features protoc-tests --implicit-test-threads -- --test-threads=1
# Add fail CI to this step when public
- name: Upload coverage
uses: codecov/codecov-action@v3
full-tests:
name: Full test Linux
strategy:
matrix:
target: [x86_64-unknown-linux-gnu,x86_64-unknown-linux-musl]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
if: matrix.target == 'x86_64-unknown-linux-musl'
with:
targets: "x86_64-unknown-linux-musl"
- name: Install protoc
run: |
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v22.2/protoc-22.2-linux-x86_64.zip
mkdir -p ~/.local
unzip protoc-22.2-linux-x86_64.zip -d ~/.local
export PATH="PATH:$HOME/.local/bin"
- uses: baptiste0928/cargo-install@v2
with:
crate: cargo-nextest
locked: true
- run: cargo fetch
- name: Build tests
run: cargo build --tests -r --features protoc-tests --target ${{ matrix.target }}
- name: Run tests
run: cargo nextest run -r --features protoc-tests --target ${{ matrix.target }}
deny-check:
name: Deny check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
publish-check:
name: Publish check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo fetch
- name: Dry run publish
run: cargo publish --dry-run -p proto-gen
release:
name: Release
needs: [full-tests, test-t2, deny-check, coverage-check]
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: proto-gen
- os: windows-latest
target: x86_64-pc-windows-msvc
bin: proto-gen.exe
- os: macOS-latest
target: x86_64-apple-darwin
bin: proto-gen
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y musl-tools
- run: cargo fetch --target ${{ matrix.target }}
- name: Release build
shell: bash
run: |
cargo b --profile lto --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
name=proto-gen
tag=$(git describe --tags --abbrev=0)
release_name="$name-$tag-${{ matrix.target }}"
release_tar="${release_name}.tar.gz"
mkdir -p "$release_name"
if [ "${{ matrix.target }}" != "x86_64-pc-windows-msvc" ]; then
strip "target/${{ matrix.target }}/lto/${{ matrix.bin }}"
fi
cp "target/${{ matrix.target }}/lto/${{ matrix.bin }}" "$release_name/"
cp README.md LICENSE-APACHE LICENSE-MIT "$release_name/"
tar czvf "$release_tar" "$release_name"
rm -r "$release_name"
# Windows environments in github actions don't have the gnu coreutils installed,
# which includes the shasum exe, so we just use powershell instead
if [ "${{ matrix.os }}" == "windows-latest" ]; then
echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c -
else
echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256"
fi
- name: Publish
uses: softprops/action-gh-release@v1
with:
draft: true
files: "proto-gen*"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}