Skip to content

Package Windows builds in self-extracting executables #64

Package Windows builds in self-extracting executables

Package Windows builds in self-extracting executables #64

Workflow file for this run

# Builds the package, and, if the commit has a tag assigned to it, create a release for it and publish it to PyPI
name: Build CI/CD
on:
push:
pull_request:
jobs:
# Builds the package and uploads a build artifiact
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: distribution-archives
path: dist/*
# Builds binaries with pyinstaller
pyinstaller:
strategy:
matrix:
os: ['ubuntu', 'windows', 'macos']
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.12'
- name: Install dependencies
run: pip install .[packaging]
- name: Build executable
run: pyinstaller --noconfirm pyinstaller.spec
- name: Create DMG
if: runner.os == 'macOS'
run: |
brew update
brew install create-dmg
mkdir -p dist/dmg
mv dist/*.app dist/dmg
create-dmg \
--volname "E-mail Draft Generator" \
--volicon "assets/icon.png" \
--window-pos 200 120 \
--window-size 600 300 \
--icon-size 100 \
--icon "E-mail Draft Generator.app" 175 120 \
--hide-extension "E-mail Draft Generator.app" \
--app-drop-link 425 120 \
"dist/E-mail Draft Generator.dmg" \
"dist/dmg/"
rm -r "dist/E-mail Draft Generator" "dist/dmg"
- name: Create .tar.gz
if: runner.os == 'Linux'
run: |
mkdir release-archives
tar -czvf release-archives/email-draft-generator-linux-x86_64.tar.gz -C dist .
rm -r "dist/E-mail Draft Generator"
cp release-archives/*.tar.gz dist
- name: Create self-extracting executable
if: runner.os == 'Windows'
run: |
"C:\Program Files\7-Zip\7z.exe" a email-draft-generator-windows-sfx-x86_64.exe -mx5 -sfx7z.sfx "dist\E-mail Draft Generator"
move email-draft-generator-windows-sfx-x86_64.exe dist
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: package-${{ matrix.os }}
path: dist/*
# Creates a release if the commit has a tag associated with it
release:
needs: [build, pyinstaller]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build
uses: actions/[email protected]
with:
path: dist
merge-multiple: true
- name: Create release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*
# Publish to PyPI if the commit has a tag associated with it
publish:
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
- name: Download build
uses: actions/[email protected]
with:
name: distribution-archives
path: dist
- name: Publish package
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450