-
Notifications
You must be signed in to change notification settings - Fork 5
174 lines (152 loc) · 5.91 KB
/
release.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This is a simplification of the workflow for sharkdp/bat.
name: Release
on:
push:
# The idea here is to trigger a release upon receiving a release-like tag
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
env:
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
jobs:
build:
name: ${{ matrix.job.os }} (${{ matrix.job.target }})
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-22.04, target: arm-unknown-linux-gnueabihf, use-cross: true }
- { os: ubuntu-22.04, target: arm-unknown-linux-musleabihf, use-cross: true }
- { os: ubuntu-22.04, target: i686-unknown-linux-gnu, use-cross: true }
- { os: ubuntu-22.04, target: i686-unknown-linux-musl, use-cross: true }
- { os: ubuntu-22.04, target: x86_64-unknown-linux-musl, use-cross: true }
- { os: macos-11, target: x86_64-apple-darwin }
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
esac
- name: Extract crate information
shell: bash
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.job.target }}
override: true
profile: minimal
- name: Show version information (Rust, cargo, GCC)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --release --target=${{ matrix.job.target }}
- name: Strip debug information from executable
id: strip
shell: bash
run: |
STRIP="strip"
case ${{ matrix.job.target }} in
arm-unknown-*) STRIP="arm-linux-gnueabihf-strip" ;;
esac;
BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin"
mkdir -p "${BIN_DIR}"
BIN_NAME="${{ env.PROJECT_NAME }}"
BIN_PATH="${BIN_DIR}/${BIN_NAME}"
# Copy the release build binary to the result location
"${STRIP}" "target/${{ matrix.job.target }}/release/${BIN_NAME}"
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}"
# Let subsequent steps know where to find the (stripped) bin
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
- name: Set testing options
id: test-options
shell: bash
run: |
# test only library unit tests and binary for arm-type targets
unset CARGO_TEST_OPTIONS
case ${{ matrix.job.target }} in arm-*-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac;
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
- name: Run tests
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: test
args: --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} -- --test-threads 1
- name: Create tarball
id: package
shell: bash
run: |
PKG_BASENAME=${PROJECT_NAME}-${PROJECT_VERSION}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}.tar.gz
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
cp "${{ steps.strip.outputs.BIN_PATH }}" LICENSE "$ARCHIVE_DIR"
tar -C "${PKG_STAGING}/${PKG_BASENAME}" -cvzf "${PKG_STAGING}/${PKG_NAME}" "${PROJECT_NAME}" LICENSE
# Let subsequent steps know where to find the compressed package
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
- name: Install cargo-deb
if: contains(matrix.job.target, 'musl')
run: cargo install cargo-deb
- name: Create deb package
if: contains(matrix.job.target, 'musl')
id: debian-package
shell: bash
run: |
cargo deb --target ${{ matrix.job.target }} --no-build --no-strip
DEB_PATH=target/${{ matrix.job.target }}/debian/*.deb
DEB_NAME=$(basename ${DEB_PATH})
echo Names are ${DEB_NAME} and ${DEB_PATH}
echo "DEB_NAME=${DEB_NAME}" >> $GITHUB_OUTPUT
echo "DEB_PATH=${DEB_PATH}" >> $GITHUB_OUTPUT
- name: "Artifact upload: tarball"
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
if-no-files-found: error
- name: "Artifact upload: Debian package"
uses: actions/upload-artifact@v3
if: steps.debian-package.outputs.DEB_NAME
with:
name: ${{ steps.debian-package.outputs.DEB_NAME }}
path: ${{ steps.debian-package.outputs.DEB_PATH }}
if-no-files-found: error
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
with:
files: |
${{ steps.package.outputs.PKG_PATH }}
${{ steps.debian-package.outputs.DEB_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}