-
Notifications
You must be signed in to change notification settings - Fork 3
332 lines (292 loc) · 12.3 KB
/
build_release.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
name: Test, Build, Package the Phase CLI
on:
pull_request:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
jobs:
pytest:
name: Run Tests
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.11]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: pip install -r dev-requirements.txt
- run: pip install pytest
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
- run: pytest tests/*.py
extract_version:
name: Extract Version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Extract version
run: |
echo "PHASE_CLI_VERSION=$(grep -oP '(?<=__version__ = ")[^"]*' phase_cli/utils/const.py)" >> $GITHUB_ENV
echo "${{ env.PHASE_CLI_VERSION }}" > ./PHASE_CLI_VERSION.txt
- uses: actions/upload-artifact@v4
with:
name: phase-version
path: ./PHASE_CLI_VERSION.txt
build:
name: Build CLI
runs-on: ${{ matrix.os }}
needs: [pytest, extract_version]
strategy:
matrix:
# ubuntu-20.04 - context: https://github.com/phasehq/cli/issues/94
# macos-13 darwin-amd64 builds (intel)
# macos-14 darwin-arm64 builds (apple silicon)
# context: https://github.com/actions/runner-images?tab=readme-ov-file#available-images
os: [ubuntu-20.04, windows-2022, macos-13, macos-14]
python-version: [3.11]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: pip install -r requirements.txt
- run: pip install pyinstaller
- run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- name: Print GLIBC version
if: matrix.os == 'ubuntu-20.04'
run: ldd --version
# Set LC_ALL based on the runner OS for Linux and macOS
- name: Set LC_ALL for Linux and macOS
run: export LC_ALL=C.UTF-8
if: runner.os != 'Windows'
shell: bash
# Set LC_ALL for Windows
- name: Set LC_ALL for Windows
run: echo "LC_ALL=C.UTF-8" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
if: runner.os == 'Windows'
shell: pwsh
# Download the version file
- uses: actions/download-artifact@v4
with:
name: phase-version
# Set the version environment variable with the correct value
- name: Set VERSION
run: |
PHASE_CLI_VERSION=$(cat phase-version/PHASE_CLI_VERSION.txt)
echo "PHASE_CLI_VERSION=$PHASE_CLI_VERSION" >> $GITHUB_ENV
- name: Debug PHASE_CLI_VERSION
run: |
echo "PHASE_CLI_VERSION is: $PHASE_CLI_VERSION"
shell: bash
# Build DEB and RPM packages for Linux
- run: |
sudo apt-get update
sudo apt-get install -y ruby-dev rubygems build-essential
sudo gem install --no-document fpm
fpm -s dir -t deb -n phase -v $PHASE_CLI_VERSION dist/phase/=usr/bin/
fpm -s dir -t rpm -n phase -v $PHASE_CLI_VERSION dist/phase/=usr/bin/
if: matrix.os == 'ubuntu-20.04'
shell: bash
# Upload DEB and RPM packages
- uses: actions/upload-artifact@v4
with:
name: phase-deb
path: "*.deb"
if: matrix.os == 'ubuntu-20.04'
- uses: actions/upload-artifact@v4
with:
name: phase-rpm
path: "*.rpm"
if: matrix.os == 'ubuntu-20.04'
- name: Set artifact name
run: |
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
echo "ARTIFACT_NAME=${{ runner.os }}-arm64-binary" >> $GITHUB_ENV
elif [[ "${{ matrix.os }}" == "macos-13" ]]; then
echo "ARTIFACT_NAME=${{ runner.os }}-amd64-binary" >> $GITHUB_ENV
else
echo "ARTIFACT_NAME=${{ runner.os }}-binary" >> $GITHUB_ENV
fi
shell: bash
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: dist/phase*
build_arm:
name: Build CLI for ARM64
runs-on: self-hosted
container:
image: python:3.11.0-bullseye
needs: [pytest, extract_version]
steps:
- uses: actions/checkout@v2
- name: Setup Environment
run: |
python --version
pip install -r requirements.txt
pip install pyinstaller
- name: Build with PyInstaller
run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- uses: actions/upload-artifact@v4
with:
name: Linux-binary-arm64
path: dist/phase*
build_apk:
name: Build CLI (alpine-latest, 3.11)
runs-on: ubuntu-20.04
needs: [pytest, extract_version]
container:
image: python:3.11-alpine
steps:
- uses: actions/checkout@v2
- run: apk add --update --no-cache python3 python3-dev build-base
- run: python3 -m ensurepip
- run: pip3 install --no-cache --upgrade pip setuptools
- run: pip install -r requirements.txt
- run: pip install pyinstaller
- run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- run: apk add alpine-sdk
- run: adduser -G abuild -g "Alpine Package Builder" -s /bin/ash -D builder
- run: mkdir /home/builder/package
- run: chown builder /home/builder/package
- run: apk add --no-cache sudo
- run: |
echo "builder ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
ls ./dist/phase
cp -r ./dist/phase/* /home/builder/package/
cp ./APKBUILD /home/builder/package
cd /home/builder/package
sudo -u builder abuild-keygen -a -i -n
sudo -u builder abuild checksum
sudo -u builder abuild -r
shell: sh
- uses: actions/upload-artifact@v4
with:
name: phase-apk
path: /home/builder/packages/builder/x86_64/*.apk
- uses: actions/upload-artifact@v4
with:
name: phase-alpine-build
path: ./dist/phase
Build_and_push_docker:
name: Build & Release - Docker
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [build, build_apk]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Download phase-version artifact
uses: actions/download-artifact@v4
with:
name: phase-version
path: phase-version
- name: Set VERSION from file
run: echo "VERSION=$(cat ./phase-version/PHASE_CLI_VERSION.txt | tr -d '\r')" >> $GITHUB_ENV
- name: Download phase-alpine-build artifact
uses: actions/download-artifact@v4
with:
name: phase-alpine-build
path: dist
- run: docker build -t phase-cli:${{ env.VERSION }} .
- name: Push to Docker Hub
run: |
echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
docker tag phase-cli:${{ env.VERSION }} phasehq/cli:${{ env.VERSION }}
docker push phasehq/cli:${{ env.VERSION }}
docker tag phase-cli:${{ env.VERSION }} phasehq/cli:latest
docker push phasehq/cli:latest
Pull_and_test_docker_image:
name: Test - CLI - Docker
needs: Build_and_push_docker
runs-on: ubuntu-20.04
steps:
- name: Download phase-version artifact
uses: actions/download-artifact@v4
with:
name: phase-version
path: phase-version
- name: Set VERSION from file
run: echo "VERSION=$(cat ./phase-version/PHASE_CLI_VERSION.txt | tr -d '\r')" >> $GITHUB_ENV
# Pull and test the versioned Docker image
- run: docker pull phasehq/cli:${{ env.VERSION }}
- run: docker run phasehq/cli:${{ env.VERSION }} phase -h
- run: docker run phasehq/cli:${{ env.VERSION }} phase -v
# Pull and test the latest Docker image
- run: docker pull phasehq/cli:latest
- run: docker run phasehq/cli:latest phase -h
- run: docker run phasehq/cli:latest phase -v
attach-assets:
name: Package assets
needs: [build, build_apk, build_arm]
runs-on: ubuntu-20.04
steps:
# Download all the artifacts from the build jobs
- name: Download all artifacts
uses: actions/download-artifact@v4
# # Debug: List the content of the current directory
# - name: Debug - List contents of artifacts directory
# run: find . -type f
# Extract version from the file
- name: Set VERSION from file
run: echo "VERSION=$(cat ./phase-version/PHASE_CLI_VERSION.txt | tr -d '\r')" >> $GITHUB_ENV
# Process assets: Rename, calculate sha256, and move them to the release directory
- name: Process assets
run: |
mkdir phase_cli_release_$VERSION
# For DEB
mv phase-deb/*.deb phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.deb
sha256sum phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.deb > phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.deb.sha256
# For RPM
mv phase-rpm/*.rpm phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.rpm
sha256sum phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.rpm > phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.rpm.sha256
# For Linux
ZIPNAME="phase_cli_linux_amd64_$VERSION.zip"
zip -r "$ZIPNAME" Linux-binary/phase/ Linux-binary/phase/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.sha256
# For Windows
ZIPNAME="phase_cli_windows_amd64_$VERSION.zip"
zip -r "$ZIPNAME" Windows-binary/phase/ Windows-binary/phase/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_windows_amd64_$VERSION.sha256
# For MacOS Intel build
ZIPNAME="phase_cli_macos_amd64_$VERSION.zip"
zip -r "$ZIPNAME" macOS-amd64-binary/phase/ macOS-binary/phase/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_macos_amd64_$VERSION.sha256
# For MacOS Apple silicon build
ZIPNAME="phase_cli_macos_arm64_$VERSION.zip"
zip -r "$ZIPNAME" macOS-arm64-binary/phase/ macOS-binary/phase/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_macos_arm64_$VERSION.sha256
# For Alpine build
ZIPNAME="phase_cli_alpine_linux_amd64_$VERSION.zip"
zip -r "$ZIPNAME" phase-alpine-build/phase phase-alpine-build/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_alpine_linux_amd64_$VERSION.sha256
# For Alpine package
mv phase-apk/*.apk phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.apk
sha256sum phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.apk > phase_cli_release_$VERSION/phase_cli_linux_amd64_$VERSION.apk.sha256
# Process assets for ARM64
- name: Process ARM64 assets
run: |
mkdir -p phase_cli_release_$VERSION/Linux-binary/phase/
mv Linux-binary-arm64/phase/* phase_cli_release_$VERSION/Linux-binary/phase/
# Adjust the ZIPNAME and paths for ARM64 binary
ZIPNAME="phase_cli_linux_arm64_$VERSION.zip"
zip -r "$ZIPNAME" phase_cli_release_$VERSION/Linux-binary/phase/ phase_cli_release_$VERSION/Linux-binary/phase/_internal
mv "$ZIPNAME" phase_cli_release_$VERSION/
sha256sum phase_cli_release_$VERSION/"$ZIPNAME" > phase_cli_release_$VERSION/phase_cli_linux_arm64_$VERSION.sha256
# Cleanup the ARM64 binary folder
rm -rf Linux-binary
# Upload the entire release directory as a single artifact
- uses: actions/upload-artifact@v4
with:
name: phase-cli-release
path: ./phase_cli_release_*/