-
Notifications
You must be signed in to change notification settings - Fork 2
194 lines (185 loc) · 6.36 KB
/
cicd.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
name: Publish to Dockerhub and GitHub packages
on: push # [push, pull_request]
jobs:
benchmark:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: benchmarks the go code
run: make benchmark
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: tests the code
run: make test
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#example-printing-context-information-to-the-log-file @ 2020 07 19
context_information:
needs: [benchmark, test]
runs-on: ubuntu-20.04
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
# https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables @ 2020 07 19
context_env:
needs: [benchmark, test]
runs-on: ubuntu-20.04
steps:
- name: Dump GitHub HOME
env:
GHHOME: ${HOME}
run: echo "$GHHOME"
- name: Dump GITHUB_WORKFLOW
env:
GITHUB_WORKFLOW: ${GITHUB_WORKFLOW}
run: echo "$GITHUB_WORKFLOW"
- name: Dump GITHUB_RUN_ID
env:
GITHUB_RUN_ID: ${GITHUB_RUN_ID}
run: echo "$GITHUB_RUN_ID"
- name: Dump GITHUB_RUN_NUMBER
env:
GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER}
run: echo "$GITHUB_RUN_NUMBER"
- name: Dump GITHUB_ACTION
env:
GITHUB_RUN_NUMBER: ${GITHUB_ACTION}
run: echo "$GITHUB_ACTION"
- name: Dump GITHUB_ACTIONS
env:
GITHUB_RUN_NUMBER: ${GITHUB_ACTIONS}
run: echo "$GITHUB_ACTIONS"
- name: Dump GITHUB_ACTOR
env:
GITHUB_RUN_NUMBER: ${GITHUB_ACTOR}
run: echo "$GITHUB_ACTOR"
- name: Dump GITHUB_REPOSITORY
env:
GITHUB_RUN_NUMBER: ${GITHUB_REPOSITORY}
run: echo "$GITHUB_REPOSITORY"
- name: Dump GITHUB_REPOSITORY
env:
GITHUB_RUN_NUMBER: ${GITHUB_REPOSITORY}
run: echo "$GITHUB_REPOSITORY"
- name: Dump GITHUB_EVENT_PATH
env:
GITHUB_RUN_NUMBER: ${GITHUB_EVENT_PATH}
run: echo "$GITHUB_EVENT_PATH"
- name: Dump GITHUB_WORKSPACE
env:
GITHUB_RUN_NUMBER: ${GITHUB_WORKSPACE}
run: echo "$GITHUB_WORKSPACE"
- name: Dump GITHUB_SHA
env:
GITHUB_RUN_NUMBER: ${GITHUB_SHA}
run: echo "$GITHUB_SHA"
- name: Dump GITHUB_REF
env:
GITHUB_RUN_NUMBER: ${GITHUB_REF}
run: echo "$GITHUB_REF"
- name: Dump GITHUB_HEAD_REF
env:
GITHUB_RUN_NUMBER: ${GITHUB_HEAD_REF}
run: echo "$GITHUB_HEAD_REF"
- name: Dump GITHUB_BASE_REF
env:
GITHUB_RUN_NUMBER: ${GITHUB_BASE_REF}
run: echo "$GITHUB_BASE_REF"
- name: Dump GITHUB_SERVER_URL
env:
GITHUB_RUN_NUMBER: ${GITHUB_SERVER_URL}
run: echo "$GITHUB_SERVER_URL"
- name: Dump GITHUB_API_URL
env:
GITHUB_RUN_NUMBER: ${GITHUB_API_URL}
run: echo "$GITHUB_API_URL"
- name: Dump GITHUB_GRAPHQL_URL
env:
GITHUB_RUN_NUMBER: ${GITHUB_GRAPHQL_URL}
run: echo "$GITHUB_GRAPHQL_URL"
push2dockerhub_if_linux:
needs: [benchmark, test]
strategy:
fail-fast: false
matrix:
os: [macOS-10.15, ubuntu-20.04]
goos: [linux, darwin]
exclude:
- os: macOS-10.15
goos: linux
- os: ubuntu-20.04
goos: darwin
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: builds the binary
run: CGO_ENABLED=0 GOOS=${{ matrix.goos }} go build -a -installsuffix cgo -ldflags '-w -extldflags "-static"' -o hello_world${{ matrix.os }}${{ matrix.goos }} .
- uses: actions/checkout@master
- name: if linux build docker image and docker hub login as well as push
if: matrix.os == 'ubuntu-20.04'
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
# inspired by https://gist.github.com/jonico/e18127b487d198606e31aac669262af8 @ 2019 08 19
d=$(date +%Y-%m-%d)
tag=$d-${{ matrix.os }}-${{ github.sha }}
docker build -t lotharschulz/hello-github-actions:$tag .
echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin
docker push lotharschulz/hello-github-actions:$tag
push_to_docker_pkg:
needs: [benchmark, test]
name: build-push-action via docker cli
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build and Push
env:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
echo ${DOCKER_PASSWORD} | docker login https://docker.pkg.github.com -u ${DOCKER_USERNAME} --password-stdin
d=$(date +%Y-%m-%d--%H-%M-%S--%N)
tag=$d-${{ github.sha }}
IMAGE_AND_TAG=docker.pkg.github.com/lotharschulz/hello-github-actions/hello-github-actions-pkg:$tag
docker build -t $IMAGE_AND_TAG .
docker push $IMAGE_AND_TAG
ghcr_push:
needs: [benchmark, test]
name: ghcr push
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build and Push
env:
GCR_USERNAME: ${{ github.actor }}
GCR_PASSWORD: ${{ secrets.CR_PAT }}
run: |
echo "${GCR_PASSWORD}" | docker login https://ghcr.io -u ${GCR_USERNAME} --password-stdin
d=$(date +%Y-%m-%d--%H-%M-%S--%N)
tag=$d-${{ github.sha }}
IMAGE_AND_TAG=ghcr.io/lotharschulz/hello-github-actions/hello-github-actions-ghcr:$tag
docker build -t $IMAGE_AND_TAG .
docker push $IMAGE_AND_TAG