-
-
Notifications
You must be signed in to change notification settings - Fork 19
289 lines (253 loc) · 10.2 KB
/
test-pr.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
281
282
283
284
285
286
287
288
289
name: Test PR
# FIXME: Can we not build either job if stuff has been unchanged since last commit for that job?
# FIXME: Use branch name for tagging docker build
on:
pull_request:
branches:
- main
paths:
- acarshub-typescript/**
- Dockerfile.acarshub
- Dockerfile.acarshub-nextgen
- rootfs/**
- .github/workflows/test-pr.yml
- version-nextgen
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Pull koalaman/shellcheck:stable Image
run: docker pull koalaman/shellcheck:stable
- name: Run Shellcheck against shell scripts
run: |
find . -type f -exec grep -m1 -l -E '^#!.*sh.*' {} \; | grep -v -E '\/(.git\/|\S+.MD|\S+.md|retired_scripts\/|acarshub-typescript\/node_modules\/)'
docker run --rm -i -v "$PWD:/mnt" koalaman/shellcheck:stable $(find . -type f -exec grep -m1 -l -E '^#!.*sh.*' {} \; | grep -v -E '\/(.git\/|\S+.MD|\S+.md|retired_scripts\/|acarshub-typescript\/node_modules\/)')
# docker run --rm -i -v "$PWD:/mnt" koalaman/shellcheck:stable $(find . -type f -exec grep -m1 -l -E '^#!.*execline.*' {} \; | grep -v '/.git/')
markdownlint:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Pull markdownlint/markdownlint:latest Image
run: docker pull markdownlint/markdownlint:latest
- name: Run markdownlint against *.md files
run: docker run --rm -i -v "$(pwd)":/workdir --workdir /workdir markdownlint/markdownlint:latest -r ~MD013,~MD007 $(find . -type f -iname '*.md' | grep -v '/.git/')
flake8:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y rrdtool librrd-dev
python -m pip install --upgrade pip
pip install flake8 pytest wheel
pip install -r $GITHUB_WORKSPACE/rootfs/webapp/requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 --extend-ignore=W503,W504,E501
acarshub-typescript:
runs-on: ubuntu-latest
needs: [hadolint, shellcheck, flake8]
steps:
# Check out our code
- name: Checkout
uses: actions/[email protected]
# Get version tag
# git log -1 : get the latest commit
# --format="%ct" : committer date, UNIX timestamp
# Then using `date` to format to YYYYMMDD format
- name: Get the version tag
run: |
echo "VERSION=$(sed '1!d' ./version-nextgen)" >> $GITHUB_ENV
# Show version tag
- name: Show version tag
run: |
echo "ACARS Hub Version: ${{ env.VERSION }}"
- name: Build ACARSHub typescript test
working-directory: ./acarshub-typescript
run: |
set -xe
npm install
sed -i 's/Pre-Release/ACARS Hub NextGen Pre-Release: ${{ env.VERSION }} Build ${{ github.run_number }}/' ./src/helpers/menu.ts
npm run build
mkdir -p ./webapp/static/images
mkdir -p ./webapp/static/js
mkdir -p ./webapp/static/sounds
mkdir -p ./webapp/templates
cp -r ./dist/static/images ./webapp/static/
cp -r ./dist/static/sounds ./webapp/static/
cp -r ./dist/static/js ./webapp/static/
mv ./dist/static/index.html ./webapp/templates/
tar cvfz webapp.tar.gz ./webapp
cp webapp.tar.gz ../webapp.tar.gz
- name: Save webapp.tar.gz
uses: actions/upload-artifact@v3
with:
name: webapp
path: |
./webapp.tar.gz
hadolint:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Pull hadolint/hadolint:latest Image
run: docker pull hadolint/hadolint:latest
- name: Run hadolint against Dockerfiles
run: docker run --rm -i -v "$PWD":/workdir --workdir /workdir --entrypoint hadolint hadolint/hadolint $(find . -type f -iname "Dockerfile*")
deploy_ghcr_nextgen_test:
name: Deploy ACARS Hub Next Gen Base Image
runs-on: ubuntu-latest
needs: [hadolint, shellcheck, flake8]
steps:
# Check out our code
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen
.github/workflows/test-pr.yml
rootfs/webapp/requirements.txt
- name: Login to ghcr.io
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Get metadata from repo
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Set up QEMU for multi-arch builds
- name: Set up QEMU
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-qemu-action@v2
# Set up buildx for multi platform builds
- name: Set up Docker Buildx
id: buildx
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v2
# Build & Push Dockerfile (only push if this action was NOT triggered by a PR)
- name: Build & Push ghcr.io/sdr-enthusiasts/docker-acarshub:nextgen-test
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile.nextgen
no-cache: true
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64
push: true
tags: ghcr.io/sdr-enthusiasts/docker-acarshub:nextgen-test
labels: ${{ steps.meta.outputs.labels }}
deploy_ghcr_latest_test:
name: Deploy test to GHCR
runs-on: ubuntu-latest
needs:
- acarshub-typescript
- deploy_ghcr_nextgen_test
steps:
# Check out our code
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen
Dockerfile.acarshub
acarshub-typescript/**
rootfs/**
.github/workflows/test-pr.yml
version
- name: Get status of next file
id: changed-file-nextgen
uses: tj-actions/[email protected]
with:
files: |
Dockerfile.nextgen
- name: Download webapp
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: actions/download-artifact@v3
with:
name: webapp
- name: Get version
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "VERSION=$(sed '1!d' ./version-nextgen)" >> $GITHUB_ENV
# Show version tag
- name: Show version tag
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "ACARS Hub Version: ${{ env.VERSION }}"
echo "ACARS Hub Build: ${{ github.run_number }}"
- name: Create ACARS Hub Version file
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "${{ env.VERSION }} Build ${{ github.run_number }}" > ./rootfs/version
- name: Create version file
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
rm ./rootfs/version
echo "${{ env.VERSION }} Build ${{ github.run_number }}" >> ./rootfs/acarshub-version
- name: Login to ghcr.io
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Get metadata from repo
- name: Extract metadata (tags, labels) for Docker
id: meta
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Set up QEMU for multi-arch builds
- name: Set up QEMU
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-qemu-action@v2
# Set up buildx for multi platform builds
- name: Set up Docker Buildx
id: buildx
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v2
- name: Patch Dockerfile if Nextgen was built for this branch
if: steps.changed-file-nextgen.outputs.any_changed == 'true'
run: sed -i "s/^FROM ghcr.io\/sdr-enthusiasts\/docker-acarshub:nextgen/FROM ghcr.io\/sdr-enthusiasts\/docker-acarshub:nextgen-test/g" Dockerfile.acarshub
# Build & Push Dockerfile (only push if this action was NOT triggered by a PR)
- name: Build & Push ghcr.io/sdr-enthusiasts/docker-acarshub:test
if: steps.changed-files-specific.outputs.any_changed == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile.acarshub
no-cache: true
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64
push: true
tags: ghcr.io/sdr-enthusiasts/docker-acarshub:test
#tags: ghcr.io/sdr-enthusiasts/docker-acarshub:test-${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
labels: ${{ steps.meta.outputs.labels }}