forked from runfalk/synology-wireguard
-
Notifications
You must be signed in to change notification settings - Fork 13
276 lines (217 loc) · 8.28 KB
/
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
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com) and contributors
# SPDX-FileContributor: Sebastian Thomschke, Vegard IT GmbH
# SPDX-License-Identifier: Apache-2.0
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Build
on:
push:
branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
tags-ignore: # don't build tags
- '**'
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '**/*.rst'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
pull_request:
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '**/*.rst'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
workflow_dispatch:
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
inputs:
DSM_VERSION:
description: 'DSM Version'
required: true
default: '7.2'
defaults:
run:
shell: bash
env:
SYNO_TOOLKIT_BASE_URL: https://global.download.synology.com/download/ToolChain/toolkit
DSM_VERSION: '7.2'
jobs:
###########################################################
preparation:
###########################################################
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: Determine effective DSM version
run: |
set -eux
if [[ -n "${{ github.event.inputs.DSM_VERSION }}" ]]; then
echo "DSM_VERSION=${{ github.event.inputs.DSM_VERSION }}" >> $GITHUB_ENV
fi
- uses: actions/cache@v4 # https://github.com/actions/cache
id: cache_synology_toolkit_base_env
with:
path: toolkit_tarballs/base_env-*
key: synology_toolkit_tarballs_DSM${{ env.DSM_VERSION }}_base_env
lookup-only: true
- name: Download Synology Base Toolkit tarball
if: steps.cache_synology_toolkit_base_env.outputs.cache-hit != 'true'
run: |
set -eux
mkdir -p toolkit_tarballs
pushd toolkit_tarballs/
archive=base_env-${DSM_VERSION}.txz
curl -sSf "$SYNO_TOOLKIT_BASE_URL/$DSM_VERSION/base/$archive" -o $archive
popd
###########################################################
build-spks:
###########################################################
runs-on: ubuntu-latest
needs:
- preparation
strategy:
fail-fast: false
matrix:
# see https://kb.synology.com/en-uk/DSM/tutorial/What_kind_of_CPU_does_my_NAS_have
PACKAGE_ARCH:
- apollolake # e.g. DS918+
- armada37xx
- armada38x
- avoton
- braswell # e.g. DS716+II
- broadwell
- broadwellnk
- bromolow
#- cedarview # no DSM 7.2 support
- denverton # e.g. RS2418+
- geminilake
- grantley
- kvmx64
- monaco
- purley
- r1000
- rtd1296
- rtd1619b
- v1000
steps:
- name: Determine effective DSM version
run: |
set -eux
if [[ -n "${{ github.event.inputs.DSM_VERSION }}" ]]; then
echo "DSM_VERSION=${{ github.event.inputs.DSM_VERSION }}" >> $GITHUB_ENV
fi
- name: "Show: environment variables"
run: env | sort
- name: Git checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: Build [synobuild] Docker image
run: |
set -eux
docker build -t synobuild .
- uses: actions/cache/restore@v4 # https://github.com/actions/cache
with:
path: toolkit_tarballs/base_env-*
key: synology_toolkit_tarballs_DSM${{ env.DSM_VERSION }}_base_env
- uses: actions/cache/restore@v4 # https://github.com/actions/cache
with:
path: toolkit_tarballs/ds.*
key: synology_toolkit_tarballs_DSM${{ env.DSM_VERSION }}_${{ matrix.PACKAGE_ARCH }}
- name: Download Synology Toolkit tarballs
run: |
set -eux
mkdir -p toolkit_tarballs
pushd toolkit_tarballs/
archive_base_url="https://global.download.synology.com/download/ToolChain/toolkit/$DSM_VERSION"
archive=ds.${{ matrix.PACKAGE_ARCH }}-$DSM_VERSION.dev.txz
[[ -f $archive ]] || curl -sSf "$SYNO_TOOLKIT_BASE_URL/$DSM_VERSION/${{ matrix.PACKAGE_ARCH }}/$archive" -o $archive
archive=ds.${{ matrix.PACKAGE_ARCH }}-$DSM_VERSION.env.txz
[[ -f $archive ]] || curl -sSf "$SYNO_TOOLKIT_BASE_URL/$DSM_VERSION/${{ matrix.PACKAGE_ARCH }}/$archive" -o $archive
popd
- name: Build SPK files
run: |
set -eux
mkdir artifacts
docker run --rm --privileged \
--env PACKAGE_ARCH=${{ matrix.PACKAGE_ARCH }} \
--env DSM_VER=${DSM_VERSION} \
-v $(pwd)/artifacts:/result_spk \
-v $(pwd)/toolkit_tarballs:/toolkit_tarballs \
synobuild
ls -l artifacts
ls -l artifacts/*
for spk in artifacts/*/*.spk; do
sudo mv "$spk" "${spk%.spk}_DSM${DSM_VERSION}.spk"
done
- name: Upload SPKs
if: github.ref_name == 'main'
uses: actions/upload-artifact@v4 # https://github.com/actions/upload-artifact
with:
name: artifacts-${{ matrix.PACKAGE_ARCH }}
path: artifacts/**
###########################################################
publish-release:
###########################################################
runs-on: ubuntu-latest
needs:
- build-spks
if: github.ref_name == 'main'
concurrency: publish-latest-release # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idconcurrency
steps:
- name: Git checkout
# only required by "hub release create" to prevent "fatal: Not a git repository"
uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: Download build artifacts
uses: actions/download-artifact@v4
- name: Set effective DSM version
run: |
set -eux
if [[ -n "${{ github.event.inputs.DSM_VERSION }}" ]]; then
echo "DSM_VERSION=${{ github.event.inputs.DSM_VERSION }}" >> $GITHUB_ENV
fi
- name: Set effective WireGuard version
run: |
set -eux
spks=($(ls artifacts-*/WireGuard-*/*.spk))
[[ ${spks[0]} =~ ([0-9.]+) ]] && echo "${BASH_REMATCH[1]}"
echo "WG_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
- name: "Delete previous release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eux
api_base_url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
release_name=WireGuard-${WG_VERSION}-DSM${DSM_VERSION}
# https://hub.github.com/hub-release.1.html
hub release delete "${release_name}" || true
# delete git tag
tag_url="$api_base_url/git/refs/tags/${release_name}"
if curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsLo /dev/null --head "$tag_url"; then
echo "Deleting tag [$tag_url]..."
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$tag_url"
fi
- name: "Create release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eux
release_name=WireGuard-${WG_VERSION}-DSM${DSM_VERSION}
# https://cli.github.com/manual/gh_release_create
echo "
${release_name}
**Use at your own risk. We are not responsible if this breaks your NAS. Realistically it should not result in data loss, but it could render your NAS inaccessible if something goes wrong.**
**Especially if you are not comfortable with removing the hard drives from your NAS and manually recovering the data, this is not for you.**
See https://kb.synology.com/en-uk/DSM/tutorial/What_kind_of_CPU_does_my_NAS_have to find the right architecture of your NAS
" | GH_DEBUG=1 gh release create "$release_name" \
--latest \
--notes-file - \
--target "${{ github.sha }}" \
$(ls artifacts-*/WireGuard-*/*.spk)
- name: "Delete intermediate build artifacts"
uses: geekyeggo/delete-artifact@v5 # https://github.com/GeekyEggo/delete-artifact/
with:
name: "*"
failOnError: false