-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
389 lines (331 loc) · 15.1 KB
/
Jenkinsfile
File metadata and controls
389 lines (331 loc) · 15.1 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// SPDX-FileCopyrightText: 2025, 2026 William Bell
//
// SPDX-License-Identifier: GPL-3.0-or-later
pipeline {
agent any
environment {
GITEA_URL = 'https://git.wbell.dev'
GITEA_REPO = 'Open-Argon/Chloride'
}
stages {
stage('Checkout') {
steps {
script {
if (env.GIT_TAG) {
echo "Checking out tag: ${env.GIT_TAG}"
checkout([
$class: 'GitSCM',
branches: [[name: "refs/tags/${env.GIT_TAG}"]],
userRemoteConfigs: [[url: scm.userRemoteConfigs[0].url]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'SubmoduleUpdate', recursiveSubmodules: true]
]
])
} else {
echo "Checking out normal branch"
checkout scm
}
sh 'git submodule update --init --recursive'
}
}
}
stage('Detect Tag') {
steps {
script {
def tag = sh(script: "git describe --tags", returnStdout: true).trim()
echo "Tag detected: ${tag}"
if (tag.toLowerCase().contains('unstable')) {
echo "Tag contains 'unstable' → marking build UNSTABLE"
currentBuild.result = 'UNSTABLE'
}
currentBuild.displayName = "#${env.BUILD_NUMBER} ${tag}"
env.TAG_NAME = tag
}
}
}
stage('Archive Source') {
steps {
script {
def version = env.TAG_NAME ?: "dev"
env.OUTPUT_FILE = "archives/source.tar.gz"
echo "Packaging Source as: ${env.OUTPUT_FILE}"
}
sh '''
mkdir -p archives
git ls-files --recurse-submodules | tar -czf $OUTPUT_FILE -T -
'''
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('Setup Conan') {
steps {
sh '''
apt update
# Add Microsoft package feed for dotnet
apt install -y cmake flex python3 python3-pip python3-venv make gcc-mingw-w64 mingw-w64 ninja-build zip jq gh dpkg-dev rpm gpg nsis
python3 -m venv /tmp/venv
. /tmp/venv/bin/activate
pip install --upgrade pip
pip install conan
mkdir -p archives macos-artifacts
rm -rf archives/* macos-artifacts/* *.zip *.tar.gz
'''
}
}
stage('Build (Parallel)') {
parallel {
stage('Linux Build') {
environment {
CONAN_HOME = "${WORKSPACE}/.conan-linux"
}
stages {
stage('Build') {
steps {
sh '''
. /tmp/venv/bin/activate
rm -rf out/linux $CONAN_HOME
conan profile detect
conan install . --build=missing -of "out/linux"
conan build . -of "out/linux"
cp -r stdlib out/linux/build/dist/
./build-stdlib.sh out/linux/build/dist/stdlib -j ARGON_INCLUDE="$(realpath include)"
'''
}
}
}
}
stage('Windows Build') {
environment {
CONAN_HOME = "${WORKSPACE}/.conan-windows"
}
stages {
stage('Build') {
steps {
sh '''
. /tmp/venv/bin/activate
rm -rf out/windows $CONAN_HOME
conan profile detect
conan install . \
--profile:host=mingw-x86_64.txt \
--build=missing -of "out/windows"
conan build . \
--profile:host=mingw-x86_64.txt -of "out/windows"
cp -r stdlib out/windows/build/dist/
./build-stdlib.sh out/windows/build/dist/stdlib -j TARGET_OS=windows ARGON_INCLUDE="$(realpath include)"
'''
}
}
}
}
stage('macOS Build (GitHub Actions)') {
environment {
GH_TOKEN = credentials('github-pat')
GH_REPO = 'open-argon/chloride'
WORKFLOW = 'macOS Build (Jenkins-triggered)'
BUILD_NAME_ARG = "${env.TAG_NAME ?: 'dev'}"
}
steps {
sh '''
set -e
# Decide what ref to build
REF=$(git describe --tags --exact-match 2>/dev/null || git rev-parse HEAD)
echo "Triggering macOS build for ref: $REF"
# Trigger workflow
gh workflow run "$WORKFLOW" \
--repo "$GH_REPO" \
--ref main \
-f ref="$REF" \
-f build_name="$BUILD_NAME_ARG"
# Get the latest run ID
RUN_ID=$(gh run list \
--repo "$GH_REPO" \
--workflow "$WORKFLOW" \
--limit 1 \
--json databaseId \
-q '.[0].databaseId')
echo "Waiting for GitHub Actions run $RUN_ID"
gh run watch "$RUN_ID" --repo "$GH_REPO"
# Download artifact
gh run download "$RUN_ID" \
--repo "$GH_REPO" \
--name macos-build \
--dir macos-artifacts
'''
}
}
}
}
stage('Archive Linux') {
steps {
script {
def version = env.TAG_NAME ?: "dev"
env.OUTPUT_FILE = "archives/argon-${version}-linux-x86_64.tar.gz"
echo "Packaging Linux as: ${env.OUTPUT_FILE}"
}
sh '''
cp LICENSE.txt out/linux/build/dist/
cp -r LICENSES out/linux/build/dist/
cp -r include out/linux/build/dist/
tar -czf "$OUTPUT_FILE" -C out/linux/build/dist .
'''
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('Debian Package Build') {
steps {
script {
def version = env.TAG_NAME ?: "0.0.0-1"
env.DEB_VERSION = version.replaceFirst('^v', '') // strip leading 'v'
env.OUTPUT_FILE = "archives/argon-${env.DEB_VERSION}-x86_64.deb"
env.PACKAGE_ROOT = "${env.WORKSPACE}/argon-${env.DEB_VERSION}-x86_64"
}
withCredentials([string(credentialsId: 'gitea-pat', variable: 'GITEA_TOKEN')]) {
sh '''
set -e
INSTALL_INTERNAL="/usr/local/lib/chloride"
rm -rf "$PACKAGE_ROOT"
DESTDIR="$PACKAGE_ROOT" cmake --install out/linux/build --prefix "$INSTALL_INTERNAL"
mkdir -p "$PACKAGE_ROOT$INSTALL_INTERNAL/stdlib"
cp -R out/linux/build/dist/stdlib/* "$PACKAGE_ROOT$INSTALL_INTERNAL/stdlib/"
mkdir -p "$PACKAGE_ROOT/usr/bin"
printf '#!/bin/bash\nexec "%s/bin/argon" "$@"\n' "$INSTALL_INTERNAL" \
> "$PACKAGE_ROOT/usr/bin/argon"
chmod +x "$PACKAGE_ROOT/usr/bin/argon"
mkdir -p "$PACKAGE_ROOT/DEBIAN"
printf 'Package: argon\nVersion: %s\nArchitecture: amd64\nMaintainer: Ugric\nDescription: Interpreter written in C for the argon programming language\n' \
"$DEB_VERSION" > "$PACKAGE_ROOT/DEBIAN/control"
cat > "$PACKAGE_ROOT/DEBIAN/postrm" << 'EOF'
#!/bin/bash
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
rm -rf /usr/local/lib/chloride
fi
EOF
chmod +x "$PACKAGE_ROOT/DEBIAN/postrm"
dpkg-deb --build "$PACKAGE_ROOT" "$OUTPUT_FILE"
curl --fail --user Jenkins:$GITEA_TOKEN \
--upload-file $OUTPUT_FILE \
https://git.wbell.dev/api/packages/Open-Argon/debian/pool/trixie/main/upload
'''
}
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('RPM Package Build') {
steps {
script {
def version = env.TAG_NAME ?: "0.0.0-1"
env.RPM_VERSION = version.replaceFirst('^v', '').replaceAll('-', '.')
env.OUTPUT_FILE = "archives/argon-${env.RPM_VERSION}-x86_64.rpm"
env.RPM_BUILD_ROOT = "${env.WORKSPACE}/rpmbuild"
}
withCredentials([string(credentialsId: 'gitea-pat', variable: 'GITEA_TOKEN'), file(credentialsId: 'rpm-signing-key', variable: 'GPG_KEY_FILE')]) {
sh '''
set -e
INSTALL_INTERNAL="/usr/local/lib/chloride"
rm -rf "$RPM_BUILD_ROOT"
mkdir -p "$RPM_BUILD_ROOT/BUILD" "$RPM_BUILD_ROOT/RPMS" \
"$RPM_BUILD_ROOT/SOURCES" "$RPM_BUILD_ROOT/SPECS" "$RPM_BUILD_ROOT/SRPMS"
PACKAGE_ROOT="$RPM_BUILD_ROOT/BUILDROOT"
DESTDIR="$PACKAGE_ROOT" cmake --install out/linux/build --prefix "$INSTALL_INTERNAL"
mkdir -p "$PACKAGE_ROOT$INSTALL_INTERNAL/stdlib"
cp -R out/linux/build/dist/stdlib/* "$PACKAGE_ROOT$INSTALL_INTERNAL/stdlib/"
mkdir -p "$PACKAGE_ROOT/usr/bin"
printf \'#!/bin/bash\\nexec "%s/bin/argon" "$@"\\n\' "$INSTALL_INTERNAL" \
> "$PACKAGE_ROOT/usr/bin/argon"
chmod +x "$PACKAGE_ROOT/usr/bin/argon"
CHANGELOG_DATE=$(date \'+%a %b %d %Y\')
cat > "$RPM_BUILD_ROOT/SPECS/argon.spec" << SPEC
Name: argon
Version: ${RPM_VERSION}
Release: 1%{?dist}
Summary: Interpreter written in C for the Argon Programming Language
License: GPL-3.0-or-later
URL: https://git.wbell.dev/Open-Argon/Chloride
BuildArch: x86_64
%description
Interpreter written in C for the Argon Programming Language
%install
cp -r ${PACKAGE_ROOT}/* %{buildroot}/
%files
/usr/bin/argon
${INSTALL_INTERNAL}/bin/argon
${INSTALL_INTERNAL}/stdlib/
%changelog
* ${CHANGELOG_DATE} Jenkins <jenkins@wbell.dev> - ${RPM_VERSION}-1
- Automated build from tag ${TAG_NAME}
SPEC
rpmbuild --define "_topdir $RPM_BUILD_ROOT" \
-bb "$RPM_BUILD_ROOT/SPECS/argon.spec"
BUILT_RPM=$(find "$RPM_BUILD_ROOT/RPMS" -name "argon-*.rpm" | head -1)
mkdir -p archives
cp "$BUILT_RPM" "$OUTPUT_FILE"
gpg --batch --import "$GPG_KEY_FILE"
echo "%_gpg_name William Bell <william@wbell.dev>" > ~/.rpmmacros
rpm --addsign "$OUTPUT_FILE"
curl --fail --user Jenkins:$GITEA_TOKEN \
--upload-file "$OUTPUT_FILE" \
https://git.wbell.dev/api/packages/Open-Argon/rpm/upload
'''
}
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('Archive Windows') {
steps {
script {
def version = env.TAG_NAME ?: "dev"
env.OUTPUT_FILE = "archives/argon-${version}-windows-x86_64.zip"
echo "Packaging Windows as: ${env.OUTPUT_FILE}"
}
sh '''
set -e
cp LICENSE.txt out/windows/build/dist/
cp -r LICENSES out/windows/build/dist/
cp -r include out/windows/build/dist/
(
cd "out/windows/build/dist" && zip -r "../../../../$OUTPUT_FILE" .
)
'''
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('Windows Installer build') {
steps {
script {
def version = env.TAG_NAME ?: "dev"
env.ARGON_VERSION = "${version}"
env.OUTPUT_FILE = "archives/argon-${version}-windows-installer-x86_64.exe"
echo "Packaging Windows as: ${env.OUTPUT_FILE}"
}
sh '''
set -e
python3 build-windows-installer.py
makensis -DOUTFILE="$OUTPUT_FILE" installer.nsi
'''
archiveArtifacts artifacts: "${env.OUTPUT_FILE}", allowEmptyArchive: false, fingerprint: true
}
}
stage('Archive macOS') {
steps {
archiveArtifacts artifacts: 'macos-artifacts/**/*.tar.gz', fingerprint: true
}
}
}
post {
always {
script {
def tag = sh(script: "git describe --tags", returnStdout: true).trim()
echo "Detected tag: ${tag}"
if (tag.toLowerCase().contains("unstable")) {
echo "Unstable tag detected"
currentBuild.result = "SUCCESS"
} else {
echo "Stable tagged build"
currentBuild.description = "Stable"
currentBuild.result = "SUCCESS"
}
}
}
}
}