This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
228 lines (207 loc) · 8.28 KB
/
CI.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
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
224
225
226
227
228
name: CI
on:
# always execute docker build when something is pushed to master or release-* branches
push:
branches:
- "master"
- "main"
- "release-*"
# in addition, execute for pull requests to those branches
pull_request:
branches:
- "master"
- "main"
- "release-*"
# Allow users to manual run the CI pipeline for a specific branch, this may
# be needed for the integration tests as they need the generated artifacts / images
workflow_dispatch: # run integration tests only when triggered manually
defaults:
run:
shell: bash
jobs:
prepare_ci_run:
name: Prepare CI Run
# Prepare CI Run looks at what has been changed in this commit/PR/... and determines which artifacts should be
# built afterwards (in other jobs that depend on this one).
runs-on: ubuntu-20.04
outputs: # declare what this job outputs (so it can be re-used for other jobs)
# build config
# metadata
GIT_SHA: ${{ steps.extract_branch.outputs.GIT_SHA }}
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
DATE: ${{ steps.get_datetime.outputs.DATE }}
TIME: ${{ steps.get_datetime.outputs.TIME }}
DATETIME: ${{ steps.get_datetime.outputs.DATETIME }}
steps:
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0 # need to checkout "all commits" for certain features to work (e.g., get all changed files)
- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v4
with:
env-file: .ci_env
- name: Extract branch name
id: extract_branch
# see https://github.com/keptn/gh-action-extract-branch-name for details
uses: keptn/gh-action-extract-branch-name@main
- name: "Get Previous tag"
id: get_previous_tag
uses: "WyriHaximus/[email protected]"
with:
fallback: "0.0.1"
- name: "Get next patch version"
id: get_next_semver_tag
uses: "WyriHaximus/[email protected]"
with:
version: ${{ steps.get_previous_tag.outputs.tag }}
- name: Get the version
id: get_version
env:
BRANCH: ${{ steps.extract_branch.outputs.BRANCH }}
BRANCH_SLUG: ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
shell: bash
run: |
# determine version
GIT_LAST_TAG=${{ steps.get_previous_tag.outputs.tag }}
GIT_NEXT_TAG=${{ steps.get_next_semver_tag.outputs.patch }}
echo "GIT_LAST_TAG=${GIT_LAST_TAG}, GIT_NEXT_TAG=${GIT_NEXT_TAG}"
if [[ "$BRANCH" == "release-"* ]]; then
# Release Branch: extract version from branch name
VERSION=${BRANCH#"release-"}
else
if [[ "$BRANCH" == "master" ]]; then
# master branch = latest
VERSION="${GIT_NEXT_TAG}-dev"
else
# Feature/Development Branch - use last tag with branch slug
VERSION="${GIT_NEXT_TAG}-dev-${BRANCH_SLUG}"
fi
fi
echo "VERSION=${VERSION}"
echo "##[set-output name=VERSION;]$(echo ${VERSION})"
- name: Get current date and time
id: get_datetime
run: |
echo "::set-output name=DATE::$(date +'%Y%m%d')"
echo "::set-output name=TIME::$(date +'%H%M')"
echo "::set-output name=DATETIME::$(date +'%Y%m%d')$(date +'%H%M')"
############################################################################
# Unit tests #
############################################################################
test:
name: Unit Tests
needs: prepare_ci_run
runs-on: ubuntu-20.04
steps:
- name: Check out repository
uses: actions/[email protected]
- name: Unit tests
uses: ./.github/actions/unit-tests
############################################################################
# Build Docker Image #
############################################################################
docker_build:
needs: [prepare_ci_run]
name: Docker Build
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
steps:
- name: Checkout Code
uses: actions/[email protected]
- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v4
with:
env-file: .ci_env
- name: Docker Build
id: docker_build
uses: keptn/gh-automation/.github/actions/[email protected]
with:
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
PUSH: ${{(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)}}
- name: Docker Build Initcontainer
id: docker_build_initcontainer
uses: keptn/gh-automation/.github/actions/[email protected]
with:
TAGS: |
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}
${{ env.DOCKER_ORGANIZATION }}/${{ env.IMAGE_INITCONTAINER }}:${{ env.VERSION }}.${{ env.DATETIME }}
BUILD_ARGS: |
version=${{ env.VERSION }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
DOCKERFILE: ${{ env.DOCKERFILE_INITCONTAINER }}
PUSH: ${{(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)}}
- id: report_docker_build_to_pr
name: Report Docker Build to PR
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
recreate: true
header: test
message: |
The following Docker Images have been built:
* ${{ fromJSON(steps.docker_build.outputs.BUILD_METADATA)['image.name'] }}
* ${{ fromJSON(steps.docker_build_initcontainer.outputs.BUILD_METADATA)['image.name'] }}
helm_chart_build:
needs: [prepare_ci_run, docker_build]
name: Build Helm Charts
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
steps:
- name: Checkout Code
uses: actions/[email protected]
- name: Load CI Environment from .ci_env
id: load_ci_env
uses: c-py/action-dotenv-to-setenv@v4
with:
env-file: .ci_env
- name: Build Helm Charts
id: build_helm_charts
uses: keptn/gh-automation/.github/actions/[email protected]
with:
VERSION: ${{ env.VERSION }}
APP_VERSION: ${{ env.VERSION }}.${{ env.DATETIME }}
CHART_NAME: ${{ env.IMAGE }}
- name: Upload Helm Chart as an artifact
id: upload_helm_chart
uses: actions/upload-artifact@v3
with:
name: helm-charts
path: installer/*.tgz
linter_build:
needs: [prepare_ci_run]
name: Build Linter
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.prepare_ci_run.outputs.VERSION }}
steps:
- name: Checkout Code
uses: actions/[email protected]
- name: Set up Go
uses: actions/[email protected]
with:
go-version-file: "go.mod"
- name: Run make
run: make build-lint
- name: Upload Linter binaries as an artifact
id: upload_helm_chart
uses: actions/upload-artifact@v3
with:
name: linter
path: bin/job-lint-*