Skip to content

Commit 37cb53e

Browse files
authored
Optimize CI runs, by avoiding unnecessary rebuilds (#2833)
1 parent 656179a commit 37cb53e

File tree

2 files changed

+72
-203
lines changed

2 files changed

+72
-203
lines changed

.github/workflows/push.yml

Lines changed: 44 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ jobs:
5353
parallel: true
5454
flag-name: run-${{ matrix.os }}-${{ matrix.python-version }}
5555

56-
ubuntu_build_apk:
57-
name: Unit test apk [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
56+
ubuntu_build:
57+
name: Build test APP [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
5858
needs: [flake8]
5959
runs-on: ${{ matrix.runs_on }}
6060
continue-on-error: true
@@ -68,36 +68,41 @@ jobs:
6868
target: testapps-with-scipy
6969
- name: webview
7070
target: testapps-webview
71+
- name: service_library
72+
target: testapps-service_library-aar
7173
steps:
7274
- name: Checkout python-for-android
7375
uses: actions/checkout@v3
74-
# helps with GitHub runner getting out of space
75-
- name: Free disk space
76-
run: |
77-
df -h
78-
sudo swapoff -a
79-
sudo rm -f /swapfile
80-
sudo apt -y clean
81-
docker rmi $(docker image ls -aq)
82-
df -h
83-
- name: Pull docker image
84-
run: |
85-
make docker/pull
86-
- name: Build multi-arch apk Python 3 (armeabi-v7a, arm64-v8a, x86_64, x86)
87-
run: |
88-
mkdir -p apks
89-
make docker/run/make/with-artifact/apk/${{ matrix.bootstrap.target }}
90-
- name: Rename apk artifact to include the build platform name
91-
run: |
92-
mv apks/${{ env.APK_ARTIFACT_FILENAME }} apks/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
93-
- name: Upload apk artifact
94-
uses: actions/upload-artifact@v1
76+
- name: Build python-for-android docker image
77+
run: |
78+
docker build --tag=kivy/python-for-android .
79+
- name: Build multi-arch ${{ matrix.bootstrap.target }} artifact with docker
80+
run: |
81+
docker run --name p4a-latest kivy/python-for-android make ${{ matrix.bootstrap.target }}
82+
- name: Copy produced artifacts from docker container (*.apk, *.aab)
83+
if: matrix.bootstrap.name != 'service_library'
84+
run: |
85+
mkdir -p dist
86+
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/${{ env.APK_ARTIFACT_FILENAME }} dist/
87+
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/${{ env.AAB_ARTIFACT_FILENAME }} dist/
88+
- name: Copy produced artifacts from docker container (*.aar)
89+
if: matrix.bootstrap.name == 'service_library'
90+
run: |
91+
mkdir -p dist
92+
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/${{ env.AAR_ARTIFACT_FILENAME }} dist/
93+
- name: Rename artifacts to include the build platform name (*.apk, *.aab, *.aar)
94+
run: |
95+
if [ -f dist/${{ env.APK_ARTIFACT_FILENAME }} ]; then mv dist/${{ env.APK_ARTIFACT_FILENAME }} dist/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}; fi
96+
if [ -f dist/${{ env.AAB_ARTIFACT_FILENAME }} ]; then mv dist/${{ env.AAB_ARTIFACT_FILENAME }} dist/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAB_ARTIFACT_FILENAME }}; fi
97+
if [ -f dist/${{ env.AAR_ARTIFACT_FILENAME }} ]; then mv dist/${{ env.AAR_ARTIFACT_FILENAME }} dist/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAR_ARTIFACT_FILENAME }}; fi
98+
- name: Upload artifacts
99+
uses: actions/upload-artifact@v3
95100
with:
96-
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
97-
path: apks/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
101+
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-artifacts
102+
path: dist
98103

99-
macos_build_apk:
100-
name: Unit test apk [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
104+
macos_build:
105+
name: Build test APP [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
101106
needs: [flake8]
102107
runs-on: ${{ matrix.runs_on }}
103108
continue-on-error: true
@@ -137,146 +142,21 @@ jobs:
137142
source ci/osx_ci.sh
138143
arm64_set_path_and_python_version 3.9.7
139144
make ${{ matrix.bootstrap.target }}
140-
- name: Rename apk artifact to include the build platform name
141-
run: |
142-
mv testapps/on_device_unit_tests/${{ env.APK_ARTIFACT_FILENAME }} ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
143-
- name: Upload apk artifact
144-
uses: actions/upload-artifact@v1
145-
with:
146-
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
147-
path: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}
148-
149-
ubuntu_build_aab:
150-
name: Unit test aab [ ${{ matrix.runs_on }} ]
151-
needs: [flake8]
152-
runs-on: ${{ matrix.runs_on }}
153-
continue-on-error: true
154-
strategy:
155-
matrix:
156-
runs_on: [ubuntu-latest]
157-
bootstrap:
158-
- name: sdl2
159-
target: testapps-with-numpy-aab
160-
- name: webview
161-
target: testapps-webview-aab
162-
steps:
163-
- name: Checkout python-for-android
164-
uses: actions/checkout@v3
165-
# helps with GitHub runner getting out of space
166-
- name: Free disk space
167-
run: |
168-
df -h
169-
sudo swapoff -a
170-
sudo rm -f /swapfile
171-
sudo apt -y clean
172-
docker rmi $(docker image ls -aq)
173-
df -h
174-
- name: Pull docker image
175-
run: |
176-
make docker/pull
177-
- name: Build Android App Bundle Python 3 (armeabi-v7a, arm64-v8a, x86_64, x86)
178-
run: |
179-
mkdir -p aabs
180-
make docker/run/make/with-artifact/aab/${{ matrix.bootstrap.target }}
181-
- name: Rename artifact to include the build platform name
182-
run: |
183-
mv aabs/${{ env.AAB_ARTIFACT_FILENAME }} aabs/${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAB_ARTIFACT_FILENAME }}
184-
- name: Upload apk artifact
185-
uses: actions/upload-artifact@v1
186-
with:
187-
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAB_ARTIFACT_FILENAME }}
188-
path: aabs/${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAB_ARTIFACT_FILENAME }}
189-
190-
191-
ubuntu_build_aar:
192-
name: Unit test aar [ ${{ matrix.runs_on }} ]
193-
needs: [flake8]
194-
runs-on: ${{ matrix.runs_on }}
195-
continue-on-error: true
196-
strategy:
197-
matrix:
198-
runs_on: [ubuntu-latest]
199-
bootstrap:
200-
- name: service_library
201-
target: testapps-service_library-aar
202-
steps:
203-
- name: Checkout python-for-android
204-
uses: actions/checkout@v3
205-
# helps with GitHub runner getting out of space
206-
- name: Free disk space
207-
run: |
208-
df -h
209-
sudo swapoff -a
210-
sudo rm -f /swapfile
211-
sudo apt -y clean
212-
docker rmi $(docker image ls -aq)
213-
df -h
214-
- name: Pull docker image
215-
run: |
216-
make docker/pull
217-
- name: Build Android AAR Python 3 (arm64-v8a)
218-
run: |
219-
mkdir -p aars
220-
make docker/run/make/with-artifact/aar/${{ matrix.bootstrap.target }}
221-
- name: Rename artifact to include the build platform name
222-
run: |
223-
mv aars/${{ env.AAR_ARTIFACT_FILENAME }} aars/${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAR_ARTIFACT_FILENAME }}
224-
- name: Upload aar artifact
225-
uses: actions/upload-artifact@v1
226-
with:
227-
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAR_ARTIFACT_FILENAME }}
228-
path: aars/${{ matrix.runs_on }}-${{ matrix.bootstrap.name}}-${{ env.AAR_ARTIFACT_FILENAME }}
229-
230-
231-
macos_build_aab:
232-
name: Unit test aab [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
233-
needs: [flake8]
234-
runs-on: ${{ matrix.runs_on }}
235-
continue-on-error: true
236-
strategy:
237-
matrix:
238-
runs_on: [macos-latest, apple-silicon-m1]
239-
bootstrap:
240-
- name: sdl2
241-
target: testapps-with-numpy-aab
242-
- name: webview
243-
target: testapps-webview-aab
244-
env:
245-
ANDROID_HOME: ${HOME}/.android
246-
ANDROID_SDK_ROOT: ${HOME}/.android/android-sdk
247-
ANDROID_SDK_HOME: ${HOME}/.android/android-sdk
248-
ANDROID_NDK_HOME: ${HOME}/.android/android-ndk
249-
steps:
250-
- name: Checkout python-for-android
251-
uses: actions/checkout@v3
252-
- name: Install python-for-android
253-
run: |
254-
source ci/osx_ci.sh
255-
arm64_set_path_and_python_version 3.9.7
256-
python3 -m pip install -e .
257-
- name: Install prerequisites via pythonforandroid/prerequisites.py (Experimental)
258-
run: |
259-
source ci/osx_ci.sh
260-
arm64_set_path_and_python_version 3.9.7
261-
python3 pythonforandroid/prerequisites.py
262-
- name: Install dependencies (Legacy)
145+
- name: Copy produced artifacts into dist/ (*.apk, *.aab)
263146
run: |
264-
source ci/osx_ci.sh
265-
arm64_set_path_and_python_version 3.9.7
266-
make --file ci/makefiles/osx.mk
267-
- name: Build multi-arch sdl2 aab Python 3 (armeabi-v7a, arm64-v8a, x86_64, x86)
268-
run: |
269-
source ci/osx_ci.sh
270-
arm64_set_path_and_python_version 3.9.7
271-
make ${{ matrix.bootstrap.target }}
272-
- name: Rename sdl2 artifact to include the build platform name
147+
mkdir -p dist
148+
cp testapps/on_device_unit_tests/*.apk dist/
149+
cp testapps/on_device_unit_tests/*.aab dist/
150+
ls -l dist/
151+
- name: Rename artifacts to include the build platform name (*.apk, *.aab)
273152
run: |
274-
mv testapps/on_device_unit_tests/${{ env.AAB_ARTIFACT_FILENAME }} ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAB_ARTIFACT_FILENAME }}
275-
- name: Upload sdl2 apk artifact
276-
uses: actions/upload-artifact@v1
153+
if [ -f dist/${{ env.APK_ARTIFACT_FILENAME }} ]; then mv dist/${{ env.APK_ARTIFACT_FILENAME }} dist/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.APK_ARTIFACT_FILENAME }}; fi
154+
if [ -f dist/${{ env.AAB_ARTIFACT_FILENAME }} ]; then mv dist/${{ env.AAB_ARTIFACT_FILENAME }} dist/${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAB_ARTIFACT_FILENAME }}; fi
155+
- name: Upload artifacts
156+
uses: actions/upload-artifact@v3
277157
with:
278-
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAB_ARTIFACT_FILENAME }}
279-
path: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-${{ env.AAB_ARTIFACT_FILENAME }}
158+
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-artifacts
159+
path: dist
280160

281161
ubuntu_rebuild_updated_recipes:
282162
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ubuntu-latest ]

Makefile

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,51 @@ rebuild_updated_recipes: virtualenv
3636
ANDROID_SDK_HOME=$(ANDROID_SDK_HOME) ANDROID_NDK_HOME=$(ANDROID_NDK_HOME) \
3737
$(PYTHON) ci/rebuild_updated_recipes.py $(REBUILD_UPDATED_RECIPES_EXTRA_ARGS)
3838

39-
testapps-with-numpy: virtualenv
39+
testapps-with-numpy: testapps-with-numpy/debug/apk testapps-with-numpy/release/aab
40+
41+
# testapps-with-numpy/MODE/ARTIFACT
42+
testapps-with-numpy/%: virtualenv
43+
$(eval MODE := $(word 2, $(subst /, ,$@)))
44+
$(eval ARTIFACT := $(word 3, $(subst /, ,$@)))
45+
@echo Building testapps-with-numpy for $(MODE) mode and $(ARTIFACT) artifact
4046
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
41-
python setup.py apk --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
47+
python setup.py $(ARTIFACT) --$(MODE) --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
4248
--requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,urllib3,chardet,idna,sqlite3,setuptools,numpy \
4349
--arch=armeabi-v7a --arch=arm64-v8a --arch=x86_64 --arch=x86 \
4450
--permission "(name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)" --permission "(name=android.permission.INTERNET)"
4551

46-
testapps-with-scipy: virtualenv
52+
testapps-with-scipy: testapps-with-scipy/debug/apk testapps-with-scipy/release/aab
53+
54+
# testapps-with-scipy/MODE/ARTIFACT
55+
testapps-with-scipy/%: virtualenv
56+
$(eval MODE := $(word 2, $(subst /, ,$@)))
57+
$(eval ARTIFACT := $(word 3, $(subst /, ,$@)))
58+
@echo Building testapps-with-scipy for $(MODE) mode and $(ARTIFACT) artifact
4759
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
4860
export LEGACY_NDK=$(ANDROID_NDK_HOME_LEGACY) && \
49-
python setup.py apk --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
61+
python setup.py $(ARTIFACT) --$(MODE) --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
5062
--requirements python3,scipy,kivy \
5163
--arch=armeabi-v7a --arch=arm64-v8a
5264

53-
testapps-with-numpy-aab: virtualenv
54-
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
55-
python setup.py aab --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
56-
--requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,urllib3,chardet,idna,sqlite3,setuptools,numpy \
57-
--arch=armeabi-v7a --arch=arm64-v8a --arch=x86_64 --arch=x86 --release \
58-
--permission "(name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)" --permission "(name=android.permission.INTERNET)"
65+
testapps-webview: testapps-webview/debug/apk testapps-webview/release/aab
5966

60-
testapps-service_library-aar: virtualenv
67+
# testapps-webview/MODE/ARTIFACT
68+
testapps-webview/%: virtualenv
69+
$(eval MODE := $(word 2, $(subst /, ,$@)))
70+
$(eval ARTIFACT := $(word 3, $(subst /, ,$@)))
71+
@echo Building testapps-webview for $(MODE) mode and $(ARTIFACT) artifact
6172
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
62-
python setup.py aar --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
63-
--bootstrap service_library \
64-
--requirements python3 \
65-
--arch=arm64-v8a --arch=x86 --release
66-
67-
testapps-webview: virtualenv
68-
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
69-
python setup.py apk --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
73+
python setup.py $(ARTIFACT) --$(MODE) --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
7074
--bootstrap webview \
7175
--requirements sqlite3,libffi,openssl,pyjnius,flask,python3,genericndkbuild \
7276
--arch=armeabi-v7a --arch=arm64-v8a --arch=x86_64 --arch=x86
7377

74-
testapps-webview-aab: virtualenv
78+
testapps-service_library-aar: virtualenv
7579
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
76-
python setup.py aab --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
77-
--bootstrap webview \
78-
--requirements sqlite3,libffi,openssl,pyjnius,flask,python3,genericndkbuild \
79-
--arch=armeabi-v7a --arch=arm64-v8a --arch=x86_64 --arch=x86 --release
80+
python setup.py aar --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
81+
--bootstrap service_library \
82+
--requirements python3 \
83+
--arch=arm64-v8a --arch=x86 --release
8084

8185
testapps/%: virtualenv
8286
$(eval $@_APP_ARCH := $(shell basename $*))
@@ -106,21 +110,6 @@ docker/run/test: docker/build
106110
docker/run/command: docker/build
107111
docker run --rm --env-file=.env $(DOCKER_IMAGE) /bin/sh -c "$(COMMAND)"
108112

109-
docker/run/make/with-artifact/apk/%: docker/build
110-
docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
111-
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-debug-1.1.apk ./apks
112-
docker rm -fv p4a-latest
113-
114-
docker/run/make/with-artifact/aar/%: docker/build
115-
docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
116-
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1.aar ./aars
117-
docker rm -fv p4a-latest
118-
119-
docker/run/make/with-artifact/aab/%: docker/build
120-
docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
121-
docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1.aab ./aabs
122-
docker rm -fv p4a-latest
123-
124113
docker/run/make/rebuild_updated_recipes: docker/build
125114
docker run --name p4a-latest -e REBUILD_UPDATED_RECIPES_EXTRA_ARGS --env-file=.env $(DOCKER_IMAGE) make rebuild_updated_recipes
126115

0 commit comments

Comments
 (0)