generated from alexstojda/go-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (175 loc) · 6.16 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
179
180
181
182
183
184
185
186
name: Build and Test & publish
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version-file: go.mod
# Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
cache: true
# Used to specify the path to a dependency file - go.sum
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@v2
with:
name: backend-reports
path: reports
frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/[email protected]
with:
# File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.
node-version-file: web/app/.nvmrc
# Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.
cache: yarn
cache-dependency-path: web/app/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@v2
with:
name: frontend-reports
path: reports
docker:
runs-on: ubuntu-latest
needs:
- frontend
- backend
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: Build Docker image
uses: docker/[email protected]
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@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
ref: ${{ github.ref == 'refs/heads/main' && 'main' || '' }}
- uses: actions/download-artifact@v2
with:
name: frontend-reports
path: reports
- uses: actions/download-artifact@v2
with:
name: backend-reports
path: reports
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
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@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v3
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 --local user.name github-actions
git config --local user.email [email protected]
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/[email protected]
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 }}
# type=ref,event=branch
# type=ref,event=pr
- name: Build and push Docker image
if: ${{ steps.changelog.outputs.skipped == 'false' }}
uses: docker/[email protected]
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 }}