-
Notifications
You must be signed in to change notification settings - Fork 2
97 lines (92 loc) · 3.31 KB
/
build-binary.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
name: build-binary
concurrency:
group: build-binary-${{ github.ref }}
cancel-in-progress: true
on:
release:
types:
- published
push:
branches:
- master
pull_request:
branches:
- master
permissions:
contents: write
jobs:
build:
runs-on: ${{ matrix.image }}
strategy:
matrix:
include:
- image: ubuntu-latest
target: x86_64-unknown-linux-gnu
- image: ubuntu-latest
target: x86_64-unknown-linux-musl
- image: macos-latest
target: x86_64-apple-darwin
- image: ubuntu-latest
target: x86_64-pc-windows-gnu
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust stable
run: |
rustup toolchain install stable --target ${{ matrix.target }}
- if: contains(matrix.target, 'windows')
name: Install Windows dependencies
run: |
sudo apt update
sudo apt install -y gcc-mingw-w64
- if: contains(matrix.target, 'apple')
name: Install Apple dependencies
run: |
brew install openssl coreutils
- name: Build
run: |
cargo build --release --target ${{ matrix.target }}
- name: Get package name
id: package-name
run: |
cargo install --path .
echo "metadata=$(cargo get package.name)" >> $GITHUB_OUTPUT
- name: Get binary name
id: binary-name
run: |
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
echo "binary-name=${{ steps.package-name.outputs.metadata }}.exe" >> $GITHUB_OUTPUT
else
echo "binary-name=${{ steps.package-name.outputs.metadata }}" >> $GITHUB_OUTPUT
fi
- name: Rename binary
run: |
cp target/${{ matrix.target }}/release/${{ steps.binary-name.outputs.binary-name }} target/${{ matrix.target }}/release/${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}
- name: Checksum
run: |
cd target/${{ matrix.target }}/release
sha256sum ${{ steps.package-name.outputs.metadata }}-${{ matrix.target }} > ${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}
target/${{ matrix.target }}/release/${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}.sha256
if-no-files-found: error
- if: github.event_name == 'release' && github.event.action == 'published'
name: Upload assets
uses: softprops/action-gh-release@v1
with:
files: |
target/${{ matrix.target }}/release/${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}
target/${{ matrix.target }}/release/${{ steps.package-name.outputs.metadata }}-${{ matrix.target }}.sha256