forked from Xerxes-2/clewdr
-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (201 loc) · 7.14 KB
/
build.yml
File metadata and controls
226 lines (201 loc) · 7.14 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
225
226
name: build
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
APT_PACKAGES: "build-essential cmake perl pkg-config libclang-dev"
CHOCOLATEY_PACKAGES: "cmake strawberryperl pkgconfiglite llvm nasm"
HOMEBREW_PACKAGES: "llvm"
BIN_NAME: "clewdr"
permissions:
contents: write
jobs:
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
check-latest: true
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- name: Build frontend
run: |
cd frontend
pnpm install
pnpm run build
- name: Upload static directory
uses: actions/upload-artifact@v4
with:
name: static-files
path: static/
retention-days: 1
build:
name: Build binary
needs: build-frontend
strategy:
matrix:
os: [linux, musllinux, android, windows, macos]
target_arch: [x86_64, aarch64]
variant: [slim, db]
include:
# rust target vendor + system + environment
- os: android
target_vendor_sys_env: linux-android
- os: macos
target_vendor_sys_env: apple-darwin
- os: linux
target_vendor_sys_env: unknown-linux-gnu
- os: musllinux
target_vendor_sys_env: unknown-linux-musl
- os: windows
target_vendor_sys_env: pc-windows-msvc
# runner
- target_arch: x86_64
runner: ubuntu-latest
- target_arch: aarch64
runner: ubuntu-24.04-arm
- os: android
runner: ubuntu-latest
- os: windows
runner: windows-latest
- os: macos
runner: macos-latest
# musl packages
- os: musllinux
musl_packages: "clang musl-tools"
exclude:
- os: android
target_arch: x86_64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Add Rust target
shell: bash
id: target
run: |
echo "triple=${{ matrix.target_arch }}-${{matrix.target_vendor_sys_env}}" >> $GITHUB_OUTPUT
rustup target add ${{ matrix.target_arch }}-${{matrix.target_vendor_sys_env}} && rustup update
- uses: nttld/setup-ndk@v1.5.0
if: ${{ matrix.os == 'android' }}
id: setup-ndk
with:
ndk-version: r27c
add-to-path: true
- name: Install APT packages
if: contains(matrix.runner, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.musl_packages }} ${{ env.APT_PACKAGES }}
- name: Install Chocolatey Packages
if: matrix.os == 'windows'
run: |
choco install -y ${{ env.CHOCOLATEY_PACKAGES }}
- name: Install Homebrew Packages
if: matrix.os == 'macos'
run: |
brew update
brew install ${{ env.HOMEBREW_PACKAGES }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ steps.target.outputs.triple }}-${{ matrix.variant }}
- name: Prepare variant env (features and suffix)
shell: bash
run: |
BASE_FEATURES="--no-default-features --features embed-resource,portable"
if [ "${{ matrix.variant }}" = "db" ]; then
echo "FEATURE_ARGS=${BASE_FEATURES},db-sqlite,db-postgres,db-mysql" >> $GITHUB_ENV
echo "ARTIFACT_SUFFIX=-db" >> $GITHUB_ENV
else
echo "FEATURE_ARGS=${BASE_FEATURES}" >> $GITHUB_ENV
echo "ARTIFACT_SUFFIX=" >> $GITHUB_ENV
fi
- name: Download static files
uses: actions/download-artifact@v4
with:
name: static-files
path: static
- name: Build ${{ steps.target.outputs.triple }} (${{ matrix.variant }})
if: ${{ matrix.os != 'android' }}
shell: bash
run: |
if [ ${{ matrix.os }} == "musllinux" ]; then
export CXX=${{ matrix.target_arch }}-linux-gnu-g++
export CFLAGS="-D_FORTIFY_SOURCE=0"
export CXXFLAGS="-D_FORTIFY_SOURCE=0"
fi
if [ ${{ matrix.os }} == "windows" ]; then
export RUSTFLAGS="-C target-feature=+crt-static"
fi
cargo build --release --target ${{ steps.target.outputs.triple }} $FEATURE_ARGS
- name: Build with Android NDK (${{ matrix.variant }})
if: ${{ matrix.os == 'android' }}
run: |
cargo install cargo-ndk
cargo ndk --target ${{ steps.target.outputs.triple }} build --release $FEATURE_ARGS
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
- name: Move artifact to work dir and zip (${{ matrix.variant }})
shell: bash
run: |
mv target/${{ steps.target.outputs.triple }}/release/${{ env.BIN_NAME }} .
mkdir -p release-package
mv ${{ env.BIN_NAME }} release-package/
if [ ${{ matrix.os }} == "android" ]; then
mv ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${{ matrix.target_arch }}-linux-android/libc++_shared.so release-package/
fi
cd release-package
if [ ${{ matrix.os }} == "windows" ]; then
7z a -tzip ../${{ env.BIN_NAME }}-${{ matrix.os }}-${{matrix.target_arch}}$ARTIFACT_SUFFIX.zip *
else
zip -r ../${{ env.BIN_NAME }}-${{ matrix.os }}-${{matrix.target_arch}}$ARTIFACT_SUFFIX.zip .
fi
- name: Upload artifact (${{ matrix.variant }})
uses: actions/upload-artifact@v4
with:
name: ${{ env.BIN_NAME }}-${{ matrix.os }}-${{matrix.target_arch}}${{ matrix.variant == 'db' && '-db' || '' }}
path: ${{ env.BIN_NAME }}-${{ matrix.os }}-${{matrix.target_arch}}${{ matrix.variant == 'db' && '-db' || '' }}.zip
retention-days: 1
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
with:
ref: master # Ensure we get the latest master with RELEASE_NOTES.md
fetch-depth: 0 # Full history for consistency
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: List downloaded artifacts
run: ls -R artifacts
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: artifacts/**/${{ env.BIN_NAME }}*.zip
name: ${{ github.ref_name }}
body_path: RELEASE_NOTES.md # Use release notes file
draft: false
prerelease: false
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}