Skip to content

Commit

Permalink
Use Makefile to build binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Apr 8, 2024
1 parent 48b0dc7 commit fc5a3e7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,47 @@ on:

jobs:
release:
runs-on: ${{ matrix.platform == 'linux' && 'ubuntu-latest' || matrix.platform == 'windows' && 'ubuntu-latest' || matrix.platform == 'osx' && 'macos-latest' }}
runs-on: ${{ matrix.platform == 'linux' && 'ubuntu-latest' || matrix.platform == 'windows' && 'ubuntu-latest' || matrix.platform == 'macos' && 'macos-latest' }}
strategy:
matrix:
platform: [linux, windows, osx]
platform: [linux, windows, macos]
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v4

# Linux

# Linux (for linux and windows we can use the default make commands to build the binary)
- name: Build binary (linux/windows)
if: matrix.platform == 'linux' || matrix.platform == 'windows'
run: docker run --rm -v "${PWD}:/src/" --env SPECFILE=./schwifty.spec batonogov/pyinstaller-${{ matrix.platform }}
run: make dist-${{ matrix.platform }}


# Macos
# Macos (for macos we need to use cachix to install nix and devenv and then use devenv to build the binary)
- uses: cachix/install-nix-action@v26
if: matrix.platform == 'osx'
if: matrix.platform == 'macos'

- uses: cachix/cachix-action@v14
if: matrix.platform == 'osx'
if: matrix.platform == 'macos'
with:
name: devenv

- name: Install devenv.sh
if: matrix.platform == 'osx'
if: matrix.platform == 'macos'
run: nix profile install nixpkgs#devenv

- name: Build binary (macos)
if: matrix.platform == 'osx'
run: devenv test
if: matrix.platform == 'macos'
run: devenv shell make dist-macos


# Finalize
- name: Test binary
run: dist/schwifty "DE89370400440532013000"
run: dist/${{ matrix.platform }}/schwifty "DE89370400440532013000"

- name: Compress binary
run: tar -czvf schwifty-${{ matrix.platform }}.tar.gz -C dist/ schwifty
run: tar -czvf schwifty-${{ matrix.platform }}.tar.gz -C dist/${{ matrix.platform }}/ schwifty

- uses: shogo82148/actions-upload-release-asset@v1
with:
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian:bookworm-slim

WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends curl tar && \
rm -rf /var/lib/apt/lists/*

# COPY ./schwifty-linux.tar.gz .

# RUN tar -xzf schwifty-linux.tar.gz && rm schwifty-linux.tar.gz

COPY ./dist/schwifty .

ENTRYPOINT ["./schwifty"]
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test
.PHONY: build test test-binary dist-linux dist-macos dist-windows

build:
pyinstaller --clean --noconfirm schwifty.spec
Expand All @@ -7,4 +7,21 @@ test:
@$(DEVENV_ROOT)/.venv/bin/python $(DEVENV_ROOT)/schwifty-cli/__main__.py "DE89370400440532013000" | jq '.'

test-binary:
@$(DEVENV_ROOT)/dist/schwifty "DE89370400440532013000" | jq '.'
@$(DEVENV_ROOT)/dist/schwifty "DE89370400440532013000" | jq '.'

# Targets for building the binary distributions for different platforms.
dist-linux:
docker run --rm -v "${PWD}:/src/" --env SPECFILE=./schwifty.spec batonogov/pyinstaller-linux
mkdir dist/linux
mv dist/schwifty dist/linux/schwifty

dist-macos:
# docker run --rm -v "${PWD}:/src/" --env SPECFILE=./schwifty.spec batonogov/pyinstaller-osx
pyinstaller --clean --noconfirm schwifty.spec
mkdir dist/macos
mv dist/schwifty dist/macos/schwifty

dist-windows:
docker run --rm -v "${PWD}:/src/" --env SPECFILE=./schwifty.spec batonogov/pyinstaller-windows
mkdir dist/windows
mv dist/schwifty dist/windows/schwifty

0 comments on commit fc5a3e7

Please sign in to comment.