-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (196 loc) · 7 KB
/
build.yaml
File metadata and controls
223 lines (196 loc) · 7 KB
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
name: Tests
on:
push:
branches: [master]
jobs:
#************* RUN GO TESTS ***************
goTests:
outputs:
newTag: ${{ steps.bump_tag.outputs.new_tag }}
tagMajor: ${{ steps.semver_parser.outputs.major }}
tagMinor: ${{ steps.semver_parser.outputs.minor }}
tagPatch: ${{ steps.semver_parser.outputs.patch }}
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Setup git config
run: git config --global url."https://x-oauth-basic:${{ secrets.GO_MODULES_TOKEN }}@github.com".insteadOf "https://github.com"
- name: Setup Golang
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: restore go cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-goTests-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-goTests-
- name: Test
run: go test -v ./...
- name: Bump version and push tag
id: bump_tag
uses: anothrNick/github-tag-action@1.34.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
- name: Parse semver string
id: semver_parser
uses: booxmedialtd/ws-action-parse-semver@v1
with:
input_string: "${{ steps.bump_tag.outputs.new_tag }}"
# version_extractor_regex: '\/v(.*)$'
#************* COMPILE RESULTS ***************
compile:
needs: goTests
runs-on: ubuntu-latest
strategy:
matrix:
program-name: [pollster-chat, pollster-api, pollster-results]
steps:
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Setup git config
run: git config --global url."https://x-oauth-basic:${{ secrets.GO_MODULES_TOKEN }}@github.com".insteadOf "https://github.com"
- name: Setup Golang
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: restore go cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.program-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.program-name }}-
- name: Compile executable
run: (CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .)
- name: Archive binary
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.program-name }}.binary
path: cmd/${{ matrix.program-name }}/main
retention-days: 1
#************* DOCKER FILE BUILD PUSHES***************
buildAndPush:
needs: [goTests, compile]
runs-on: ubuntu-latest
strategy:
matrix:
program-name: [twitchfix]
steps:
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Setup git config
run: git config --global url."https://x-oauth-basic:${{ secrets.GO_MODULES_TOKEN }}@github.com".insteadOf "https://github.com"
- name: Set Up Docker Build
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Login to Harbor
uses: docker/login-action@v1
with:
registry: harbor.streem.tech
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
- name: Archive api binary
uses: actions/download-artifact@v2
with:
name: ${{ matrix.program-name }}.binary
path: cmd/${{ matrix.program-name }}/main
- name: Build and push API
uses: docker/build-push-action@v2
with:
push: true
tags: |
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:test
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:${{ needs.goTests.outputs.newTag }}
context: "."
file: dockerfile
#************* DOCKER FILE BUILD PUSHES***************
pushVersionedContainers:
strategy:
matrix:
program-name: [twitchfix]
needs: [goTests]
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
token: ${{ secrets.GO_MODULES_TOKEN }}
- name: Setup git config
run: git config --global url."https://x-oauth-basic:${{ secrets.GO_MODULES_TOKEN }}@github.com".insteadOf "https://github.com"
- name: Set Up Docker Build
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Login to Harbor
uses: docker/login-action@v1
with:
registry: harbor.streem.tech
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
- name: Get Archive binary
uses: actions/download-artifact@v2
with:
name: ${{ matrix.program-name }}.binary
path: cmd/${{ matrix.program-name }}/main
- name: Build and push API
uses: docker/build-push-action@v2
with:
push: true
tags: |
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:latest
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:v${{ needs.goTests.outputs.tagMajor }}
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:v${{ needs.goTests.outputs.tagMajor }}.${{ needs.goTests.outputs.tagMinor }}
harbor.streem.tech/streemtech-pub/${{ matrix.program-name }}:v${{ needs.goTests.outputs.tagMajor }}.${{ needs.goTests.outputs.tagMinor }}.${{ needs.goTests.outputs.tagPatch }}
context: "."
file: dockerfile
#************* CLEANUP JOBS ***************
cleanup:
strategy:
matrix:
program-name: [pollster-chat, pollster-api, pollster-results]
runs-on: ubuntu-latest
needs: [pushVersionedContainers]
if: ${{ always() }}
steps:
- name: Delete Artifacts after done.
uses: geekyeggo/delete-artifact@v1
with:
name: ${{ matrix.program-name }}.binary
failOnError: false
cleanupOnFailure:
strategy:
matrix:
program-name: [twitchfix]
runs-on: ubuntu-latest
needs: [goTests, pushVersionedContainers]
if: ${{ failure() }}
steps:
- name: cleanup Github tags
uses: dev-drprasad/delete-tag-and-release@v0.1.2
with:
delete_release: false # default: false
tag_name: ${{ needs.goTests.outputs.newTag }} # tag name to delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete Artifacts after done when failed.
uses: geekyeggo/delete-artifact@v1
with:
name: ${{ matrix.program-name }}.binary
failOnError: false