Skip to content

Instantly share code, notes, and snippets.

@carlos-a-g-h
Last active May 27, 2023 13:49
Show Gist options
  • Save carlos-a-g-h/54656c28eb574002700cb0e68f5d45f7 to your computer and use it in GitHub Desktop.
Save carlos-a-g-h/54656c28eb574002700cb0e68f5d45f7 to your computer and use it in GitHub Desktop.
This is for python apps. Creates a github release and adds Windows and Linux binaries made with PyInstaller as release assets. Edit the env vars before using
name: Create release and binaries
on:
workflow_dispatch:
env:
TAGNAME: "tag-name-here"
FILE_REQ: "requirements.txt"
FILE_PY: "program.py"
NAME_LINUX: "linux-build.tar"
NAME_LINUX_STEM: "linux-build"
NAME_WINDOWS: "windows-build.zip"
NAME_WINDOWS_STEM: "windows-build"
jobs:
job-one:
name: Build binaries
strategy:
matrix:
os: [windows-2019,ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- name: Pull the repo
uses: actions/checkout@v3
- name: Setup Python (1)
uses: actions/setup-python@v3
with:
python-version: "3.9.6"
- name: Setup Python (2)
run: |
pip install -r "${{ env.FILE_REQ }}"
- name: Linux (Build binary)
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
pip install pyinstaller
pyinstaller --onefile "${{ env.FILE_PY }}"
mv dist "${{ env.NAME_LINUX_STEM }}"
tar -cvf "${{ env.NAME_LINUX }}" "${{ env.NAME_LINUX_STEM }}"
- name: Linux (Upload artifact)
if: ${{ matrix.os == 'ubuntu-20.04' }}
uses: actions/upload-artifact@v3
with:
name: "${{ env.NAME_LINUX }}"
path: "${{ env.NAME_LINUX }}"
- name: Windows (Build binary)
if: ${{ matrix.os == 'windows-2019' }}
run: |
pip install PyInstaller
python -m PyInstaller --onefile "${{ env.FILE_PY }}"
mv dist "${{ env.NAME_WINDOWS_STEM }}"
Compress-Archive "${{ env.NAME_WINDOWS_STEM }}" "${{ env.NAME_WINDOWS }}"
- name: Windows (Upload artifact)
if: ${{ matrix.os == 'windows-2019' }}
uses: actions/upload-artifact@v3
with:
name: "${{ env.NAME_WINDOWS }}"
path: "${{ env.NAME_WINDOWS }}"
job-two:
name: Create release and add the assets
needs: job-one
runs-on: ubuntu-latest
steps:
- name: Download artifact (Linux)
uses: actions/download-artifact@v2.1.1
with:
name: "${{ env.NAME_LINUX }}"
- name: Download artifact (Windows)
uses: actions/download-artifact@v2.1.1
with:
name: "${{ env.NAME_WINDOWS }}"
- name: Make sure that the files exist
run: |
ls -l "${{ env.NAME_LINUX }}"
ls -l "${{ env.NAME_WINDOWS }}"
- name: Create release
id: CreateRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: "${{ env.TAGNAME }}"
release_name: "${{ env.TAGNAME }}"
draft: false
prerelease: false
- name: Ubuntu / Linux (Upload Release Asset)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.CreateRelease.outputs.upload_url }}
asset_path: "${{ env.NAME_LINUX }}"
asset_name: "${{ env.NAME_LINUX }}"
asset_content_type: application/octet-stream
- name: Windows (Upload Release Asset)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.CreateRelease.outputs.upload_url }}
asset_path: "${{ env.NAME_WINDOWS }}"
asset_name: "${{ env.NAME_WINDOWS }}"
asset_content_type: application/octet-stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment