-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for "Options/Flags" to pass to pyinstaller (#2)
- [NEW] Added support of pyinstaller options - Provide all options in "inputs.options: <comma-seperated-options-here>" - .py and .spec type of specs, both supports d/f types of options - Look at readme for the list of supported options - README updated - Information about new input, i.e "options" - List of all supported options - List of all inputs and outputs with their description and default values
- Loading branch information
1 parent
8921d4f
commit 3f23c8b
Showing
5 changed files
with
302 additions
and
160 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,128 @@ | ||
name: Versatile PyInstaller | ||
author: '@sayyid5416' | ||
description: GitHub Action to package python scripts into executables | ||
branding: | ||
icon: hard-drive | ||
color: yellow | ||
|
||
|
||
inputs: | ||
spec: | ||
description: > | ||
path of your '.py' or '.spec' file. | ||
- This file will be used to create executable. | ||
- If .py: Generated spec file will also be uploaded as artifact | ||
required: true | ||
default: '' | ||
requirements: | ||
description: path of your requirements.txt file | ||
default: '' | ||
python_ver: | ||
description: specific python version you want to use | ||
default: '3.10' | ||
exe_path: | ||
description: path where generated executable will be saved, on runner-os | ||
default: './dist' | ||
upload_exe_with_name: | ||
description: If passed, executable will be uploaded with this name as artifact. Else, artifact won't be uploaded. | ||
default: '' | ||
|
||
outputs: | ||
executable_path: | ||
description: path on runner-os, where generated executable files are stored | ||
value: ${{ inputs.exe_path }} | ||
is_uploaded: | ||
description: true, if packaged executable has been uploaded as artifact | ||
value: ${{ steps.exe_uploading.outputs.uploaded }} | ||
|
||
|
||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
|
||
- name: checks | ||
shell: bash | ||
run: python "${{ github.action_path }}/src/checks.py" | ||
env: | ||
spec: ${{ inputs.spec }} | ||
upload_exe_with_name: ${{ inputs.upload_exe_with_name }} | ||
|
||
- name: Setting modified outputs | ||
id: mods | ||
shell: bash | ||
run: python "${{ github.action_path }}/src/mods.py" | ||
env: | ||
spec: ${{ inputs.spec }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: (Install) python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python_ver }} | ||
|
||
- name: (Install) python dev tools | ||
shell: bash | ||
run: python -m pip install pip wheel setuptools | ||
|
||
- name: (Install) dependencies | ||
if: inputs.requirements != '' | ||
run: python -m pip install -r "${{ inputs.requirements }}" | ||
shell: bash | ||
|
||
- name: (Install) pyinstaller | ||
shell: bash | ||
run: pip install pyinstaller | ||
|
||
- name: (Create) Executable | ||
shell: bash | ||
run: | | ||
pyinstaller \ | ||
--clean \ | ||
--noconfirm \ | ||
--dist ${{ inputs.exe_path }} \ | ||
"${{ inputs.spec }}" | ||
echo "✔️ Executable created successfully at _'${{ inputs.exe_path }}'_" >> $GITHUB_STEP_SUMMARY | ||
echo " - Python version used: '${{ inputs.python_ver }}'" >> $GITHUB_STEP_SUMMARY | ||
- name: (Upload) Executable | ||
id: artifact_upload | ||
if: inputs.upload_exe_with_name != '' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ inputs.upload_exe_with_name }} | ||
path: ${{ inputs.exe_path }} | ||
|
||
- name: (Upload) generated spec file - if .py | ||
if: endsWith(inputs.spec, '.py') | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Generated spec file | ||
path: ${{ steps.mods.outputs.spec_name }}.spec | ||
|
||
- name: If executable upload success | ||
id: exe_uploading | ||
if: steps.artifact_upload.conclusion == 'success' | ||
shell: bash | ||
run: | | ||
echo "✔️ Executable **_(${{ inputs.upload_exe_with_name }})_** uploaded successfully" >> $GITHUB_STEP_SUMMARY | ||
echo "uploaded='true'" >> $GITHUB_OUTPUT | ||
- name: If executable upload fails | ||
if: failure() && steps.artifact_upload.conclusion == 'failure' | ||
shell: bash | ||
run: | | ||
echo "::warning title=Failed-Upload::\ | ||
Executable couldn't upload. \ | ||
Check available storage at: 'settings > billing > Storage for Actions and Packages'." | ||
name: Versatile PyInstaller | ||
author: '@sayyid5416' | ||
description: GitHub Action to package python scripts into executables | ||
branding: | ||
icon: hard-drive | ||
color: yellow | ||
|
||
|
||
inputs: | ||
spec: | ||
description: > | ||
path of your '.py' or '.spec' file. | ||
- This file will be used to create executable. | ||
- If .py: Generated spec file will also be uploaded as artifact | ||
required: true | ||
default: '' | ||
requirements: | ||
description: path of your requirements.txt file | ||
default: '' | ||
options: | ||
description: > | ||
Options to set for pyinstaller command | ||
Ex: options: '--onedir, -F' (seperated by comma and space) | ||
- Supported options: Check readme | ||
default: '' | ||
python_ver: | ||
description: specific python version you want to use | ||
default: '3.10' | ||
exe_path: | ||
description: Path on runner-os, where generated executable files are stored | ||
default: './dist' | ||
upload_exe_with_name: | ||
description: If passed, uploads executable artifact with this name. Else, artifact won't be uploaded. | ||
default: '' | ||
|
||
outputs: | ||
executable_path: | ||
description: path on runner-os, where generated executable files are stored | ||
value: ${{ inputs.exe_path }} | ||
is_uploaded: | ||
description: true, if packaged executable has been uploaded as artifact | ||
value: ${{ steps.exe_uploading.outputs.uploaded }} | ||
|
||
|
||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
|
||
- name: checks | ||
shell: bash | ||
run: python "${{ github.action_path }}/src/checks.py" | ||
env: | ||
spec: ${{ inputs.spec }} | ||
upload_exe_with_name: ${{ inputs.upload_exe_with_name }} | ||
|
||
- name: (Set) modified outputs | ||
id: mods | ||
shell: bash | ||
run: python "${{ github.action_path }}/src/mods.py" | ||
env: | ||
spec: ${{ inputs.spec }} | ||
options: ${{ inputs.options }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: (Install) python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python_ver }} | ||
|
||
- name: (Install) python dev tools | ||
shell: bash | ||
run: python -m pip install pip wheel setuptools | ||
|
||
- name: (Install) dependencies | ||
if: inputs.requirements != '' | ||
run: python -m pip install -r "${{ inputs.requirements }}" | ||
shell: bash | ||
|
||
- name: (Install) pyinstaller | ||
shell: bash | ||
run: pip install pyinstaller | ||
|
||
- name: (Create) Executable | ||
shell: bash | ||
run: | | ||
pyinstaller \ | ||
--clean \ | ||
--noconfirm \ | ||
--dist ${{ inputs.exe_path }} \ | ||
${{ steps.mods.outputs.supported_options }} \ | ||
"${{ inputs.spec }}" | ||
echo "✔️ Executable created successfully at _'${{ inputs.exe_path }}'_" >> $GITHUB_STEP_SUMMARY | ||
echo " - Python version used: '${{ inputs.python_ver }}'" >> $GITHUB_STEP_SUMMARY | ||
- name: (Upload) Executable | ||
id: artifact_upload | ||
if: inputs.upload_exe_with_name != '' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ inputs.upload_exe_with_name }} | ||
path: ${{ inputs.exe_path }} | ||
|
||
- name: (Upload) generated spec file - if .py | ||
if: endsWith(inputs.spec, '.py') | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Generated spec file | ||
path: ${{ steps.mods.outputs.spec_name }}.spec | ||
|
||
- name: If executable upload success | ||
id: exe_uploading | ||
if: steps.artifact_upload.conclusion == 'success' | ||
shell: bash | ||
run: | | ||
echo "✔️ Executable **_(${{ inputs.upload_exe_with_name }})_** uploaded successfully" >> $GITHUB_STEP_SUMMARY | ||
echo "uploaded='true'" >> $GITHUB_OUTPUT | ||
- name: If executable upload fails | ||
if: failure() && steps.artifact_upload.conclusion == 'failure' | ||
shell: bash | ||
run: | | ||
echo "::warning title=Failed-Upload::\ | ||
Executable couldn't upload. \ | ||
Check available storage at: 'settings > billing > Storage for Actions and Packages'." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
from typing import Literal | ||
|
||
|
||
def env(name:str, _def=''): | ||
""" Returns environment variable """ | ||
return os.environ.get(name, _def) | ||
|
||
|
||
#-bug: Previous step annotations are being overwritten | ||
def set_annotation( | ||
message:str, | ||
title:str='', | ||
_type:Literal['debug', 'notice', 'warning', 'error']='notice', | ||
): | ||
""" | ||
Sets annotation with `message` text | ||
- `title`: If provided, `title` text will be shown as title | ||
- `_type`: Type of annotation to set | ||
""" | ||
title = f' title={title}' if title else '' | ||
print(f'::{_type}{title}::{message}') | ||
if _type == 'error': | ||
exit(1) | ||
|
||
|
||
def set_output(key:str, value:str): | ||
""" Sets the output to `$GITHUB_OUTPUT` file | ||
- Using `key=value` | ||
""" | ||
with open(env('GITHUB_OUTPUT'), 'a') as f: | ||
f.write(f'{key}={value}\n') |
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
Oops, something went wrong.