Skip to content

Commit

Permalink
Combine TestPyPi and PyPi publishing workflows (#175)
Browse files Browse the repository at this point in the history
This way we can test the publish workflow on PRs, but only publish on
releases.
  • Loading branch information
JasonGross authored Oct 24, 2023
1 parent 268f55e commit 970ec5b
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 60 deletions.
53 changes: 0 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,56 +153,3 @@ jobs:
if: ${{ needs.docker-build.result == 'success' }}
- run: echo 'The triggering workflow failed (docker)' && false
if: ${{ needs.docker-build.result != 'success' }}

build-package:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
setuptools
wheel
twine
--user
- name: Bump package version with local extension
run: etc/ci/bump-package-version.sh ".dev$(date +%s)"
- name: Build a binary wheel and a source tarball
run: make dist PYTHON=python3
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build-package
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/coq-tools

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
158 changes: 151 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
name: Publish Python 🐍 distribution 📦 to PyPI or TestPyPI

on:
release:
types: [published] # Only publish to pip when we formally publish a release
# For more on how to formally release on Github, read https://help.github.com/en/articles/creating-releases
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
build-distribution:
name: Build distribution 📦
runs-on: ubuntu-latest

Expand All @@ -25,6 +30,9 @@ jobs:
wheel
twine
--user
- name: Bump package version with local extension
run: etc/ci/bump-package-version.sh ".dev$(date +%s)"
if: ${{ ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }}
- name: Build a binary wheel and a source tarball
run: make dist PYTHON=python3
- name: Store the distribution packages
Expand All @@ -33,12 +41,94 @@ jobs:
name: python-package-distributions
path: dist/

build-standalone:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Build standalone ⛏️ ${{ matrix.os }} ${{ (matrix.os == 'windows-latest' && '🪟') || (matrix.os == 'macos-latest' && '🍎') || (matrix.os == 'ubuntu-latest' && '🐧') }}
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pyinstaller
run: >-
python3 -m
pip install
pyinstaller
- name: Build a standalone executable
run: make standalone
- name: Store the standalone packages
uses: actions/upload-artifact@v3
with:
name: python-standalone-${{ matrix.os }}
path: dist/

collect-standalone:
name: Collect standalone ⛏️
runs-on: ubuntu-latest
needs:
- build-standalone

steps:
- uses: actions/checkout@v4
- name: Download standalone ⛏️ Ubuntu
uses: actions/download-artifact@v3
with:
name: python-standalone-ubuntu-latest
path: dist-ubuntu/
- name: Download standalone ⛏️ Windows
uses: actions/download-artifact@v3
with:
name: python-standalone-windows-latest
path: dist-windows/
- name: Download standalone ⛏️ MacOS
uses: actions/download-artifact@v3
with:
name: python-standalone-macos-latest
path: dist-macos/
- run: |
mkdir -p dist
for os in ubuntu windows macos; do
pushd "dist-$os"
find .
rm -rf */_internal
for d in */; do
pushd "$d"
for i in *; do
echo "$i"
chmod +x "$i"
if [[ $i == *".exe" ]]; then
# If string ends with .exe, insert -os before .exe
mv "$i" "../../dist/${i/.exe/-${os}.exe}"
else
# Otherwise, just append -os
mv "$i" "../../dist/${i}-${os}"
fi
done
popd
done
popd
done
find dist/
ls -la dist/
tar -czvf standalone.tar.gz dist/
- name: Store the standalone ⛏️ packages
uses: actions/upload-artifact@v3
with:
name: python-standalone
path: standalone.tar.gz

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
PiPI: Publish Python 🐍 distribution 📦
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes
needs:
- build
- build-distribution
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -55,12 +145,57 @@ jobs:
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-testpypi:
name: >-
TestPyPI: Publish Python 🐍 distribution 📦
if: ${{ ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }} # only publish to TestPyPI on non-tag pushes
needs:
- build-distribution
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/coq-tools

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

check-publish:
runs-on: ubuntu-latest
needs:
- publish-to-testpypi
- collect-standalone
if: ${{ always() && ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }}
steps:
- run: echo 'The triggering workflow (publish-to-testpypi) passed'
if: ${{ needs.publish-to-testpypi.result == 'success' }}
- run: echo 'The triggering workflow (publish-to-testpypi) failed' && false
if: ${{ needs.publish-to-testpypi.result != 'success' }}
- run: echo 'The triggering workflow (collect-standalone) passed'
if: ${{ needs.collect-standalone.result == 'success' }}
- run: echo 'The triggering workflow (collect-standalone) failed' && false
if: ${{ needs.collect-standalone.result != 'success' }}


github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes
needs:
- publish-to-pypi
- collect-standalone
runs-on: ubuntu-latest

permissions:
Expand All @@ -73,12 +208,20 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: Download standalone
uses: actions/download-artifact@v3
with:
name: python-standalone
path: standalone.tar.gz
- name: Unpack standalone
run: tar -xzvf standalone.tar.gz
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
./dist/*
# ./dist/*.tar.gz
# ./dist/*.whl
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -93,6 +236,7 @@ jobs:
bump-package-version:
name: Bump package version
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes

steps:
- uses: actions/checkout@v4
Expand Down

0 comments on commit 970ec5b

Please sign in to comment.