-
Notifications
You must be signed in to change notification settings - Fork 34
280 lines (249 loc) · 11 KB
/
ci-build.yml
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
name: ci-build
on:
push:
branches:
- "**"
pull_request:
branches:
- master
- develop
- 'feature/**'
jobs:
build:
strategy:
matrix:
docker_tag:
- archlinux
- fedora-31
- fedora-32
- fedora-33
- fedora-34
- fedora-37
- fedora-38
- debian-stretch
- debian-buster
- debian-bullseye
- ubuntu-18.04
- ubuntu-20.04
- ubuntu-20.10
- ubuntu-21.04
- ubuntu-22.04
- opensuse-15.0
- opensuse-15.1
- opensuse-15.2
- opensuse-15.3
- opensuse-15.4
- opensuse-15.5
- centos-8
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
env:
DOCKER_IMG: ghcr.io/jahnf/projecteur/projecteur
DOCKER_TAG: ${{ matrix.docker_tag }}
MAKEFLAGS: -j2
CLOUDSMITH_USER: jahnf
CLOUDSMITH_SUMMARY: ci-build from branch '${{ github.ref }}'
CLOUDSMITH_DESC: For more information visit https://github.com/jahnf/Projecteur
steps:
# ===================================================================================
# ---------- Add ~/.local/bin to PATH ----------
- run: |
export LOCAL_BIN=~/.local/bin
echo "${LOCAL_BIN}" >> $GITHUB_PATH
# ===================================================================================
# ---------- Checkout and build inside docker container ----------
- uses: actions/checkout@v3
with:
# unfortunately, currently we need all the history for a valid auto generated version
fetch-depth: 0
- run: |
export BRANCH=${GITHUB_REF/refs\/heads\//}
echo Detected branch: ${BRANCH}
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
- name: Pull ${{ matrix.docker_tag }} docker image
run: |
docker pull ${DOCKER_IMG}:${{ matrix.docker_tag }}
- name: docker create build container
run: |
docker run --name build --env MAKEFLAGS=${MAKEFLAGS} \
--env TRAVIS_BRANCH=${BRANCH} \
-d -v `pwd`:/source:ro -t ${DOCKER_IMG}:${{ matrix.docker_tag }}
- name: cmake configuration
run: docker exec build /bin/bash -c "mkdir -p /build/dist-pkg && cd /build && cmake /source"
- name: cmake build
run: docker exec build /bin/bash -c "cd /build && cmake --build ."
- name: create linux package
run: docker exec build /bin/bash -c "cd /build && cmake --build . --target dist-package"
- name: Run projecteur executable, print version
run: |
docker exec build /bin/bash -c "cd /build && ./projecteur --version"
docker exec build /bin/bash -c "cd /build && ./projecteur -f"
# ===================================================================================
# ---------- Gather artifacts and version information from container build ----------
- name: Get created artifacts from docker container
run: |
docker cp build:/build/dist-pkg .
docker cp build:/build/version-string .
- name: Set version environment variable
run: |
projecteur_version=`cat version-string`
echo "projecteur_version=${projecteur_version}" >> $GITHUB_ENV
- name: Move source package
if: startsWith(matrix.docker_tag, 'archlinux')
run: mkdir -p source-pkg && mv dist-pkg/*source.tar.gz ./source-pkg || true
- name: Get source package filename for artifact uploads
run: |
src_pkg_artifact=`ls -1 source-pkg/* | head -n 1`
echo "src_pkg_artifact=${src_pkg_artifact}" >> $GITHUB_ENV
- name: Get binary package filename for artifact uploads
run: |
dist_pkg_artifact=`ls -1 dist-pkg/* | head -n 1`
echo "dist_pkg_artifact=${dist_pkg_artifact}" >> $GITHUB_ENV
- if: startsWith(matrix.docker_tag, 'archlinux')
run: echo "${{ env.BRANCH }}" >> version-branch
# ===================================================================================
# ---------- Upload artifacts to github ----------
- name: Upload source-pkg artifact to github
if: startsWith(matrix.docker_tag, 'archlinux')
uses: actions/upload-artifact@v3
with:
name: source-package
path: ${{ env.src_pkg_artifact }}
- name: Upload version-info to github
if: startsWith(matrix.docker_tag, 'archlinux')
uses: actions/upload-artifact@v3
with:
name: version-info
path: |
./version-string
./version-branch
- name: Upload binary package artifact to github
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.docker_tag }}-package
path: ${{ env.dist_pkg_artifact }}
# ===================================================================================
# ---------- Set environment variables depending on branch ----------
- name: Set environment variable defaults
run: |
echo "upload_bin_pkg=${{ false }}" >> $GITHUB_ENV
echo "upload_src_pkg=${{ false }}" >> $GITHUB_ENV
echo "cloudsmith_upload_repo=projecteur-develop" >> $GITHUB_ENV
echo "REPO_UPLOAD=${{ false }}" >> $GITHUB_ENV
- name: Check for binary-pkg upload conditions
if: ${{ (env.BRANCH == 'develop' || env.BRANCH == 'master') && github.repository == 'jahnf/Projecteur' }}
run: |
echo "upload_bin_pkg=${{ true }}" >> $GITHUB_ENV
pip install --upgrade wheel
pip install --upgrade cloudsmith-cli
- name: Check for source-pkg upload conditions
if: ${{ env.upload_bin_pkg == 'true' && startsWith(matrix.docker_tag, 'archlinux') && github.repository == 'jahnf/Projecteur' }}
run: |
echo "upload_src_pkg=${{ true }}" >> $GITHUB_ENV
- if: env.BRANCH == 'master'
run: |
echo "cloudsmith_upload_repo=projecteur-stable" >> $GITHUB_ENV
# ===================================================================================
# ---------- Upload artifacts to cloudsmith ----------
- name: Upload raw binary-pkg to cloudsmith
if: env.upload_bin_pkg == 'true'
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
CLOUDSMITH_REPO: ${{ env.cloudsmith_upload_repo }}
run: |
cloudsmith push raw -W -k ${CLOUDSMITH_API_KEY} --name ${{ matrix.docker_tag }} --republish \
--version ${{ env.projecteur_version }} ${CLOUDSMITH_USER}/${CLOUDSMITH_REPO} \
--summary "${CLOUDSMITH_SUMMARY}" --description "${CLOUDSMITH_DESC}" ${{ env.dist_pkg_artifact }}
- name: Upload raw source-pkg to cloudsmith
if: ${{ env.upload_src_pkg == 'true' && github.repository == 'jahnf/Projecteur' }}
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
CLOUDSMITH_REPO: ${{ env.cloudsmith_upload_repo }}
run: |
cloudsmith push raw -W -k ${CLOUDSMITH_API_KEY} --name sources --republish \
--version ${{ env.projecteur_version }} ${CLOUDSMITH_USER}/${CLOUDSMITH_REPO} \
--summary "${CLOUDSMITH_SUMMARY}" --description "${CLOUDSMITH_DESC}" ${{ env.src_pkg_artifact }}
- name: Get package and repo type for upload
if: env.upload_bin_pkg == 'true'
run: |
filename=$(basename -- "${{ env.dist_pkg_artifact }}")
export PKG_TYPE="${filename##*.}"
declare -A distromap=( ["debian-stretch"]="debian/stretch" ["debian-buster"]="debian/buster" \
["debian-bullseye"]="debian/bullseye" ["ubuntu-18.04"]="ubuntu/bionic" \
["ubuntu-20.04"]="ubuntu/focal" ["ubuntu-21.04"]="ubuntu/hirsute" \
["ubuntu-22.04"]="ubuntu/jammy" \
["opensuse-15.1"]="opensuse/15.1" ["opensuse-15.2"]="opensuse/15.2" \
["opensuse-15.3"]="opensuse/15.3" ["opensuse-15.4"]="opensuse/15.4" \
["opensuse-15.5"]="opensuse/15.5" ["centos-8"]="el/8" \
["fedora-31"]="fedora/31" \
["fedora-32"]="fedora/32" ["fedora-33"]="fedora/33" \
["fedora-34"]="fedora/34" ["fedora-37"]="fedora/37" ["fedora-38"]="fedora/38" )
export DISTRO=${distromap[${{ matrix.docker_tag }}]}
echo PKGTYPE=$PKG_TYPE
echo DISTRO=$DISTRO
echo "PKG_TYPE=${PKG_TYPE}" >> $GITHUB_ENV
echo "DISTRO=${DISTRO}" >> $GITHUB_ENV
if [ -z ${DISTRO} ] || [ -z ${PKG_TYPE} ]; then \
export REPO_UPLOAD=false; else export REPO_UPLOAD=true; fi;
echo "REPO_UPLOAD=${REPO_UPLOAD}" >> $GITHUB_ENV
- name: Linux repo upload on cloudsmith for ${{ env.DISTRO }}
if: env.REPO_UPLOAD == 'true'
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
CLOUDSMITH_REPO: ${{ env.cloudsmith_upload_repo }}
run: |
echo Uploading for ${DISTRO} - ${PKG_TYPE}: ${CLOUDSMITH_USER}/${CLOUDSMITH_REPO}/${DISTRO}
cloudsmith push ${PKG_TYPE} -W -k ${CLOUDSMITH_API_KEY} --republish \
${CLOUDSMITH_USER}/${CLOUDSMITH_REPO}/${DISTRO} ${{ env.dist_pkg_artifact }}
# =====================================================================================
# ---------- Upload artifacts to projecteur server ------------
projecteur-bin-upload:
if: ${{ github.repository == 'jahnf/Projecteur' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Get version-info
uses: actions/download-artifact@v3
with:
name: version-info
- name: Extract version info
run: |
BRANCH=`cat version-branch`
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
VERSION=`cat version-string`
echo "VERSION=${VERSION}" >> $GITHUB_ENV
DO_UPLOAD=$(( [ "master" = "$BRANCH" ] || [ "develop" = "$BRANCH" ] ) && echo true || echo false)
echo "DO_UPLOAD=${DO_UPLOAD}" >> $GITHUB_ENV
- uses: actions/download-artifact@v3
if: env.DO_UPLOAD == 'true'
with:
path: artifacts
- name: Create upload directory
if: env.DO_UPLOAD == 'true'
run: |
BRANCHDIR=${{ env.BRANCH }}
[ "master" = "$BRANCHDIR" ] && BRANCHDIR=stable
VERSION=${{ env.VERSION }}
mkdir -p upload/$BRANCHDIR/$VERSION
find ./artifacts -iname "projecteur*" -exec mv -t upload/$BRANCHDIR/$VERSION {} +
BRANCHNAME=${BRANCHDIR/\//_}
BRANCH_FILENAME=${BRANCHNAME}-latest.json
echo '{ "version": "${{ env.VERSION}}" }' >> upload/$BRANCH_FILENAME
echo "BRANCHNAME=${BRANCHNAME}" >> $GITHUB_ENV
find . -iname "projecteur*"
cd upload/$BRANCHDIR/$VERSION
sha1sum * > sha1sums.txt
- name: 📂 Upload files
if: env.DO_UPLOAD == 'true'
run: |
cd upload && sudo apt-get install lftp --no-install-recommends
lftp ${{ secrets.PROJECTEUR_UPLOAD_HOSTNAME }} \
-u "${{ secrets.PROJECTEUR_UPLOAD_USER }},${{ secrets.PROJECTEUR_UPLOAD_TOKEN }}" \
-e "set ftp:ssl-force true; set ssl:verify-certificate true; mirror \
--reverse --upload-older --dereference -x ^\.git/$ ./ ./; quit"
- name: Update latest symlink
if: env.DO_UPLOAD == 'true'
run: |
curl --fail -i -X POST -F "token=${{ secrets.PROJECTEUR_UPDATE_TOKEN }}" \
${{ secrets.PROJECTEUR_UPDATE_URL }}?branch=${{ env.BRANCHNAME }}