ArtemSBulgakov / buildozer-action

GitHub Action to build your Python application with Buildozer
MIT License
73 stars 71 forks source link

Buildozer action

Build workflow Build (with Buildozer master) workflow

Build your Python/Kivy applications for Android with Buildozer. This action uses official Buildozer Docker image, but adds some features and patches to use in GitHub Actions.

Full workflow

Full workflow with uploading binaries as artifact.

name: Build
on: [push, pull_request]

jobs:
  # Build job. Builds app for Android with Buildozer
  build-android:
    name: Build for Android
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Build with Buildozer
        uses: ArtemSBulgakov/buildozer-action@v1
        id: buildozer
        with:
          workdir: test_app
          buildozer_version: stable

      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          name: package
          path: ${{ steps.buildozer.outputs.filename }}
Full workflow with uploading binaries to branch Builds app and uploads to the `data` branch. Also copy [.ci/move_binary.py](.ci/move_binary.py) script and create `data` branch as described above. ```yaml name: Build on: push: branches-ignore: - data - gh-pages tags: - '**' pull_request: branches-ignore: - data - gh-pages jobs: # Build job. Builds app for Android with Buildozer build-android: name: Build for Android runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: path: master - name: Build with Buildozer uses: ArtemSBulgakov/buildozer-action@v1 id: buildozer with: repository_root: master workdir: test_app buildozer_version: stable - name: Upload artifacts uses: actions/upload-artifact@v2 with: name: package path: ${{ steps.buildozer.outputs.filename }} - name: Checkout uses: actions/checkout@v2 with: path: data ref: data # Branch name - name: Set up Python uses: actions/setup-python@v2 with: python-version: 3.7 architecture: x64 - name: Push binary to data branch if: github.event_name == 'push' run: python master/.ci/move_binary.py "${{ steps.buildozer.outputs.filename }}" master data bin ```

Examples

You can search GitHub for repositories that use this action.

Some great examples:

Inputs

command

Required Command to start Buildozer.

repository_root

Required Path to cloned repository.

workdir

Required Working directory where buildozer.spec is located.

buildozer_version

Required Version of Buildozer to install.

Outputs

filename

Filename of built package relative to GITHUB_WORKSPACE.

Environment variables

You can set environment variables to change Buildozer settings. See Buildozer Readme for more information.

Example (change Android architecture):

env:
  APP_ANDROID_ARCH: armeabi-v7a

Caching

You can set up cache for Buildozer global and local directories. Global directory is in root of repository. Local directory is in workdir.

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:

- 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

- name: Build with Buildozer
  uses: ArtemSBulgakov/buildozer-action@v1
  id: buildozer
  with:
    command: buildozer android debug
    workdir: src
    buildozer_version: stable

Uploading binaries

As artifact

You can upload binary as artifact to run. You will be able to download it by clicking on "Artifacts" button on run page (where you see logs).

- name: Upload artifacts
  uses: actions/upload-artifact@v2
  with:
    name: package
    path: ${{ steps.buildozer.outputs.filename }}

To branch

Artifacts use GitHub Storage and you have to pay for private repositories when limit exceeded. Another way to upload binary is pushing it to branch in your repository.

Copy .ci/move_binary.py script, edit it if you want and add this to your workflow:

- name: Checkout
  uses: actions/checkout@v2
  with:
    path: data
    ref: data # Branch name

- name: Set up Python
  uses: actions/setup-python@v2
  with:
    python-version: 3.7
    architecture: x64

- name: Push binary to data branch
  if: github.event_name == 'push'
  run: python master/.ci/move_binary.py "${{ steps.buildozer.outputs.filename }}" master data bin

Also you need to create data branch:

git checkout --orphan data
echo # Branch `data` > README.md
git add README.md
git commit -m "Add Readme"
git push origin data

Action versioning

Currently it is recommended to use v1 tag. This tag updates when new v1.x.x version released. All v1 versions will have backward compatibility. You will get warning when v2 will be released.

How to build packages locally

Use official Buildozer's Docker image (repository).

Contributing

Create Bug Request if you have problems with running this action or Feature Request if you have ideas how to improve it. If you know how to fix something, feel free to fork repository and create Pull Request. Test your changes in fork before creating Pull Request.

Format python files:

pip install pre-commit
pre-commit install

# Format all files
pre-commit run --all-files

License

ArtemSBulgakov/buildozer-action is released under the terms of the MIT License.