-
Notifications
You must be signed in to change notification settings - Fork 17
224 lines (212 loc) · 8.08 KB
/
ci.yaml
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
name: Build and Release
on:
push:
branches:
- '**'
tags:
- '*'
jobs:
build-package:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Build Package via Docker
run: |
docker build -t kubemarine --build-arg BUILD_TYPE=package --no-cache .
CONTAINER_ID=$(docker create kubemarine)
docker cp "${CONTAINER_ID}:/opt/kubemarine/dist" dist
docker rm -v "${CONTAINER_ID}"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: package
path: ./dist
retention-days: 1
build-binary:
runs-on: ${{ matrix.target.os }}
needs: build-package
strategy:
fail-fast: false
matrix:
target:
- {os: windows-2022, arch: 'win64'}
- {os: macos-12, arch: 'macos12-x86_64'}
- {os: macos-12, arch: 'macos12-arm64'}
- {os: ubuntu-latest, arch: 'linux-x86_64'}
include:
- executable_path: './dist/kubemarine'
- target: {os: windows-2022, arch: 'win64'}
executable_path: 'dist\kubemarine.exe'
- target: {os: ubuntu-latest, arch: 'linux-x86_64'}
# It is important to build on centos7 base image as long as we support running of the executable on Centos 7
build_cmd: >
docker run -t -v $(pwd):/opt/app-root/src centos/python-38-centos7 bash -c
'python scripts/ci/build_binary.py'
- target: {os: windows-2022, arch: 'win64'}
build_cmd: python scripts/ci/build_binary.py
- target: {os: macos-12, arch: 'macos12-x86_64'}
build_cmd: python scripts/ci/build_binary.py x86_64
- target: {os: macos-12, arch: 'macos12-arm64'}
build_cmd: python scripts/ci/build_binary.py arm64
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Download Package
uses: actions/download-artifact@v3
with:
name: package
path: ./dist
# Remove the step after https://github.com/actions/setup-python/issues/713 is solved
- name: Fix broken pip installation
if: ${{ matrix.target.os == 'macos-12' }}
run: |
SITE_PACKAGES="/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages"
PIP_VERSION=$(cat $SITE_PACKAGES/pip/__init__.py | grep __version__ | sed 's/["=]//g' | awk '{print $2}')
for dist_info in $(find $SITE_PACKAGES -name 'pip-*.dist-info'); do
if [[ $(basename "$dist_info") != "pip-$PIP_VERSION.dist-info" ]]; then
echo "Removing broken pip installation $dist_info"
rm -rf $dist_info
fi
done
- name: Build
run: ${{ matrix.build_cmd }}
- name: Run Selftest
if: ${{ matrix.target.arch != 'macos12-arm64' }}
run: ${{ matrix.executable_path }} selftest
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: kubemarine-${{ matrix.target.arch }}
path: ${{ matrix.executable_path }}
retention-days: 1
test-binary:
# Currently macos-latest is macos-14-arm64, and thus binary build for macos12-arm64 can be tested on it.
runs-on: macos-latest
needs: build-binary
steps:
- name: Download Executable
uses: actions/download-artifact@v3
with:
name: kubemarine-macos12-arm64
- name: Run Selftest
run: |
chmod +x kubemarine
./kubemarine selftest
test-package:
runs-on: ${{ matrix.os }}
needs: build-package
# Testing of packages can consume some time, so it is currently decided to run them only on main branch and tags.
# Meanwhile, testing of the image with package internally is done in the separate workflow on each push.
if: ${{ startsWith(github.ref, 'refs/tags') || github.ref_name == 'main' }}
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- wheel: 'dist/*.whl'
remove_files_script: 'find . -not -path "./test*" -not -path "./examples*" -not -path "./scripts*" -delete'
- os: windows-latest
wheel: '(get-item dist\*.whl).FullName'
remove_files_script: 'Get-ChildItem -Exclude test,examples,scripts | Remove-Item -Recurse -Force'
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Keep Testing Files
run: ${{ matrix.remove_files_script }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download Package
uses: actions/download-artifact@v3
with:
name: package
path: ./dist
- name: Install Package
run: python -m pip install ${{ matrix.wheel }}
- name: Enable UTF-8 on Windows
run: echo "PYTHONIOENCODING=utf-8" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Run Tests
run: python -m unittest discover -s test/unit -t test/unit
create-release:
runs-on: ubuntu-latest
# For simpler and faster solution, release now requires only package, and it is uploaded to the release immediately.
# Binaries will be built and uploaded asynchronously.
needs: build-package
if: startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Validate and Prepare
id: prepare
run: |
VERSION=$(cat kubemarine/version)
if [[ $VERSION != "${{ github.ref_name }}" ]]; then
echo -e "\033[91mGit tag does not equal to kubemarine/version\033[0m"
exit 1
fi
BRANCH_OWNERS=$(git branch -r --contains HEAD | sed 's/^[[:space:]]*origin\/\(.*\)$/\1/' | grep "^\(main\|.*_branch\)$" || true)
if [[ -z "$BRANCH_OWNERS" || $(echo "$BRANCH_OWNERS" | wc -l) != 1 ]]; then
echo -e "\033[91mFailed to detect the only release branch containing the HEAD commit.\033[0m"
echo "Available branches:"
git branch -r --contains HEAD
exit 1
fi
echo -e "\033[0;32mTarget commitish: ${BRANCH_OWNERS}\033[0m"
echo "target_commitish=$BRANCH_OWNERS" >> $GITHUB_OUTPUT
- name: Download Package
uses: actions/download-artifact@v3
with:
name: package
path: ./dist
- name: Pack Package
run: zip -r package.zip dist
- name: Create Release
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: true
generate_release_notes: true
# The value is necessary to manage the branch after release is released.
# See patch.yaml workflow.
target_commitish: ${{ steps.prepare.outputs.target_commitish }}
files: |
package.zip
upload-binary:
runs-on: ubuntu-latest
needs: [ build-binary, test-binary, create-release ]
if: startsWith(github.ref, 'refs/tags')
strategy:
matrix:
arch: [ 'win64', 'macos12-x86_64', 'macos12-arm64', 'linux-x86_64' ]
include:
- ext: ''
- arch: 'win64'
ext: '.exe'
steps:
- name: Download Executable
uses: actions/download-artifact@v3
with:
name: kubemarine-${{ matrix.arch }}
- name: Prepare Executable
run: mv kubemarine${{ matrix.ext }} kubemarine-${{ matrix.arch }}${{ matrix.ext }}
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
with:
# Since the release already exists, the following does not change it, but only uploads the artifact.
files: |
kubemarine-${{ matrix.arch }}${{ matrix.ext }}