-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
133 lines (125 loc) · 3.43 KB
/
action.yaml
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
name: Build Rust
description: >
Builds a rust project and uploads the result as an artifact. The artifact
will contain a single file with the pattern <archive-prefix>-<target>.tar.gz
inputs:
target:
description: "the build target"
required: true
use-cross:
description: "use cross"
required: true
default: "false"
binaries:
description: "whitespace seperated list of binaries to include"
required: true
archive-prefix:
description: "Prefix for the archive. "
required: true
extra-files:
description: "Extra files included in the archive."
required: true
default: ""
upx:
description: "Compress binaries with upx"
required: true
default: "false"
upx-version:
description: "Version of upx to use"
required: true
default: "5.0.0"
upx-args:
description: "Arguments to pass to upx"
required: true
default: "--best --lzma"
package-id:
description: "The package-id to build"
required: true
default: ""
runs:
using: composite
steps:
- uses: dtolnay/rust-toolchain@stable
- name: Setup build arguments
id: build-arguments
env:
PACKAGE: ${{ inputs.package-id }}
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let result = "";
if (process.env.PACKAGE) {
result += ` --package ${process.env.PACKAGE}`;
}
return result;
- name: Setup rustup target
shell: bash
run: |
if [ "${USE_CROSS}" != "true" ]; then
rustup target add ${{ inputs.target }}
fi
- name: Setup Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ inputs.target }}${{ inputs.package-id }}
cache-on-failure: "true"
- name: Build
shell: bash
env:
USE_CROSS: ${{ inputs.use-cross }}
BUILD_ARGUMENTS: ${{ steps.build-arguments.outputs.result }}
TARGET: ${{ inputs.target }}
run: |
if [ "${USE_CROSS}" = "true" ]; then
cargo install cross
CARGO=cross
else
CARGO=cargo
fi
${CARGO} build ${BUILD_ARGUMENTS} --release --target "${TARGET}"
- name: Compress binary
shell: bash
if: ${{ inputs.upx == 'true' }}
env:
BINARIES: ${{ inputs.binaries }}
TARGET: ${{ inputs.target }}
UPX_ARGS: ${{ inputs.upx-args }}
UPX_VERSION: ${{ inputs.upx-version }}
run: |
case "$(uname -m)" in
x86_64)
arch="amd64"
;;
aarch64)
arch="arm64"
;;
*)
echo "Unsupported architecture"
exit 1
;;
esac
curl -o upx.tar.xz -L https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-${arch}_linux.tar.xz
tar xf upx.tar.xz
UPX=$PWD/upx-5.0.0-amd64_linux/upx
for bin in ${BINARIES}; do
"$UPX" $UPX_ARGS "target/${TARGET}/release/${bin}"
done
- name: Package
shell: bash
env:
BINARIES: ${{ inputs.binaries }}
TARGET: ${{ inputs.target }}
ARCHIVE_PREFIX: ${{ inputs.archive-prefix }}
EXTRA_FILES: ${{ inputs.extra-files }}
run: |
mkdir bin
for bin in ${BINARIES}; do
cp "target/${TARGET}/release/${bin}" bin
done
tar czf ${ARCHIVE_PREFIX}-${TARGET}.tar.gz ${EXTRA_FILES} bin
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.target }}
path: ${{ inputs.archive-prefix }}-${{ inputs.target }}.tar.gz