-
Notifications
You must be signed in to change notification settings - Fork 4
230 lines (207 loc) · 6.76 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
229
name: CI
on:
push:
branches:
- '**'
tags:
- 'v*.*.*'
pull_request:
branches:
- '**'
jobs:
lint:
name: Linter
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.10.7
- name: Setup dependencies
run: pip install -r requirements.txt
- name: Run linter
run: pylint ./kubedeployer ./tests
unit-tests:
name: Run unit tests
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Build docker image
run: docker build -t deployer-unit-tests --target tests .
- name: Run unit tests
run: docker run --rm -v $PWD:/srv -i deployer-unit-tests pytest /srv/tests/unit/
integration-tests:
name: Run integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Run integration tests
run: |
chmod +x scripts/run_tests.sh
./scripts/run_tests.sh --rm
create-release:
name: Create release
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests ]
steps:
- name: Build changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
configurationJson: |
{
"template": "#{{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n#{{UNCATEGORIZED}}\n</details>",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 🔧 Refactoring",
"labels": ["refactor"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
},
{
"title": "## 💬 Other",
"labels": ["other"]
}
]
}
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
body: ${{ steps.build_changelog.outputs.changelog }}
publish-to-test-pypi:
name: publish to test pypi
permissions:
contents: read
needs: [ create-release ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
e2e-tests:
name: run e2e tests
needs: [ publish-to-test-pypi ]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: itlabsio/kubedeployer
- id: get_version
uses: battila7/get-version-action@v2
- name: build
env:
LIB_VERSION: ${{ steps.get_version.outputs.version-without-v }}
run: |
chmod +x scripts/run_e2e_tests.sh
./scripts/run_e2e_tests.sh -v ${LIB_VERSION}
publish-to-pypi:
name: publish to pypi
permissions:
contents: read
needs: [ lint, unit-tests, integration-tests, e2e-tests ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: python3 -m pip install --upgrade build && python3 -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
push-to-registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests, publish-to-pypi, e2e-tests ]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: itlabsio/kubedeployer
- id: get_version
uses: battila7/get-version-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
target: release
build-args: |
LIB_VERSION=${{ steps.get_version.outputs.version-without-v }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
trigger-pipeline-by-main:
name: Trigger Gitlab pipeline by main
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: [lint, unit-tests, integration-tests]
steps:
- name: Run pipeline
env:
URL: ${{ secrets.GITLAB_URL }}
TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
curl -v --request POST --fail --header "PRIVATE-TOKEN: ${TOKEN}" --header "Content-Type: application/json" --data '{"ref": "master", "variables": [{"key": "FROM_GITHUB", "value": "YES"}]}' ${URL}
trigger-pipeline-by-tag:
name: Trigger Gitlab pipeline by tag
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
needs: [ lint, unit-tests, integration-tests ]
steps:
- id: get_version
uses: battila7/get-version-action@v2
- name: Run pipeline
env:
URL: ${{ secrets.GITLAB_URL }}
TOKEN: ${{ secrets.GITLAB_TOKEN }}
LIB_VERSION: ${{ steps.get_version.outputs.version-without-v }}
run: |
curl -v --request POST --fail --header "PRIVATE-TOKEN: ${TOKEN}" --header "Content-Type: application/json" --data '{"ref": "master", "variables": [{"key": "LIB_VERSION", "value": "'$LIB_VERSION'"}]}' ${URL}