Skip to content

Commit

Permalink
Add cx_freeze and GitHub CI
Browse files Browse the repository at this point in the history
Eagerly add a GitHub action build while the canonical URL is still in
BitBucket so that some custom actions can be created ahead of the
switchover from BitBucket to GitHub.
  • Loading branch information
bennettgoble committed Sep 12, 2022
1 parent f66d3a6 commit ed9fbec
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
18 changes: 18 additions & 0 deletions .github/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
changelog:
exclude:
labels:
- ignore-for-release
authors:
- dependabot
categories:
- title: Breaking Changes 🛠
labels:
- semver-major
- breaking-change
- title: New Features 🎉
labels:
- semver-minor
- enhancement
- title: Other Changes
labels:
- '*'
47 changes: 47 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
pull_request:
push:
branches: [main]
tags: [v*]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all history for setuptools_scm to be able to read tags

- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install python dependencies
run: pip install .[dev,build]

- name: Run tests
if: matrix.os != 'windows-latest'
run: |
# Set up git user for git command to work with tests
git config --global user.name "tests"
git config --global user.email "[email protected]"
pytest -vv
- name: Build python package
run: python -m build

- name: cx_Freeze
run: |
python setup_cxfreeze.py build
python setup_cxfreeze.py finalize
- uses: secondlife-3p/release-action@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
artifacts: dist/autobuild-*.zip
allowUpdates: true
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: check-ast
- id: check-yaml
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'write_to': 'autobuild/version.py',
'write_to_template': 'AUTOBUILD_VERSION_STRING = \'{version}\'',
},
setup_requires=['setuptools_scm>=6,<7'],
setup_requires=['setuptools_scm'],
entry_points={
'console_scripts': ['autobuild=autobuild.autobuild_main:main']
},
Expand All @@ -48,6 +48,9 @@
'Operating System :: Unix',
],
install_requires=['llbase', 'pydot'],
extras_require={'dev': ['pytest']},
extras_require={
'dev': ['pytest'],
'build': ['build', 'cx-Freeze', 'setuptools_scm'],
},
python_requires='>=3.7',
)
56 changes: 56 additions & 0 deletions setup_cxfreeze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import platform
import shutil
from distutils.core import Command
from pathlib import Path

from cx_Freeze import Executable, setup
from setuptools_scm import get_version

ROOT_DIR = Path(__file__).parent.absolute()
COPY_TO_ZIP = ["LICENSE"]
SYSTEM_ALIASES = {"Darwin": "macos"}
ARCH_ALIASES = {"64bit": "x64"}

def get_system():
default_sys = platform.system()
return SYSTEM_ALIASES.get(default_sys, default_sys).lower()


def get_arch():
default_arch = platform.architecture()[0]
return ARCH_ALIASES.get(default_arch, default_arch).lower()


class FinalizeCommand(Command):
description = "Prepare cx_Freeze build dirs and create a zip file"
user_options = []

def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self):
version = get_version(ROOT_DIR)
for path in (ROOT_DIR / "build").iterdir():
if path.name.startswith("exe.") and path.is_dir():
for to_copy in COPY_TO_ZIP:
shutil.copy(ROOT_DIR / to_copy, path / to_copy)
system = get_system()
arch = get_arch()
zip_path = ROOT_DIR / f"dist/autobuild-{system}-{arch}-v{version}"
shutil.make_archive(zip_path, "zip", path)


build_exe_options = {
"packages": ["autobuild"],
}

autobuild = Executable("autobuild/autobuild_main.py", base=None, target_name="autobuild")

setup(
options={"build_exe": build_exe_options},
executables=[autobuild],
cmdclass={"finalize": FinalizeCommand}
)

0 comments on commit ed9fbec

Please sign in to comment.