-
Notifications
You must be signed in to change notification settings - Fork 3
257 lines (228 loc) · 9.09 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: CICD
on:
push:
branches:
- main
- 'release-*'
pull_request:
branches: '*'
workflow_dispatch:
branches: '*'
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Check out code
uses: actions/checkout@v2
- name: Install depdendencies
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
- name: Run Linters
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make lint
unit:
name: Unit Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Check out code
uses: actions/checkout@v2
- name: Install depdendencies
run: |
go install github.com/t-yuki/gocover-cobertura@latest
# ToDo: run tests in /cmd directory
- name: Run tests
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make test
gocover-cobertura < cover.out > cobertura-coverage.xml
# ToDo: generate/merge coverage for tests in /cmd directory
- name: Generate coverage report
uses: irongut/[email protected]
with:
filename: cobertura-coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_complexity: true
indicators: false
output: both
thresholds: '50 85'
- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Upload coverage as artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: code-coverage
path: |
cover.out
cobertura-coverage.xml
code-coverage-results.md
retention-days: 5
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Get the version (non-release branch)
if: ${{ !startsWith(github.ref, 'refs/heads/release-') }}
run: |
export BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}})
export BUILD_VERSION=$(date +'%Y%m%d%H%M')-$BRANCH_NAME
echo $BUILD_VERSION > VERSION
echo $BRANCH_NAME > BRANCH
- name: Get the version (release branch)
if: ${{ startsWith(github.ref, 'refs/heads/release-') }}
run: |
export BASE_VERSION=$(cat version.txt)
export VERSION=$BASE_VERSION-$(date +'%Y%m%d%H%M')
echo $VERSION > VERSION
- name: Build Images
run: |
export VERSION=$(cat VERSION)
echo $VERSION
make docker-build
- name: Push to DockerHub
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
export VERSION=$(cat VERSION)
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
make docker-push
- name: Build Install YAMLs
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
run: |
export VERSION=$(cat VERSION)
make release
- name: Build default-image manifest file
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
run: |
export VERSION=$(cat VERSION)
export MANIFEST_FILENAME=default-images-$VERSION.manifest
export MANIFEST_FILEPATH=./$MANIFEST_FILENAME
echo "MANIFEST_FILEPATH=$MANIFEST_FILEPATH" >> $GITHUB_ENV
echo "MANIFEST_FILENAME=$MANIFEST_FILENAME" >> $GITHUB_ENV
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
go run scripts/create_default_images_manifest.go $MANIFEST_FILEPATH $VERSION false
else
# Currently setting the release bool to false so we don't break downstream pipelines
go run scripts/create_default_images_manifest.go $MANIFEST_FILEPATH $VERSION false
fi
cat $MANIFEST_FILEPATH
- name: Get Version
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: vars
run:
echo ::set-output name=version::$(cat VERSION)
- name: Create Release
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_VERSION: "${{ steps.vars.outputs.version }}"
with:
tag_name: ${{ env.TAG_VERSION }}
release_name: Release ${{ env.TAG_VERSION }}
draft: false
prerelease: false
- name: Upload astraconnector yaml
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: upload-astraconnector-yaml
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_PATH: "./build/astra_v1_astraconnector.yaml"
ASSET_NAME: "astra_v1_astraconnector.yaml"
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.FILE_PATH }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: text/yaml
- name: Upload default-image manifest
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: upload-manifest
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_PATH: ${{ env.MANIFEST_FILEPATH }}
ASSET_NAME: ${{ env.MANIFEST_FILENAME }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.FILE_PATH }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: text/plain
- name: Upload astraconnector_operator.yaml
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: upload-astraconnector-operator-yaml
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_PATH: "./build/astraconnector_operator.yaml"
ASSET_NAME: "astraconnector_operator.yaml"
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.FILE_PATH }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: text/yaml
- name: Set astra-unified-installer.sh default versions
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
run: |
export VERSION=$(cat VERSION)
cp ./unified-installer/astra-unified-installer.sh ./build/astra-unified-installer.sh
sed -i "s/readonly __DEFAULT_CONNECTOR_OPERATOR_IMAGE_TAG=\"\"/readonly __DEFAULT_CONNECTOR_OPERATOR_IMAGE_TAG=\"$VERSION\"/g" ./build/astra-unified-installer.sh
sed -i "s/readonly __GIT_REF_CONNECTOR_OPERATOR=\"main\"/readonly __GIT_REF_CONNECTOR_OPERATOR=\"$VERSION\"/g" ./build/astra-unified-installer.sh
- name: Upload astra-unified-installer.sh
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: upload-install-script
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_PATH: "./build/astra-unified-installer.sh"
ASSET_NAME: "astra-unified-installer.sh"
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.FILE_PATH }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: application/x-sh
- name: Upload example env file
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') }}
id: upload-example-install-env
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILE_PATH: "./unified-installer/install-example-config.env"
ASSET_NAME: "install-example-config.env"
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.FILE_PATH }}
asset_name: ${{ env.ASSET_NAME }}
asset_content_type: text/plain