Build with PyInstaller #51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build with PyInstaller | |
on: | |
workflow_dispatch: | |
inputs: | |
py_version: | |
description: 'Python version to use' | |
required: true | |
default: '3.9' | |
release_version: | |
description: 'Release version (e.g., v1.0.0)' | |
required: true | |
default: 'v0.0.1-alpha' | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ github.event.inputs.py_version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyinstaller | |
pip install -r requirements.txt | |
- name: Run PyInstaller | |
run: | | |
pyinstaller main.spec | |
- name: Rename executable for Windows | |
if: runner.os == 'Windows' | |
run: | | |
Rename-Item -Path dist/vigilant.exe -NewName vigilant-${{ matrix.os }}-${{ github.sha }}.exe | |
- name: Rename executable for macOS and Linux | |
if: runner.os != 'Windows' | |
run: | | |
chmod +x dist/vigilant | |
mv dist/vigilant dist/vigilant-${{ matrix.os }}-${{ github.sha }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: executable-${{ matrix.os }} | |
path: dist/vigilant-${{ matrix.os }}-${{ github.sha }}* | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: executable-ubuntu-latest | |
path: ./dist | |
- name: Download macOS artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: executable-macos-latest | |
path: ./dist | |
- name: Download Windows artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: executable-windows-latest | |
path: ./dist | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.event.inputs.release_version }} | |
release_name: ${{ github.event.inputs.release_version }} | |
draft: false | |
prerelease: false | |
generate_release_notes: true | |
overwrite: true | |
body: | | |
Pre-release versions are not consistent between tags. This is just used | |
as a way to automatically package the game as executables for different | |
operating systems. Each executable version is suffixed with its github | |
commit hash to identify versions. Pre-releases might be overwritten with | |
newer versions (differentiable by the github commit hash in the file | |
name). | |
- name: Upload Linux executable to Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./dist/vigilant-ubuntu-latest-${{ github.sha }} | |
asset_name: vigilant-ubuntu-latest-${{ github.sha }} | |
asset_content_type: application/octet-stream | |
- name: Upload macOS executable to Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./dist/vigilant-macos-latest-${{ github.sha }} | |
asset_name: vigilant-macos-latest-${{ github.sha }} | |
asset_content_type: application/octet-stream | |
- name: Upload Windows executable to Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./dist/vigilant-windows-latest-${{ github.sha }}.exe | |
asset_name: vigilant-windows-latest-${{ github.sha }}.exe | |
asset_content_type: application/octet-stream |