-
Notifications
You must be signed in to change notification settings - Fork 42
195 lines (162 loc) · 5.55 KB
/
build-and-test.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
name: Build and Test
on: [pull_request]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SYSL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SYSL_PLANTUML: http://www.plantuml.com/plantuml
GOPROXY: ${{ vars.GOPROXY }}
NPM_CONFIG_REGISTRY: ${{ vars.NPM_CONFIG_REGISTRY }}
DOCKER_BUILD_ARGS: ${{ vars.DOCKER_BUILD_ARGS }}
jobs:
build-and-test:
name: Build and Test
strategy:
matrix:
os: ${{ vars.BUILD_AND_TEST_OS_MATRIX && fromJSON(vars.BUILD_AND_TEST_OS_MATRIX) || fromJSON('[ "ubuntu-latest", "macOS-latest", "windows-latest" ]') }}
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
cache: false
- name: Set up Node
if: runner.os != 'Windows'
uses: actions/setup-node@v4
with:
node-version: 18
- uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/go/bin
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache-
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Needed to get the head of the branch for pull request events
fetch-depth: 0
- name: Ensure no tests are using Jest's 'test.only()'
if: runner.os == 'Linux'
run: find ts/src -type f -name '*.test.ts' | (! xargs grep 'test\.only\(')
- name: Generate intermediate files
run: make generate
- name: Run unit tests
if: runner.os != 'Windows'
run: make test
- name: Run unit tests (Windows)
if: runner.os == 'Windows'
run: .\scripts\test-with-coverage-windows.bat
- name: Set GOVERSION environment variable
run: echo "GOVERSION=$(go version | awk '{print $3, $4;}')" >> $GITHUB_ENV
- name: Build sysl binary
if: runner.os != 'Windows'
run: make build
# According to https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
# Ubuntu: sysl_linux_amd64:
# macOS Catalina: sysl_darwin_amd64
- name: Install sysl
if: runner.os != 'Windows'
run: |
mkdir bin && \
cp dist/sysl bin/sysl
- name: Test installed
if: runner.os != 'Windows'
run: ./scripts/test-gosysl.sh
env:
GOPATH: .
- name: Build sysl binary (Windows)
if: runner.os == 'Windows'
run: make build-windows
# sysl_windows_amd64: according to https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
# Windows Server 2019 supports 64-bit applications
- name: Install sysl (Windows)
if: runner.os == 'Windows'
run: md .\bin; copy .\dist\sysl.exe .\bin\sysl.exe
- name: Test installed (Windows)
if: runner.os == 'Windows'
run: .\scripts\test-gosysl.bat
- name: Install TypeScript deps
if: runner.os != 'Windows'
run: |
# install yarn if needed
npm i -g yarn
# switch registry in lock file
if [ -n "${{ env.NPM_CONFIG_REGISTRY }}" ]; then
sed -i'.bak' 's#https://registry.npmjs.org#${{ env.NPM_CONFIG_REGISTRY }}#' yarn.lock
rm yarn.lock.bak
fi
yarn install --frozen-lockfile
working-directory: ts
- name: Test TypeScript
if: runner.os != 'Windows'
run: yarn test
working-directory: ts
env:
SYSL_PATH: ../bin/sysl
build-docker:
name: Builds the sysl docker image
runs-on: ${{ vars.RUNNER_UBUNTU && fromJSON(vars.RUNNER_UBUNTU) || 'ubuntu-latest' }}
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
cache: false
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate intermediate files
run: make generate
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/anzbank/sysl
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{raw}}
type=sha,prefix=,format=long
labels: |
org.opencontainers.image.url=https://sysl.io
- name: Build docker image
uses: docker/build-push-action@v6
with:
context: .
pull: true
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ env.DOCKER_BUILD_ARGS }}
Lint:
name: Lint
runs-on: ${{ vars.RUNNER_UBUNTU && fromJSON(vars.RUNNER_UBUNTU) || 'ubuntu-latest' }}
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Tidy
run: go mod tidy
- name: Generate intermediate files
run: make -B generate
- name: Run golangci-lint
run: make lint-docker
- name: Check tidy
run: make check-clean
- name: Validate goreleaser config
run: |
go run github.com/goreleaser/goreleaser/v2@v2.1.0 check -f .goreleaser.yml