forked from redlib-org/redlib
-
Notifications
You must be signed in to change notification settings - Fork 1
224 lines (176 loc) · 6.91 KB
/
main.yml
File metadata and controls
224 lines (176 loc) · 6.91 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Build binary
on:
workflow_dispatch
#schedule:
# - cron: '5 5 * * *'
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
REDLIB_ROOT_DIR: /tmp/redlib
APT: sudo apt -y -qq -o=Dpkg::Use-Pty=0
defaults:
run:
shell: bash
jobs:
get_prebuilt_last_tag:
runs-on: ubuntu-latest
outputs:
REDLIB_PREBUILT_LATEST_TAG: ${{ steps.release_latest_tag.outputs.REDLIB_PREBUILT_LATEST_TAG }}
steps:
- name: Get latest release tag of this repo
id: release_latest_tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd /tmp/
REDLIB_PREBUILT_LATEST_TAG=$(gh release list -R mycodedoesnotcompile2/redlib_fork --json tagName -L 1 --jq '.[].tagName' --exclude-drafts --exclude-pre-releases)
echo "REDLIB_PREBUILT_LATEST_TAG=$REDLIB_PREBUILT_LATEST_TAG" >> $GITHUB_OUTPUT
build:
needs: get_prebuilt_last_tag
strategy:
fail-fast: false
matrix:
include:
- TARGET: x86_64-unknown-linux-gnu
OS: ubuntu-latest
- TARGET: x86_64-unknown-linux-musl
OS: ubuntu-latest
- TARGET: aarch64-unknown-linux-gnu
OS: ubuntu-24.04-arm
- TARGET: aarch64-unknown-linux-musl
OS: ubuntu-24.04-arm
- TARGET: armv7-unknown-linux-gnueabihf
OS: ubuntu-latest
# - TARGET: armv7-unknown-linux-musleabihf
# OS: ubuntu-latest
# CONTAINER: ghcr.io/rust-cross/rust-musl-cross:armv7-musleabihf
- TARGET: arm-unknown-linux-gnueabihf
OS: ubuntu-latest
#- TARGET: arm-unknown-linux-musleabihf
# OS: ubuntu-latest
# - TARGET: x86_64-apple-darwin
# OS: macos-latest
# - TARGET: x86_64-pc-windows-msvc
# OS: windows-latest
runs-on: ${{ matrix.OS }}
container:
image: ${{ matrix.CONTAINER }}
env:
TARGET: ${{ matrix.TARGET }}
OS: ${{ matrix.OS }}
CONTAINER: ${{ matrix.CONTAINER }}
REDLIB_PREBUILT_LATEST_TAG: ${{ needs.get_prebuilt_last_tag.outputs.REDLIB_PREBUILT_LATEST_TAG }}
outputs:
REDLIB_CURRENT_COMMIT_ID: ${{ steps.release_commit_id.outputs.REDLIB_CURRENT_COMMIT_ID }}
REDLIB_VERSION: ${{ steps.release_version.outputs.REDLIB_VERSION }}
steps:
- name: Clone redlib repo and check if there is a new and uncompiled yet version
id: release_commit_id
run: |
cd /tmp/
git clone 'https://github.com/mycodedoesnotcompile2/redlib_fork.git' redlib
ls -alh .
cd $REDLIB_ROOT_DIR
REDLIB_CURRENT_COMMIT_ID=$(git rev-parse --short HEAD)
echo "REDLIB_CURRENT_COMMIT_ID=$REDLIB_CURRENT_COMMIT_ID" >> $GITHUB_ENV
echo "REDLIB_CURRENT_COMMIT_ID=$REDLIB_CURRENT_COMMIT_ID" >> $GITHUB_OUTPUT
# case: no new commit => abort the workflow
if [[ $REDLIB_PREBUILT_LATEST_TAG == $REDLIB_CURRENT_COMMIT_ID ]]; then
echo "[!] No new version to compile"
exit 100
fi
- name: Get redlib version
id: release_version_cargo_get
uses: nicolaiunrein/cargo-get@master
with:
subcommand: package.version
options: --entry "$REDLIB_ROOT_DIR/Cargo.toml"
- name: Set REDLIB_VERSION env var
id: release_version
run: |
REDLIB_VERSION=${{ steps.release_version_cargo_get.outputs.metadata }}
echo "REDLIB_VERSION=$REDLIB_VERSION" >> $GITHUB_ENV
echo "REDLIB_VERSION=$REDLIB_VERSION" >> $GITHUB_OUTPUT
- name: Install and configure dependencies
run: |
if [[ $OS =~ ^ubuntu.*$ ]]; then
$APT update
$APT install crossbuild-essential-armhf
fi
# for musl builds
if [[ $TARGET == *"-musl"* ]]; then
$APT install musl-tools
fi
# for arm targets
if [[ $TARGET == "arm"* ]]; then
cd "$REDLIB_ROOT_DIR"
cargo install --force --locked bindgen-cli
fi
# some additional configuration for cross-compilation on linux
cat >>~/.cargo/config.toml <<EOF
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF
- name: Install rust target
run: rustup target add $TARGET
- name: Run build
run: |
cd $REDLIB_ROOT_DIR
cargo build --release --target $TARGET
- name: List build information
run: |
OLD_REDLIB_BIN_PATH="$REDLIB_ROOT_DIR/target/$TARGET/release/redlib"
REDLIB_BIN_PATH="$REDLIB_ROOT_DIR-$REDLIB_VERSION-wproxy-$TARGET"
REDLIB_BIN_HASH_PATH="$REDLIB_BIN_PATH.sha256.txt"
cp -f "$OLD_REDLIB_BIN_PATH" "$REDLIB_BIN_PATH"
ls -alh "$REDLIB_BIN_PATH"
cd "$(dirname "$REDLIB_BIN_PATH")"
sha256sum --tag "$(basename "$REDLIB_BIN_PATH")" | tee "$REDLIB_BIN_HASH_PATH"
echo "REDLIB_BIN_PATH=$REDLIB_BIN_PATH" >> $GITHUB_ENV
echo "REDLIB_BIN_HASH_PATH=$REDLIB_BIN_HASH_PATH" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.TARGET }}
path: |
${{ env.REDLIB_BIN_PATH }}
${{ env.REDLIB_BIN_HASH_PATH }}
deploy_release:
needs: build
runs-on: ubuntu-latest
env:
REDLIB_CURRENT_COMMIT_ID: ${{ needs.build.outputs.REDLIB_CURRENT_COMMIT_ID }}
REDLIB_VERSION: ${{ needs.build.outputs.REDLIB_VERSION }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
pattern: binary-*
merge-multiple: true
path: /tmp/results
- name: List target
run: |
cd "/tmp/results"
ls -alh
RELEASE_NOTES="/tmp/release_notes.txt"
echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_ENV
cat *.sha256.txt > "$RELEASE_NOTES"
sha256sum -c *.sha256.txt
mkdir -p "/tmp/hashes"
mv -f *.sha256.txt "/tmp/hashes/"
- name: Create a new Github release
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 #v2.3.2
with:
make_latest: true
body_path: ${{ env.RELEASE_NOTES }}
name: version ${{ env.REDLIB_VERSION }} - build ${{ env.REDLIB_CURRENT_COMMIT_ID }}
tag_name: ${{ env.REDLIB_CURRENT_COMMIT_ID }}
files: |
/tmp/results/redlib-*