-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (185 loc) · 6.31 KB
/
build-vue.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
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build
on:
push:
paths:
- '**.vue'
- '**.ts'
- '**.tsx'
- '!**.test.ts'
- '**.js'
- '**.jsx'
- '**.json'
- '**.mscz'
- '**.conf'
- '**.go'
- 'Dockerfile'
- '*.Dockerfile'
- '.Dockerignore'
- '**/build-vue.yml'
pull_request:
branches: [ main, dev ]
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: fysiksektionen/sangbok-html
jobs:
##
## Build zip file to export
##
build:
runs-on: ubuntu-latest
name: Build vue
needs: sheet-music
strategy:
fail-fast: false
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install packages
run: npm ci
- name: Fetch sheet music artifacts
uses: actions/download-artifact@v3
with:
name: music-svgs
path: public/msvg
- name: Unpack sheet music artifacts
working-directory: public/msvg
run: mv svgs.json ../../src/assets/msvgs.json
- name: build
run: npx vite build
- name: Archive production artifacts
uses: actions/upload-artifact@v3
if: ${{ matrix.node-version == '20.x' }}
with:
name: dist-node-${{ matrix.node-version }}
path: |
dist
##
## Sheet music generation
##
sheet-music:
runs-on: ubuntu-latest
name: Generate sheet music resources
steps:
- uses: actions/checkout@v3
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'npm'
- name: Install svgo
run: npm install -g svgo
- name: Install MuseScore 3
run: sudo apt-get update && sudo apt-get install musescore3
- name: Unpack cached svg:s
run: rm -rf svg && tar -xJf svg.tar.lzma
working-directory: ./music
- name: Convert mscz to compressed svg:s (from cache)
working-directory: ./music
run: ./convert.sh --compress --no-move
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/actions-dev' }}
- name: Convert mscz to compressed svg:s (from scratch)
working-directory: ./music
run: ./convert.sh --compress --no-move --force-on-change
if: ${{ github.ref == 'refs/heads/main' }}
- name: Convert mscz to compressed svg:s (workflow testing)
working-directory: ./music
run: ./convert.sh --compress --no-move --force-cache-regeneration
if: ${{ github.ref == 'refs/heads/actions-dev' }}
- name: Compute hashes
working-directory: ./music
run: sha1sum mscz/*.mscz
- name: Perpare for export
working-directory: ./music
run: cp svgs.json svg
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: music-svgs
path: music/svg
- name: Push new cache to repo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
git add music/svg.tar.lzma music/mscz.sha1 music/svgs.json
git commit -m "Automatic msvg cache update ($(head -c 8 music/mscz.sha1))" --author "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" | exit 0
git push
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/actions-dev' }}
# TODO: git commit exit codes are overridden above. This is most commonly done to prevent the workflow from crashing due to empty commits. It may, however, be a source of bugs if git commit crashes for some other reason.
##
## Docker build
##
docker:
runs-on: ubuntu-latest
name: Build Docker containers
needs: sheet-music
strategy:
fail-fast: false
matrix:
variant: [default, gz, gz-br]
include:
- variant: default
compression: semi-redundant gzip/brotli
server: nginx
- variant: gz
suffix: -nginx-gz
compression: gzip
server: nginx
- variant: gz-br
suffix: -nginx-gz-br
compression: redundant gzip/brotli
server: nginx
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Fetch sheet music artifacts
uses: actions/download-artifact@v3
with:
name: music-svgs
path: public/msvg
- name: Unpack sheet music artifacts
working-directory: public/msvg
run: mv svgs.json ../../src/assets/msvgs.json
# Login against a Docker registry except on PR(https://github.com/docker/login-action)
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker (https://github.com/docker/metadata-action)
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=edge,branch=dev
type=ref,event=branch
flavor: |
suffix=${{ matrix.suffix }}
- name: Build and push Docker image (${{ matrix.server }} with ${{ matrix.compression }} precompression)
uses: docker/build-push-action@v5
with:
file: docker/${{ matrix.server }}/${{ matrix.variant }}.Dockerfile
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}