-
Notifications
You must be signed in to change notification settings - Fork 6
121 lines (102 loc) · 3.44 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
name: CI
on:
release:
types: [published]
pull_request:
# workflow_dispatch:
permissions:
contents: write
defaults:
run:
shell: bash
jobs:
ci:
strategy:
fail-fast: false
matrix:
# prettier-ignore
cfg:
- { os: macos-latest , target: x86_64-apple-darwin }
- { os: ubuntu-latest , target: x86_64-unknown-linux-musl }
- { os: windows-latest, target: x86_64-pc-windows-msvc }
runs-on: ${{ matrix.cfg.os }}
env:
CARGO: cargo
RUST_TOOLCHAIN: "1.70"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize
id: init
run: |
echo "$HOME/.cargo/bin" >>$GITHUB_PATH
echo "cargo-dependencies=${{ hashFiles('**/Cargo.lock') }}" >>$GITHUB_OUTPUT
- name: Install Just
uses: extractions/setup-just@v1
- name: Cache Rust toolchain
id: cache-rust-toolchain
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.rustup/
key: rust-toolchain-${{ matrix.cfg.target }}-${{ env.RUST_TOOLCHAIN }}
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@v1
if: steps.cache-rust-toolchain.outputs.cache-hit != 'true'
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
targets: ${{ matrix.cfg.target }}
components: rustfmt,clippy
- name: Override Rust toolchain
run: |
rustup override set ${{ env.RUST_TOOLCHAIN }}
echo "CARGO_BUILD_TARGET=${{ matrix.cfg.target }}" >>$GITHUB_ENV
- name: Cache Cargo dependencies
id: cache-cargo-dependencies
uses: actions/cache@v3
with:
path: |
.cargo/config
vendor/
target/
# prettier-ignore
key: cargo-dependencies-${{ matrix.cfg.target }}-${{ steps.init.outputs.cargo-dependencies }}
- name: Vendor Cargo dependencies
if: steps.cache-cargo-dependencies.outputs.cache-hit != 'true'
run: just vendor
- name: Build Cargo dependencies
run: $CARGO build
- name: Run format check
run: $CARGO fmt --check --all
- name: Run tests
run: $CARGO test --workspace
- name: Build release binary
if: github.event_name == 'release' && github.event.action == 'published'
run: |
$CARGO build --verbose --release
echo "RELEASE=true" >>$GITHUB_ENV
echo "RELEASE_DIR=target/$CARGO_BUILD_TARGET/release" >>$GITHUB_ENV
- name: Pack assets (*nix)
if: env.RELEASE && matrix.cfg.os != 'windows-latest'
run: |
asset="nerdfix-$CARGO_BUILD_TARGET.tar.gz"
cp "$RELEASE_DIR/nerdfix" nerdfix
tar -czvf "$asset" nerdfix
echo "ASSET=$asset" >>$GITHUB_ENV
- name: Pack assets (Windows)
if: env.RELEASE && matrix.cfg.os == 'windows-latest'
run: |
asset="nerdfix-$CARGO_BUILD_TARGET.zip"
cp "$RELEASE_DIR/nerdfix.exe" nerdfix.exe
7z a "$asset" nerdfix.exe
echo "ASSET=$asset" >>$GITHUB_ENV
# NOTE: don't save release build dependencies to cache
- name: Clean release build
if: env.RELEASE
run: rm -rf "$RELEASE_DIR"
- name: Upload release asset
uses: softprops/action-gh-release@v1
if: env.RELEASE && startsWith(github.ref, 'refs/tags/')
with:
files: ${{ env.ASSET }}