Skip to content

Commit

Permalink
Add support for generating binaries with pyinstaller (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0l authored Feb 12, 2021
1 parent b9c2c4f commit 9d0ea89
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pyinstaller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build binary

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/requirements.txt
pip install -r requirements/requirements_dev.txt
pip install pyinstaller
- name: Build binary
run: |
invoke build-binary
- name: Test the binary
run:
invoke test-binary

- name: Prepare binary for upload
run:
invoke prepare-binary

24 changes: 24 additions & 0 deletions aws-gate.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- mode: python -*-

block_cipher = None

a = Analysis(['bin/aws-gate'],
pathex=['.'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
cipher=block_cipher)

pyz = PYZ(a.pure,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='aws-gate',
debug=False,
strip=None,
upx=True,
console=True)
1 change: 1 addition & 0 deletions requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ flake8==3.8.4
flake8-bandit==2.1.2
flake8-bugbear==20.11.1
hypothesis==6.2.0
invoke==1.5.0
placebo==0.9.0
pre-commit==2.10.1
pylint==2.6.0
Expand Down
37 changes: 37 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import hashlib
import os
import platform

from invoke import task


@task
def build_binary(ctx):
ctx.run("pyinstaller ./aws-gate.spec")


@task
def test_binary(ctx):
ctx.run("./dist/aws-gate --version")
ctx.run("./dist/aws-gate --help")


@task
def prepare_binary(ctx): # pylint: disable=unused-argument
binary_name = "aws-gate"
binary_path = f"./dist/{binary_name}"
platform_suffix = f"{platform.system()}_{platform.machine()}"
platform_binary_name = f"{binary_name}-{platform_suffix}"
platform_binary_path = f"{binary_path}-{platform_suffix}"

os.rename(binary_path, platform_binary_path)

with open(f"{platform_binary_path}-sha256sum.txt", "w") as h:
with open(f"{platform_binary_path}", "rb") as f:
hash = hashlib.sha256(f.read()).hexdigest()
h.write(f"{hash} {platform_binary_name}\n")


@task
def clean_binary(ctx):
ctx.run("rm -vrf ./dist")

0 comments on commit 9d0ea89

Please sign in to comment.