Skip to content

Instantly share code, notes, and snippets.

@carlos-a-g-h
Created October 23, 2023 15:22
Show Gist options
  • Save carlos-a-g-h/e1fc09e659188538f1c7c53db60ccfb4 to your computer and use it in GitHub Desktop.
Save carlos-a-g-h/e1fc09e659188538f1c7c53db60ccfb4 to your computer and use it in GitHub Desktop.
Github workflow for single-file Nuitka (python) executable binaries
name: (Generic) Nuitka
on:
workflow_dispatch:
inputs:
THE_NAME:
description: Repository name (without your username)
type: string
required: true
MAIN_PY:
description: Python main filename
type: string
required: true
default: main.py
#NO_WINDOWS:
# description: Do not build for Windows, just Linux
# type: boolean
# required: true
# default: false
concurrency:
group: "${{ github.workflow }} - ${{ inputs.THE_NAME }}"
cancel-in-progress: false
jobs:
job1:
name: Build blob and upload as artifact
strategy:
matrix:
os: [ "ubuntu-20.04" , "windows-2019" ]
runs-on: ${{ matrix.os }}
steps:
#- name: Check if on Windows
# if: ${{ contains(matrix.os,'windows') == true && inputs.NO_WINDOWS == true }}
# run: exit 1
- uses: actions/checkout@v4
with:
repository: "${{ github.repository_owner }}/${{ inputs.THE_NAME }}"
ref: main
token: ${{ secrets.GH_TOKEN }}
path: source-code
sparse-checkout: .
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: 3.9.6
- name: Setup Python (req.txt)
if: ${{ hashFiles('req.txt') != '' }}
working-directory: source-code
run: |
pip install -r req.txt
mkdir out
- name: Setup Python (install Nuitka)
run: |
pip install nuitka
- name: Build for Linux
if: ${{ contains(matrix.os,'windows') == false }}
working-directory: source-code
run: |
python -m nuitka --onefile --onefile-no-compression --assume-yes-for-downloads "${{ inputs.MAIN_PY }}" --output-dir="the-output" --output-filename="${{ inputs.THE_NAME }}"
mv "the-output/${{ inputs.THE_NAME }}" "the-output/${{ inputs.THE_NAME }}.${{ matrix.os }}.${{ runner.arch }}.bin"
find the-output
- name: Build for Windows
if: ${{ contains(matrix.os,'windows') == true }}
working-directory: source-code
run: |
python -m nuitka --onefile --onefile-no-compression --assume-yes-for-downloads "${{ inputs.MAIN_PY }}" --output-dir="the-output" --output-filename="${{ inputs.THE_NAME }}.exe"
mv "the-output/${{ inputs.THE_NAME }}.exe" "the-output/${{ inputs.THE_NAME }}.${{ matrix.os }}.${{ runner.arch }}.exe"
ls
- uses: actions/upload-artifact@v3
with:
name: "${{ matrix.os }}"
if-no-files-found: error
path: |
./source-code/the-output/${{ inputs.THE_NAME }}.${{ matrix.os }}.${{ runner.arch }}.bin
./source-code/the-output/${{ inputs.THE_NAME }}.${{ matrix.os }}.${{ runner.arch }}.exe
job2:
name: Create the release
needs: job1
runs-on: ubuntu-latest
outputs:
the_upload_url: "${{ steps.step_release.outputs.upload_url }}"
steps:
- name: Get date
id: step_date
run: |
echo "the_tag_name=$(date +%Y-%m-%d-%H-%M-%S)" >> "$GITHUB_OUTPUT"
- name: (Debug) Show date
run: echo "${{ steps.step_date.outputs.the_tag_name }}"
- name: Create release
id: step_release
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: false
name: "${{ steps.step_date.outputs.the_tag_name }}"
tag_name: "${{ steps.step_date.outputs.the_tag_name }}"
token: "${{ secrets.GH_TOKEN }}"
- name: (Debug) Show Upload URL
run: |
echo ${{ steps.step_release.outputs.upload_url }}
job3:
name: Attach an artifact
needs: job2
strategy:
max-parallel: 1
matrix:
binary: [ ubuntu-20.04 , windows-2019 ]
runs-on: ubuntu-latest
steps:
- name: (Debug) Show upload URL
run: |
echo "from last job: ${{ needs.job2.outputs.the_upload_url }}"
echo "from event: ${{ github.event.release.upload_url }}"
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: "${{ matrix.binary }}"
path: "./the-asset/"
- name: (Debug) Check dir
run: ls -l the-asset
- name: Get filename
id: step_filename
run: |
tmp_var="$(ls the-asset|grep ${{ inputs.THE_NAME }})"
echo "file name is: $tmp_var"
echo "the_asset_name=$tmp_var" >> "$GITHUB_OUTPUT"
- name: Attach the artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ needs.job2.outputs.the_upload_url }}
asset_path: "./the-asset/${{ steps.step_filename.outputs.the_asset_name }}"
asset_name: "${{ steps.step_filename.outputs.the_asset_name }}"
asset_content_type: application/octet-stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment