name: PyInstaller Action author: "@Martin005" 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" python_arch: description: specific python architecture you want to use default: "x64" 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: (Install) python uses: actions/setup-python@v4 with: python-version: ${{ inputs.python_ver }} architecture: ${{ inputs.python_arch }} - name: (Install) python dev tools shell: bash run: python -m pip install pip wheel setuptools - name: checks for inputs 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 repository uses: actions/checkout@v3 - 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 \ --distpath ${{ 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 echo " - Python architecture used: '${{ inputs.python_arch }}'" >> $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'."