Use trusted publisher to publish to PyPI #108
Workflow file for this run
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
name: Deploy | |
on: | |
push: | |
tags: ['v*'] | |
workflow_dispatch: | |
inputs: | |
pre-release-suffix: | |
description: 'Version suffix for pre-release package ("a", "b", "rc", etc.)' | |
required: false | |
default: '' | |
pre-release-version: | |
description: 'Version number for pre-release package (defaults to build number)' | |
required: false | |
default: '' | |
env: | |
LATEST_PY_VERSION: '3.10' | |
# Required for creating a new release | |
permissions: | |
contents: write | |
jobs: | |
build-app-packages: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
fail-fast: false | |
defaults: | |
run: | |
shell: bash | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.LATEST_PY_VERSION }} | |
- uses: snok/[email protected] | |
with: | |
virtualenvs-in-project: true | |
- name: Install system packages | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: sudo apt-get install -y '^libxcb.*-dev' libegl-dev libwebp-dev libpng16-16 libx11-xcb-dev rpm | |
- name: Cache python packages | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ env.LATEST_PY_VERSION }}-pyinstaller-${{ matrix.os }}-${{ hashFiles('poetry.lock') }} | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | | |
poetry install -v --without dev | |
poetry run pip install -U pyinstaller setuptools | |
- name: Build PyInstaller package | |
run: poetry run pyinstaller -y packaging/naturtag.spec | |
# Include taxon FTS db, compress, and set platform name | |
- name: Finish pyinstaller package (Linux) | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
ASSETS=dist/naturtag/assets | |
tar -xvzf $ASSETS/taxonomy.tar.gz --directory $ASSETS/ | |
rm $ASSETS/taxonomy.tar.gz | |
tar -C dist/naturtag/ -czvf naturtag-linux.tar.gz . | |
echo "DIST_NAME=linux" >> $GITHUB_ENV | |
- name: Finish pyinstaller package (macOS) | |
if: ${{ matrix.os == 'macos-latest' }} | |
run: | | |
ASSETS=dist/naturtag.app/Contents/Resources/assets | |
tar -xvzf $ASSETS/taxonomy.tar.gz --directory $ASSETS/ | |
rm $ASSETS/taxonomy.tar.gz | |
tar -C dist/naturtag/ -czvf naturtag-macos.tar.gz . | |
echo "DIST_NAME=macos" >> $GITHUB_ENV | |
- name: Finish pyinstaller package (Windows) | |
if: ${{ matrix.os == 'windows-latest' }} | |
run: | | |
tar -xvzf dist/naturtag/assets/taxonomy.tar.gz --directory dist/naturtag/assets/ | |
rm dist/naturtag/assets/taxonomy.tar.gz | |
tar -C dist/naturtag/ -czvf naturtag-windows.tar.gz . | |
echo "DIST_NAME=windows" >> $GITHUB_ENV | |
# Build deb, snap, and rpm packages | |
- name: Build Linux packages with FPM | |
if : ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')" | |
export PATH="$PATH:$GEM_HOME/bin" | |
gem install fpm --user-install | |
cd packaging | |
./build_fpm.sh | |
# Build dmg package | |
- name: Build disk image (macOS) | |
if: ${{ matrix.os == 'macos-latest' }} | |
run: | | |
brew install create-dmg | |
cd packaging | |
./build_dmg.sh | |
# Upload workflow artifacts | |
- name: Upload pyinstaller package | |
uses: actions/upload-artifact@v3 | |
with: | |
name: naturtag-${{ env.DIST_NAME }}.tar.gz | |
path: naturtag-${{ env.DIST_NAME }}.tar.gz | |
- name: Upload disk image (macOS) | |
if: ${{ matrix.os == 'macos-latest' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: naturtag.dmg | |
path: dist/naturtag.dmg | |
- name: Upload FPM workflow artifacts (Linux) | |
if : ${{ matrix.os == 'ubuntu-latest' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: naturtag-fpm | |
path: dist/naturtag.* | |
# Create a release with all workflow artifacts attached | |
release-app-packages: | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
needs: build-app-packages | |
steps: | |
- uses: actions/download-artifact@v3 | |
- name: Collect artifacts from workflow subdirs | |
run: | | |
find . -type d -depth -name 'naturtag*' -exec mv {} {}_dir \; | |
find . -type f -mindepth 2 -exec mv -- {} . \; | |
rmdir *_dir | |
ls -ARl | |
- name: Create release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: 'naturtag*' | |
# Publish python package to PyPI | |
release-pypi-package: | |
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.pre-release-suffix | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.LATEST_PY_VERSION }} | |
- uses: snok/[email protected] | |
with: | |
virtualenvs-in-project: true | |
- name: Set pre-release version | |
if: github.event.inputs.pre-release-suffix | |
env: | |
pre-release-suffix: ${{ github.event.inputs.pre-release-suffix }} | |
pre-release-version: ${{ github.event.inputs.pre-release-version || github.run_number }} | |
run: | | |
poetry version $(poetry version -s).${{ env.pre-release-suffix }}${{ env.pre-release-version }} | |
poetry version | |
- name: Build package distributions | |
run: poetry build | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 |