Skip to content

Commit

Permalink
Build flatpaks
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed May 22, 2024
1 parent d0a7251 commit a120e41
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-package/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ runs:
echo "wheel-version=$(jq -r '."wheel-version"' dist/.wheel-metadata.json)" >> $GITHUB_OUTPUT
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ steps.get-wheel-info.outputs.wheel-name }}
path: ${{ steps.get-wheel-info.outputs.wheel-path }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Clone the repo
uses: actions/checkout@v4
- name: Download pre-built wheel
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
id: download-wheel
with:
name: ${{ needs.build-package.outputs.wheel-name }}
Expand All @@ -54,7 +54,7 @@ jobs:
-s 'test-${{ matrix.python-version }}(latest)'
-- '${{ steps.download-wheel.outputs.download-path }}/${{ needs.build-package.outputs.wheel-name }}'
- name: Upload coverage data
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: .coverage.*
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Clone the repo
uses: actions/checkout@v4
- name: Download pre-built wheel
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
id: download-wheel
with:
name: ${{ needs.build-package.outputs.wheel-name }}
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
- name: Clone the repo
uses: actions/checkout@v4
- name: Download coverage data
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Install nox
Expand All @@ -131,7 +131,7 @@ jobs:
run: |
nox -s produce_coverage_report
- name: Upload HTML report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
108 changes: 67 additions & 41 deletions .github/workflows/freeze.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ jobs:
matrix:
build-env:
- os: macos-12
rust-target: aarch64-apple-darwin
target: aarch64-apple-darwin
- os: macos-12
rust-target: x86_64-apple-darwin
target: x86_64-apple-darwin
- os: ubuntu-22.04
rust-target: aarch64-unknown-linux-gnu
target: aarch64-unknown-linux-gnu
- os: ubuntu-22.04
rust-target: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
# - os: windows-2022
# rust-target: aarch64-pc-windows-msvc
# target: aarch64-pc-windows-msvc
- os: windows-2022
rust-target: x86_64-pc-windows-msvc
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.build-env.os }}
steps:
- name: Clone the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download pre-built wheel
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
id: download-wheel
with:
name: ${{ needs.build-package.outputs.wheel-name }}
Expand All @@ -62,7 +62,7 @@ jobs:
- name: Install cross-compilation toolchain
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.build-env.rust-target }}
target: ${{ matrix.build-env.target }}
- name: Install cross
uses: taiki-e/install-action@v2
with:
Expand All @@ -75,29 +75,29 @@ jobs:
--wheel-file '${{ steps.download-wheel.outputs.download-path }}/${{ needs.build-package.outputs.wheel-name }}'
--out-dir ./dist-cli
env:
CARGO_BUILD_TARGET: ${{ matrix.build-env.rust-target }}
CARGO_BUILD_TARGET: ${{ matrix.build-env.target }}
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: instawow-cli-${{ needs.build-package.outputs.wheel-version }}-${{ matrix.build-env.rust-target }}
name: instawow-cli-${{ needs.build-package.outputs.wheel-version }}-${{ matrix.build-env.target }}
path: ./dist-cli/instawow*
freeze-gui:
needs: build-package
strategy:
matrix:
build-env:
- os: macos-12
- os: macos-latest
target: universal2-apple-darwin
python-version: "3.12"
briefcase-build-opts: ""
briefcase-package-opts: "--adhoc-sign"
- os: ubuntu-22.04
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
python-version: "3.12"
briefcase-build-opts: "linux appimage --no-docker"
briefcase-package-opts: "linux appimage"
- os: windows-2022
- os: macos-latest-large
target: aarch64-unknown-linux-gnu
image: quay.io/pypa/musllinux_1_2_aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
python-version: "3.12"
briefcase-build-opts: ""
briefcase-package-opts: ""
fail-fast: false
runs-on: ${{ matrix.build-env.os }}
steps:
Expand All @@ -106,42 +106,68 @@ jobs:
with:
fetch-depth: 0
- name: Download pre-built wheel
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
id: download-wheel
with:
name: ${{ needs.build-package.outputs.wheel-name }}
path: ./dist
- name: Install briefcase Linux dependencies
run: sudo apt-get update --fix-missing && sudo apt-get install -y
patchelf pkgconf
libgtk-3-dev libwebkit2gtk-4.1-dev
libgirepository1.0-dev gir1.2-javascriptcoregtk-4.1 gir1.2-webkit2-4.1
if: startsWith(matrix.build-env.os, 'ubuntu-')
run: sudo apt-get update --fix-missing && sudo apt-get install -y flatpak-builder
if: matrix.build-env.python-version && startsWith(matrix.build-env.os, 'ubuntu-')
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.build-env.python-version }}
if: matrix.build-env.python-version
- name: Install nox
run: pipx install nox uv
- name: Patch in the wheel dependency
if: matrix.build-env.python-version
- name: Freeze the GUI
run: >-
nox -s patch_frontend_spec --
nox
--error-on-missing-interpreters
--force-python ${{ matrix.build-env.python-version }}
-s freeze_gui-${{ matrix.build-env.python-version }}
--
--wheel-file '${{ steps.download-wheel.outputs.download-path }}/${{ needs.build-package.outputs.wheel-name }}'
- name: Patch in the version number
run: >-
nox -s patch_frontend_spec --
--version ${{ needs.build-package.outputs.wheel-version }}
if: startsWith(github.ref, 'refs/tags/')
- name: Install and run briefcase
${{ startsWith(github.ref, 'refs/tags/') && '--release' || '' }}
if: matrix.build-env.python-version
- name: Install nix (image)
uses: cachix/install-nix-action@v25
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
if: matrix.build-env.image
- name: Install Docker runner (image)
run: nix profile install nixpkgs#colima nixpkgs#docker
if: matrix.build-env.image
- name: Start Docker runner (image)
run: colima start
if: matrix.build-env.image
- name: Freeze the GUI (image)
run: |
python -m pip install 'briefcase @ git+https://github.com/layday/briefcase@instawow'
python -m briefcase build ${{ matrix.build-env.briefcase-build-opts }}
python -m briefcase package ${{ matrix.build-env.briefcase-package-opts }}
working-directory: instawow-gui
echo "
set -ex
PATH="/opt/python/cp312-cp312/bin:$PATH"
apk add flatpak-builder
# Can't untar under __iw
cp -R __iw __iw2
cd __iw2
python -m pip install nox uv
nox -s freeze_gui -- --wheel-file '${{ steps.download-wheel.outputs.download-path }}/${{ needs.build-package.outputs.wheel-name }}' ${{
startsWith(github.ref, 'refs/tags/') && '--release' || ''
}}
cp -R instawow-gui/dist ../__iw/instawow-gui/dist
" | docker run --privileged -iv .:/__iw ${{ matrix.build-env.image }}
if: matrix.build-env.image
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: instawow-gui-${{ needs.build-package.outputs.wheel-version }}-${{ matrix.build-env.os }}
name: instawow-gui-${{ needs.build-package.outputs.wheel-version }}-${{ matrix.build-env.target }}
path: |
instawow-gui/dist/instawow-gui-*
if-no-files-found: error
Expand All @@ -151,7 +177,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download built artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: release-assets
- name: Zip up CLI directories
Expand Down
78 changes: 46 additions & 32 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,27 @@ def _session_install_for_python_next(session: nox.Session, install_args: list[st
with tempfile.TemporaryDirectory() as temp_dir:
constraints_txt = Path(temp_dir, 'python-next-constraints.txt')
constraints_txt.write_text("""\
typing-extensions @ git+https://github.com/python/typing_extensions
""")

session.install('-c', os.fspath(constraints_txt), *install_args)
else:
session.install(*install_args)


def _locate_or_build_dist(session: nox.Session):
if session.posargs:
(package_path,) = session.posargs
else:
build_dists(session)

with Path('dist', '.wheel-metadata.json').open('rb') as wheel_metadata_json:
package_path = json.load(
wheel_metadata_json,
)['wheel-path']

return package_path


@nox.session(reuse_venv=True)
def dev_env(session: nox.Session):
"Bootstrap the dev env."
Expand Down Expand Up @@ -99,15 +112,7 @@ def test(session: nox.Session, minimum_versions: bool):
if not os.environ.get('CI'):
session.create_tmp()

if session.posargs:
(package_path,) = session.posargs
else:
build_dists(session)

with Path('dist', '.wheel-metadata.json').open('rb') as wheel_metadata_json:
package_path = json.load(
wheel_metadata_json,
)['wheel-path']
package_path = _locate_or_build_dist(session)

install_args = [
f'instawow[skeletal-gui, test] @ {package_path}',
Expand Down Expand Up @@ -151,21 +156,12 @@ def produce_coverage_report(session: nox.Session):
def type_check(session: nox.Session):
"Run Pyright."

if session.posargs:
(package_path,) = session.posargs
else:
build_dists(session)

with Path('dist', '.wheel-metadata.json').open('rb') as wheel_metadata_json:
package_path = json.load(
wheel_metadata_json,
)['wheel-path']
package_path = _locate_or_build_dist(session)

_session_install_for_python_next(
session,
[f'instawow[skeletal-gui, types] @ {package_path}'],
)

session.run('npx', 'pyright', external=True)


Expand Down Expand Up @@ -268,27 +264,45 @@ def freeze_cli(session: nox.Session):
raise RuntimeError('built executable not found')


@nox.session(python=False)
def patch_frontend_spec(session: nox.Session):
"Patch the wheel path and version in the frontend spec."
@nox.session
def freeze_gui(session: nox.Session):
"Freeze the GUI with briefcase."

import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument('--version')
parser.add_argument('--wheel-file')
parser.add_argument('--platform', default=sys.platform)
parser.add_argument('--release', action='store_true')
parser.add_argument('--wheel-file', required=True)

options = parser.parse_args(session.posargs)

spec_path = Path(__file__).parent.joinpath('instawow-gui', 'pyproject.toml')
spec = spec_path.read_text(encoding='utf-8')

if options.version:
spec = spec.replace('version = "0.1.0"', f'version = "{options.version}"')

if options.wheel_file:
spec = spec.replace(
'"instawow[gui]"',
f'"instawow[gui] @ {Path(options.wheel_file).resolve().as_uri()}"',
)
if options.release:
(package_metadata,) = Distribution.discover(name='instawow', path=[options.wheel_file])
spec = spec.replace(
'"instawow[gui]"', f'"instawow[gui] @ {Path(options.wheel_file).resolve().as_uri()}"'
'version = "0.1.0"',
f'version = "{package_metadata.version}"',
)

spec_path.write_text(spec, encoding='utf-8')

if options.platform == 'linux':
build_opts = package_opts = ['linux', 'flatpak']
elif options.platform == 'darwin':
build_opts = []
package_opts = ['--adhoc-sign']
else:
build_opts = []
package_opts = []

session.install('briefcase')

with session.chdir('instawow-gui'):
session.run('briefcase', 'build', *build_opts)
session.run('briefcase', 'package', *package_opts)

0 comments on commit a120e41

Please sign in to comment.