Skip to content

Commit 806ebe9

Browse files
Create testbuild.yml
1 parent 2223eb0 commit 806ebe9

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed

.github/workflows/testbuild.yml

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
name: Test Build binary
2+
3+
on:
4+
#workflow_dispatch
5+
schedule:
6+
- cron: '5 5 * * *'
7+
8+
#permissions:
9+
#contents: write
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
ONIUX_ROOT_DIR: /tmp/oniux
14+
APT: sudo apt -y -qq -o=Dpkg::Use-Pty=0
15+
16+
defaults:
17+
run:
18+
# necessary for windows
19+
shell: bash
20+
21+
jobs:
22+
build:
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
# a list of all the targets
27+
include:
28+
- TARGET: x86_64-unknown-linux-gnu
29+
OS: ubuntu-latest
30+
container: debian:bookworm
31+
32+
- TARGET: x86_64-unknown-linux-gnu
33+
OS: ubuntu-latest
34+
35+
- TARGET: x86_64-unknown-linux-musl
36+
OS: ubuntu-latest
37+
38+
- TARGET: aarch64-unknown-linux-gnu
39+
OS: ubuntu-24.04-arm
40+
41+
- TARGET: aarch64-unknown-linux-musl
42+
OS: ubuntu-24.04-arm
43+
44+
- TARGET: armv7-unknown-linux-gnueabihf
45+
OS: ubuntu-latest
46+
47+
#- TARGET: armv7-unknown-linux-musleabihf
48+
# OS: ubuntu-latest
49+
50+
- TARGET: arm-unknown-linux-gnueabihf
51+
OS: ubuntu-latest
52+
53+
#- TARGET: arm-unknown-linux-musleabihf
54+
# OS: ubuntu-latest
55+
56+
# - TARGET: x86_64-apple-darwin
57+
# OS: macos-latest
58+
59+
# - TARGET: x86_64-pc-windows-msvc
60+
# OS: windows-latest
61+
62+
runs-on: ${{ matrix.OS }}
63+
container:
64+
image: ${{ matrix.container }}
65+
66+
env:
67+
NAME: oniux_binary
68+
TARGET: ${{ matrix.TARGET }}
69+
OS: ${{ matrix.OS }}
70+
71+
outputs:
72+
ONIUX_CURRENT_COMMIT_ID: ${{ steps.release_commit_id.outputs.ONIUX_CURRENT_COMMIT_ID }}
73+
ONIUX_VERSION: ${{ steps.release_version.outputs.ONIUX_VERSION }}
74+
75+
steps:
76+
- name: Get latest release tag of this repo
77+
env:
78+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
run: |
80+
cd /tmp/
81+
ONIUX_PREBUILT_LATEST_TAG=$(gh release list -R mycodedoesnotcompile2/oniux_prebuilt_binary --json tagName -L 1 --jq '.[].tagName' --exclude-drafts --exclude-pre-releases)
82+
echo "ONIUX_PREBUILT_LATEST_TAG=$ONIUX_PREBUILT_LATEST_TAG" >> $GITHUB_ENV
83+
84+
- name: Clone oniux repo and check if there is a new and uncompiled yet version
85+
id: release_commit_id
86+
run: |
87+
cd /tmp/
88+
git clone 'https://gitlab.torproject.org/tpo/core/oniux.git' -o oniux
89+
90+
cd /tmp/oniux/
91+
ONIUX_CURRENT_COMMIT_ID=$(git rev-parse --short HEAD)
92+
echo "ONIUX_CURRENT_COMMIT_ID=$ONIUX_CURRENT_COMMIT_ID" >> $GITHUB_ENV
93+
echo "ONIUX_CURRENT_COMMIT_ID=$ONIUX_CURRENT_COMMIT_ID" >> $GITHUB_OUTPUT
94+
95+
# case: no new commit => abort the workflow
96+
if [[ $ONIUX_PREBUILT_LATEST_TAG == $ONIUX_CURRENT_COMMIT_ID ]]; then
97+
echo "[!] No new version to compile"
98+
exit 100
99+
fi
100+
101+
- name: Get oniux version
102+
id: release_version
103+
uses: nicolaiunrein/cargo-get@master
104+
with:
105+
subcommand: package.version
106+
options: --entry /tmp/oniux/Cargo.toml
107+
108+
- name: Set ONIUX_VERSION env var
109+
run: |
110+
echo "ONIUX_VERSION=${{ steps.release_version.outputs.metadata }}" >> $GITHUB_ENV
111+
echo "ONIUX_VERSION=$ONIUX_VERSION" >> $GITHUB_OUTPUT
112+
113+
- name: Cargo cache
114+
uses: actions/cache@v4
115+
with:
116+
path: |
117+
~/.cargo/registry
118+
/tmp/oniux
119+
key: build-cargo-registry-${{ matrix.TARGET }}
120+
121+
- name: Install and configure dependencies
122+
run: |
123+
# dependencies are only needed on ubuntu as that's the only place where
124+
# we make cross-compilation
125+
if [[ $OS =~ ^ubuntu.*$ ]]; then
126+
$APT update
127+
$APT install crossbuild-essential-armhf libsqlite3-dev
128+
fi
129+
130+
if [[ $TARGET == *"-musl"* ]]; then
131+
$APT install musl-tools
132+
fi
133+
134+
if [[ $TARGET == "arm"* ]]; then
135+
cd "$ONIUX_ROOT_DIR"
136+
cargo install --force --locked bindgen-cli
137+
fi
138+
139+
# some additional configuration for cross-compilation on linux
140+
cat >>~/.cargo/config.toml <<EOF
141+
[target.armv7-unknown-linux-gnueabihf]
142+
linker = "arm-linux-gnueabihf-gcc"
143+
[target.armv7-unknown-linux-musleabihf]
144+
linker = "arm-linux-gnueabihf-gcc"
145+
[target.arm-unknown-linux-gnueabihf]
146+
linker = "arm-linux-gnueabihf-gcc"
147+
[target.arm-unknown-linux-musleabihf]
148+
linker = "arm-linux-gnueabihf-gcc"
149+
EOF
150+
151+
- name: Install rust target
152+
run: rustup target add $TARGET
153+
154+
- name: Run build
155+
run: |
156+
cd $ONIUX_ROOT_DIR
157+
#cargo build --release --verbose --target $TARGET
158+
cargo build --release --target $TARGET
159+
160+
- name: List build information
161+
run: |
162+
OLD_ONIUX_BIN_PATH="$ONIUX_ROOT_DIR/target/$TARGET/release/oniux"
163+
ONIUX_BIN_PATH="$ONIUX_ROOT_DIR-$ONIUX_VERSION-$TARGET"
164+
ONIUX_BIN_HASH_PATH="$ONIUX_BIN_PATH.sha256.txt"
165+
166+
cp -f "$OLD_ONIUX_BIN_PATH" "$ONIUX_BIN_PATH"
167+
ls -alh "$ONIUX_BIN_PATH"
168+
169+
cd "$(dirname "$ONIUX_BIN_PATH")"
170+
sha256sum --tag "$(basename "$ONIUX_BIN_PATH")" | tee "$ONIUX_BIN_HASH_PATH"
171+
172+
echo "ONIUX_BIN_PATH=$ONIUX_BIN_PATH" >> $GITHUB_ENV
173+
echo "ONIUX_BIN_HASH_PATH=$ONIUX_BIN_HASH_PATH" >> $GITHUB_ENV
174+
175+
176+
- name: Upload artifact
177+
uses: actions/upload-artifact@v4
178+
with:
179+
name: binary-${{ matrix.TARGET }}
180+
path: |
181+
${{ env.ONIUX_BIN_PATH }}
182+
${{ env.ONIUX_BIN_HASH_PATH }}
183+
184+
185+
deploy_release:
186+
needs: build
187+
runs-on: ubuntu-latest
188+
env:
189+
ONIUX_CURRENT_COMMIT_ID: ${{ needs.build.outputs.ONIUX_CURRENT_COMMIT_ID }}
190+
ONIUX_VERSION: ${{ needs.build.outputs.ONIUX_VERSION }}
191+
192+
steps:
193+
- name: Download Artifact
194+
uses: actions/download-artifact@v4
195+
with:
196+
pattern: binary-*
197+
merge-multiple: true
198+
path: /tmp/results
199+
200+
- name: List target
201+
run: |
202+
cd "/tmp/results"
203+
ls -alh
204+
205+
RELEASE_NOTES="/tmp/release_notes.txt"
206+
echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_ENV
207+
208+
cat *.sha256.txt > "$RELEASE_NOTES"
209+
mkdir -p "/tmp/hashes"
210+
mv -f *.sha256.txt "/tmp/hashes/"
211+
212+
- name: Create a new Github release
213+
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 #v2.3.2
214+
with:
215+
body_path: ${{ env.RELEASE_NOTES }}
216+
name: ${{ env.ONIUX_VERSION }}
217+
tag_name: ${{ env.ONIUX_CURRENT_COMMIT_ID }}
218+
files: |
219+
/tmp/results/oniux-*

0 commit comments

Comments
 (0)