-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (126 loc) · 4.96 KB
/
Copy pathautoBuild.yml
File metadata and controls
138 lines (126 loc) · 4.96 KB
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
name: Auto Build Release
on:
push:
tags:
- "v*"
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-C codegen-units=1 -C strip=symbols"
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
prefix-key: release
key: ${{ matrix.target }}
cache-on-failure: true
- name: Cache cargo tools
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
if: matrix.target == 'x86_64-unknown-linux-gnu'
with:
path: ~/.cargo/bin
key: cargo-tools-${{ runner.os }}-deb-rpm
restore-keys: cargo-tools-${{ runner.os }}-
- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install cargo tools
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
if ! command -v cargo-deb &> /dev/null; then
cargo install cargo-deb
fi
if ! command -v cargo-generate-rpm &> /dev/null; then
cargo install cargo-generate-rpm
fi
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Get crate info
id: crate_info
run: |
echo "name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')" >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
shell: bash
- name: Create archives and packages
run: |
cd target/${{ matrix.target }}/release
case "${{ runner.os }}" in
"Windows")
7z a ../../../${{ steps.crate_info.outputs.name }}-${{ matrix.target }}-${{ steps.crate_info.outputs.version }}.zip ${{ steps.crate_info.outputs.name }}.exe
cp ${{ steps.crate_info.outputs.name }}.exe ../../../${{ steps.crate_info.outputs.name }}-${{ matrix.target }}-${{ steps.crate_info.outputs.version }}.exe
;;
*)
tar czf ../../../${{ steps.crate_info.outputs.name }}-${{ matrix.target }}-${{ steps.crate_info.outputs.version }}.tar.gz ${{ steps.crate_info.outputs.name }}
;;
esac
shell: bash
- name: Create DEB package
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
cargo deb --target ${{ matrix.target }} --no-build
cp target/${{ matrix.target }}/debian/*.deb ${{ steps.crate_info.outputs.name }}-${{ steps.crate_info.outputs.version }}-amd64.deb
- name: Create RPM package
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
cargo generate-rpm --target ${{ matrix.target }}
find target/${{ matrix.target }}/generate-rpm -name "*.rpm" -exec cp {} ${{ steps.crate_info.outputs.name }}-${{ steps.crate_info.outputs.version }}-1.x86_64.rpm \;
- name: Upload artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ steps.crate_info.outputs.name }}-${{ matrix.target }}
path: |
*.tar.gz
*.zip
*.exe
*.deb
*.rpm
retention-days: 1
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
- name: Get crate info
id: crate_info
run: |
echo "name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')" >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
with:
files: artifacts/**/*
name: "v${{ steps.crate_info.outputs.version }}"
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}