Skip to content

Commit

Permalink
ci: native binaries (#382)
Browse files Browse the repository at this point in the history
* add pyinstaller

* pyinstaller compilation smoke test

* pyinstaller: move to dev deps, add py version

* add --hidden-import jinja2_ansible_filters

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* docs: wip adr

* chore: test

* docs: added some points about Nuitka

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: adding multiple os runs for build

* chore: improving build

* chore: fixing tests; removing setting from vscode clashing with ruff

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* chore: testing ci

* cI: refining ci/cd pipelines; dumping binaries to (pre)release

* chore: adding new poetry action to cd

* chore: removing old adr draft

* chore: addressing pr comments

* chore: patching tealer

---------

Co-authored-by: Joe Polny <joepolny@gmail.com>
Co-authored-by: Negar Abbasi <negar.abbasi@makerx.com.au>
  • Loading branch information
3 people authored Jan 29, 2024
1 parent 3b0f258 commit daa9fc5
Show file tree
Hide file tree
Showing 22 changed files with 4,412 additions and 191 deletions.
67 changes: 67 additions & 0 deletions .github/actions/build-binaries/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Setup, Build, and Test"
description: "Set up Python with Poetry, build and test binaries"
inputs:
package_name:
description: "The name of the package to build and test"
required: true
upload_binaries:
description: "Flag to determine if this is a production release"
required: true
operating_system:
description: "Operating system to set the correct binary path and extension"
required: true
build_command:
description: "Command to build the binaries"
required: true
python_version:
description: "Python version to use"
required: true

runs:
using: "composite"
steps:
- name: Build Executable
run: ${{ inputs.build_command }}
shell: bash

- name: Test Executable
run: |
ls -l dist
./dist/${{ inputs.package_name }}/${{ inputs.package_name }}${{ inputs.operating_system == 'windows-latest' && '.exe' || '' }} --help
shell: bash

- name: Set release version
shell: bash
continue-on-error: true
if: ${{ inputs.upload_binaries == 'true' }}
run: |
echo "RELEASE_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV
git describe --tags $(git rev-list --tags --max-count=1)
- name: Zip binaries
shell: bash
continue-on-error: true
if: ${{ inputs.upload_binaries == 'true' }}
run: |
ls -l dist
cd dist/algokit/
tar -zcvf ../../algokit-${{ env.RELEASE_VERSION }}-${{ inputs.operating_system }}-py${{ inputs.python_version }}.tar.gz *
cd ../..
ls -l
- name: Upload binary as artifact
if: ${{ inputs.upload_binaries == 'true' }}
uses: actions/upload-artifact@v4
with:
name: algokit-cli-${{ inputs.operating_system }}-py${{ inputs.python_version }}
path: algokit-${{ env.RELEASE_VERSION }}-${{ inputs.operating_system }}-py${{ inputs.python_version }}.tar.gz

- name: Append binary to release
continue-on-error: true
if: ${{ inputs.upload_binaries == 'true' }}
uses: softprops/action-gh-release@v1
with:
files: |
algokit-${{ env.RELEASE_VERSION }}-${{ inputs.operating_system }}-py${{ inputs.python_version }}.tar.gz
tag_name: ${{ env.RELEASE_VERSION }}
prerelease: ${{ contains(env.RELEASE_VERSION, 'beta') }}
22 changes: 22 additions & 0 deletions .github/actions/setup-poetry/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Python Poetry Action"
description: "An action to setup Poetry"
inputs:
poetry-version:
description: "The version of poetry to install"
required: false
default: "latest"
runs:
using: "composite"
steps:
- run: |
pip install --user pipx
pipx ensurepath
shell: bash
- if: ${{ inputs.poetry-version == 'latest' }}
run: |
pipx install poetry
shell: bash
- if: ${{ inputs.poetry-version != 'latest' }}
run: |
pipx install poetry==${{ inputs.poetry-version }}
shell: bash
135 changes: 135 additions & 0 deletions .github/workflows/build-binaries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Build, Test and Publish Pyinstaller Binaries

on:
workflow_call:
inputs:
upload_binaries:
required: true
type: string
python_version:
required: true
type: string

jobs:
build-binaries-ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout source code (for release)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries == 'true' }}
with:
fetch-depth: 0

- name: Checkout source code (for build)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries != 'true' }}
with:
fetch-depth: 1

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ runner.os }}-${{ inputs.python_version }}

- name: Install dependencies
run: poetry install --no-interaction

- name: Build linux binary
uses: ./.github/actions/build-binaries
with:
python_version: ${{ inputs.python_version }}
package_name: "algokit"
upload_binaries: ${{ inputs.upload_binaries }}
operating_system: ${{ runner.os }}
build_command: "poetry run poe package_unix"

build-binaries-windows:
runs-on: windows-latest
steps:
- name: Checkout source code (for release)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries == 'true' }}
with:
fetch-depth: 0

- name: Checkout source code (for build)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries != 'true' }}
with:
fetch-depth: 1

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ runner.os }}-${{ inputs.python_version }}

- name: Install dependencies
run: poetry install --no-interaction

- name: Build windows binary
uses: ./.github/actions/build-binaries
with:
python_version: ${{ inputs.python_version }}
package_name: "algokit"
upload_binaries: ${{ inputs.upload_binaries }}
operating_system: ${{ runner.os }}
build_command: "poetry run poe package_windows"

build-binaries-macos:
runs-on: macos-latest
steps:
- name: Checkout source code (for release)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries == 'true' }}
with:
fetch-depth: 0

- name: Checkout source code (for build)
uses: actions/checkout@v4
if: ${{ inputs.upload_binaries != 'true' }}
with:
fetch-depth: 1

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ runner.os }}-${{ inputs.python_version }}

- name: Install dependencies
run: poetry install --no-interaction

- name: Build macos binary
uses: ./.github/actions/build-binaries
with:
python_version: ${{ inputs.python_version }}
package_name: "algokit"
upload_binaries: ${{ inputs.upload_binaries }}
operating_system: ${{ runner.os }}
build_command: "poetry run poe package_unix"
38 changes: 26 additions & 12 deletions .github/workflows/build-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,49 @@ jobs:
build-python:
strategy:
matrix:
#os: ["ubuntu-latest", "macos-latest", "windows-latest"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
# Mac and Windows chew through build minutes - waiting until repo is public to enable
os: ["ubuntu-latest", "windows-latest"]
python: ["3.10"]
python: ["3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: "poetry"

- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ matrix.os }}-${{ matrix.python }}

- name: Install dependencies
run: poetry install --no-interaction && pipx install tealer==0.1.1
# TODO: remove fixed pipx dependency once 3.12 compatibility is addressed
# track here -> https://github.com/crytic/tealer/pull/209
run: poetry install --no-interaction && pipx install git+https://github.com/algorandfoundation/tealer@3-12

- name: pytest + coverage
shell: bash
run: |
set -o pipefail
poetry run pytest -n auto --junitxml=pytest-junit.xml --cov-report=term-missing:skip-covered --cov=src | tee pytest-coverage.txt
id: pytest

- name: Upload received snapshots (in case of failure)
if: failure() && steps.pytest.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: test-artifacts-${{ matrix.os }}-python${{ matrix.python }}
path: tests/**/*.received.txt

- name: pytest coverage comment - using Python 3.10 on ubuntu-latest
if: matrix.python == '3.10' && matrix.os == 'ubuntu-latest'
- name: pytest coverage comment - using Python 3.12 on ubuntu-latest
if: matrix.python == '3.12' && matrix.os == 'ubuntu-latest'
continue-on-error: true # forks fail to add a comment, so continue any way
uses: MishaKav/pytest-coverage-comment@main
with:
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ jobs:
# Fetch entire repository history so we can determine version number from it
fetch-depth: 0

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"

- name: Install dependencies
run: poetry install --no-interaction --no-root
- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ runner.os }}-3.10

- name: Get branch name
shell: bash
Expand Down Expand Up @@ -112,6 +114,15 @@ jobs:
path: dist/algokit*-py3-none-any.whl
if-no-files-found: error

upload-binaries:
name: Build and Upload Binaries
if: ${{ github.ref_name == 'main' }}
uses: ./.github/workflows/build-binaries.yaml
needs: release
with:
upload_binaries: "true"
python_version: "3.12"

cd-publish-release-packages:
name: Publish Release Packages
needs: release
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
python-version: "3.12"

- name: Set up Poetry
uses: ./.github/actions/setup-poetry

- uses: actions/cache@v4
name: Setup poetry cache
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}-${{ runner.os }}-3.12

- name: Install dependencies
run: poetry install --no-interaction
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/issue_closed.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/issue_commented.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/issue_labelled.yml

This file was deleted.

Loading

1 comment on commit daa9fc5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit
   __init__.py15753%6–13, 17–24, 32–34
   __main__.py220%1–3
src/algokit/cli
   completions.py108298%83, 98
   deploy.py72790%44, 46, 92–94, 158, 182
   dispenser.py121199%77
   doctor.py48394%142–144
   explore.py501276%34–39, 41–46
   generate.py67396%74–75, 140
   goal.py44198%71
   init.py1901692%277–278, 328, 331–333, 344, 388, 414, 454, 463–465, 468–473, 486
   localnet.py1191587%74–78, 111, 123, 138–148, 161, 206, 227–228
   task.py34391%25–28
src/algokit/cli/common
   utils.py26292%120, 123
src/algokit/cli/tasks
   analyze.py81199%81
   assets.py821384%65–66, 72, 74–75, 105, 119, 125–126, 132, 134, 136–137
   ipfs.py51884%52, 80, 92, 94–95, 105–107
   mint.py66494%48, 70, 91, 250
   send_transaction.py651085%52–53, 57, 89, 158, 170–174
   sign_transaction.py59886%21, 28–30, 71–72, 109, 123
   transfer.py39392%26, 90, 117
   utils.py994555%26–34, 40–43, 75–76, 100–101, 125–133, 152–162, 209, 258–259, 279–290, 297–299
   vanity_address.py561082%41, 45–48, 112, 114, 121–123
   wallet.py79495%21, 66, 136, 162
src/algokit/core
   bootstrap.py1171091%101–102, 124, 151, 180–185
   conf.py54885%12, 24, 28, 36, 38, 71–73
   deploy.py691184%61–64, 73–75, 79, 84, 91–93
   dispenser.py2022687%91, 123–124, 141–149, 191–192, 198–200, 218–219, 259–260, 318, 332–334, 345–346, 356, 369, 384
   doctor.py65789%67–69, 92–94, 134
   generate.py41295%69, 87
   goal.py60395%30–31, 41
   log_handlers.py68790%50–51, 63, 112–116, 125
   proc.py45198%98
   sandbox.py2181892%62, 73–75, 96, 142–149, 160, 456, 472, 497, 505
   typed_client_generation.py80594%55–57, 70, 75
   utils.py1043170%44–45, 49–68, 129, 132, 138–152
   version_prompt.py72889%26–27, 39, 58–61, 79, 108
src/algokit/core/tasks
   analyze.py93397%105–112, 187
   ipfs.py63789%58–64, 140, 144, 146, 152
   nfd.py491373%25, 31, 34–41, 70–72, 99–101
   vanity_address.py903462%49–50, 54, 59–75, 92–108, 128–131
   wallet.py71593%37, 129, 155–157
src/algokit/core/tasks/mint
   mint.py781087%123–133, 187
   models.py901188%50, 52, 57, 71–74, 85–88
TOTAL347240088% 

Tests Skipped Failures Errors Time
399 0 💤 0 ❌ 0 🔥 23.196s ⏱️

Please sign in to comment.