-
Notifications
You must be signed in to change notification settings - Fork 13
96 lines (76 loc) · 3.4 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
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md
on:
push: { }
name: Validate
jobs:
build:
name: Build
strategy:
fail-fast: false
matrix:
job:
- { os: ubuntu-22.04, label: ubuntu22, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-22.04, label: ubuntu22, target: x86_64-unknown-linux-musl, use-cross: true }
- { os: macos-latest, label: macos, target: x86_64-apple-darwin }
- { os: windows-latest, label: windows, target: x86_64-pc-windows-msvc }
rust: [ stable ]
runs-on: ${{ matrix.job.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- name: Install cross
if: ${{ matrix.job.use-cross }}
run: cargo install cross
- name: Run cargo check
run: cargo check
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo clippy (cross)
if: ${{ matrix.job.use-cross }}
run: cross clippy --release --target ${{ matrix.job.target }} -- -D warnings
- name: Run cargo clippy
if: ${{ !matrix.job.use-cross }}
run: cargo clippy --release --target ${{ matrix.job.target }} -- -D warnings
- name: Run cargo test (cross)
if: ${{ matrix.job.use-cross }}
run: cross test --release --target ${{ matrix.job.target }}
- name: Run cargo test
if: ${{ !matrix.job.use-cross }}
run: cargo test --release --target ${{ matrix.job.target }}
- name: Build Release (cross)
if: ${{ matrix.job.use-cross }}
run: cross build --release --target ${{ matrix.job.target }} --locked
- name: Build Release
if: ${{ !matrix.job.use-cross }}
run: cargo build --release --target ${{ matrix.job.target }} --locked
- name: Package
id: package
run: |
PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml)
PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
PKG_SUFFIX=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac;
PKG_NAME=${PROJECT_NAME}-${PROJECT_VERSION}-${{ matrix.job.label }}-${{ matrix.job.target }}${PKG_SUFFIX}
case ${{ matrix.job.target }} in
*-pc-windows-*) 7z -y a "${PKG_NAME}" ./target/${{matrix.job.target}}/release/cncli.exe | tail -2 ;;
*) tar -C target/${{matrix.job.target}}/release -czf "${PKG_NAME}" cncli ;;
esac;
echo ::set-output name=PKG_NAME::${PKG_NAME}
echo ::set-output name=PKG_PATH::${PKG_NAME}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
prerelease: "${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}"
files: ${{ steps.package.outputs.PKG_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}