From 4879dd702727c1c57ade4bcd70433c68b1dc442f Mon Sep 17 00:00:00 2001 From: Artem Bulgakov Date: Tue, 23 Jun 2020 15:13:54 +0300 Subject: [PATCH] Move global_buildozer_dir to workspace --- Dockerfile | 1 + README.md | 24 ++++++++++++++++++++++++ entrypoint.sh | 8 ++++++++ patches.py | 20 ++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 patches.py diff --git a/Dockerfile b/Dockerfile index 4a1916d..911c066 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,5 +11,6 @@ RUN pip3 uninstall -y buildozer RUN echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf > /dev/null COPY entrypoint.sh /action/entrypoint.sh +COPY patches.py /action/patches.py ENTRYPOINT ["/action/entrypoint.sh"] diff --git a/README.md b/README.md index bd5a6ad..e311ff0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,30 @@ Filename of built package relative to repository root. - Example: `test_app/bin/testapp-0.1-armeabi-v7a-debug.apk` +## Caching + +You can set up cache for Buildozer global and local directories. Global +directory is in root of repository. Local directory is in workdir. + +- Global: `.buildozer-global` (sdk, ndk, platform-tools) +- Local: `test_app/.buildozer` (dependencies, build temp, _not recommended to cache_) + +I don't recommend to cache local buildozer directory because Buildozer doesn't +automatically update dependencies to latest version. + +Use cache only if it speeds up your workflow! Usually this only adds 1-3 minutes +to job running time, so I don't use it. + +Example: + +```yaml +- name: Cache Buildozer global directory + uses: actions/cache@v2 + with: + path: .buildozer-global + key: buildozer-global-${{ hashFiles('test_app/buildozer.spec') }} # Replace with your path +``` + ## Example usage ```yaml diff --git a/entrypoint.sh b/entrypoint.sh index 18f15c3..23d611f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,6 +34,14 @@ if ! cd "$INPUT_WORKDIR"; then exit 1 fi +# Apply patches +echo ::group::Applying patches to Buildozer +if ! python3 /action/patches.py; then + echo ::error::Error while running patches.py + # exit 1 # Allow to fail +fi +echo ::endgroup:: + # Run command if ! sh -c "$INPUT_COMMAND"; then echo ::error::Error while executing command \""$INPUT_COMMAND"\" diff --git a/patches.py b/patches.py new file mode 100644 index 0000000..5a1c3b4 --- /dev/null +++ b/patches.py @@ -0,0 +1,20 @@ +import os +import buildozer + +print("Changing global_buildozer_dir") +source = open(buildozer.__file__, "r", encoding="utf-8").read() +new_source = source.replace( + """ + @property + def global_buildozer_dir(self): + return join(expanduser('~'), '.buildozer') +""", + f""" + @property + def global_buildozer_dir(self): + return '{os.environ["GITHUB_WORKSPACE"]}/.buildozer_global' +""", +) +if new_source == source: + print("::warning::Cannot change global buildozer directory. Update buildozer-action to new version or create a Bug Request") +open(buildozer.__file__, "w", encoding="utf-8").write(new_source)