-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (166 loc) · 5.56 KB
/
build-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
name: Build and Test & publish
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.repository }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Setup dependencies
run: make setup-backend env
- name: Generate code from spec
run: make generate-backend
- name: Run go vet
run: go vet ./...
- name: Run backend tests
run: make test-backend-cov
- uses: actions/upload-artifact@v4
with:
name: backend-reports
path: reports
frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: ./web/app/.nvmrc
cache: yarn
cache-dependency-path: '**/yarn.lock'
- name: Setup dependencies
run: make setup-frontend env
- name: Generate code from spec
run: make generate-frontend
- name: Run frontend tests
run: make test-frontend
- uses: actions/upload-artifact@v4
with:
name: frontend-reports
path: reports
docker:
runs-on: ubuntu-latest
needs:
- frontend
- backend
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
sonar:
runs-on: ubuntu-latest
needs:
- publish
if: ${{ always() && (needs.publish.result == 'skipped' || needs.publish.result == 'success') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: frontend-reports
path: reports
- uses: actions/download-artifact@v4
with:
name: backend-reports
path: reports
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
publish:
needs:
- docker
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v5
with:
git-user-name: github-actions
git-user-email: [email protected]
fallback-version: 0.0.0
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-commit: true
version-file: web/app/package.json
git-push: false
- name: Update version field in OAPI spec file
if: ${{ steps.changelog.outputs.skipped == 'false' }}
uses: mikefarah/[email protected]
with:
cmd: yq -i '.info.version = "${{ steps.changelog.outputs.version }}"' 'api/openapi.yaml'
- name: Update version field of sonar-project.properties
if: ${{ steps.changelog.outputs.skipped == 'false' }}
run: sed -i "s/sonar.projectVersion=.*/sonar.projectVersion=${{ steps.changelog.outputs.version }}/" "sonar-project.properties"
- name: Commit release
if: ${{ steps.changelog.outputs.skipped == 'false' }}
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add .
git commit -m "chore(release): ${{ steps.changelog.outputs.tag }} [skip ci]"
- name: Extract metadata (tags, labels) for Docker
id: meta
if: ${{ steps.changelog.outputs.skipped == 'false' }}
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=semver,pattern={{version}},value=${{ steps.changelog.outputs.tag }}
- name: Build and push Docker image
if: ${{ steps.changelog.outputs.skipped == 'false' }}
uses: docker/build-push-action@v6
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Push changes
if: ${{ steps.changelog.outputs.skipped == 'false' }}
run: |
git push origin main --follow-tags
- name: Create Release
if: ${{ steps.changelog.outputs.skipped == 'false' }}
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: false
name: ${{ steps.changelog.outputs.tag }}
tag: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}
token: ${{ github.token }}