-
Notifications
You must be signed in to change notification settings - Fork 13
103 lines (83 loc) · 3.61 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
# 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: aarch64-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
if: ${{ matrix.job.target == 'x86_64-unknown-linux-gnu' }}
run: cargo check
- name: Run cargo fmt
if: ${{ matrix.job.target == 'x86_64-unknown-linux-gnu' }}
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)
if [[ "${{ matrix.job.target }}" == *-pc-windows-* ]]; then
PKG_SUFFIX=".zip"
else
PKG_SUFFIX=".tar.gz"
fi
PKG_NAME=${PROJECT_NAME}-${PROJECT_VERSION}-${{ matrix.job.label }}-${{ matrix.job.target }}${PKG_SUFFIX}
if [[ "${{ matrix.job.target }}" == *-pc-windows-* ]]; then
7z -y a "${PKG_NAME}" ./target/${{matrix.job.target}}/release/cncli.exe | tail -2
else
tar -C target/${{matrix.job.target}}/release -czf "${PKG_NAME}" cncli
fi
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 }}