publish release #97
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
# REF: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#the-whole-ci-cd-workflow | |
name: publish release | |
on: | |
# run this workflow when manually triggered | |
workflow_dispatch: | |
inputs: | |
part: | |
description: "Semver part to bump (major, minor, patch)" | |
type: choice | |
required: true | |
default: "patch" | |
options: ["major", "minor", "patch"] | |
dry-run: | |
description: "Dry run" | |
type: boolean | |
required: true | |
default: true | |
# skip-tests: | |
# description: "Skip tests" | |
# type: boolean | |
# required: true | |
# default: false | |
jobs: | |
test: | |
uses: ./.github/workflows/dev.yml | |
# name: Run tests | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Get repo | |
# uses: actions/checkout@v4 | |
# - name: Run tests | |
# if: ${{ github.event.inputs.skip-tests == 'false' }} | |
# uses: ./.github/workflows/dev.yml | |
# - name: Get repo | |
# uses: actions/checkout@v4 | |
# - name: Skip tests | |
# if: ${{ github.event.inputs.skip-tests == 'true' }} | |
# run: echo "Skipping tests" | |
bump: | |
name: Bump version | |
runs-on: ubuntu-latest | |
needs: test | |
outputs: | |
VERSION: ${{ steps.get-version.outputs.VERSION }} | |
SHORT_VERSION: ${{ steps.get-version.outputs.SHORT_VERSION }} | |
MAJOR_VERSION: ${{ steps.get-version.outputs.MAJOR_VERSION }} | |
MINOR_VERSION: ${{ steps.get-version.outputs.MINOR_VERSION }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get tags | |
run: git fetch --tags origin | |
- name: Configure git for github-actions[bot] | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Install Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install Poetry | |
uses: abatilo/actions-poetry@v2 | |
- name: Install commitizen | |
run: pip install commitizen | |
- name: Bump version with commitizen | |
run: | | |
cz bump --increment ${{ github.event.inputs.part }} | |
- name: Commit and push with tags | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
run: git push --follow-tags | |
- name: Get version | |
id: get-version | |
run: | | |
version="$(poetry version -s)" | |
echo "VERSION=$version" >> $GITHUB_OUTPUT | |
major_version="$(cut -d '.' -f 1 <<< $version)" | |
echo "MAJOR_VERSION=$major_version" >> $GITHUB_OUTPUT | |
minor_version="$(cut -d '.' -f 2 <<< $version)" | |
echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT | |
short_version="$major_version.$minor_version" | |
echo "SHORT_VERSION=$short_version" >> $GITHUB_OUTPUT | |
- name: Show short version | |
run: echo ${{ steps.get-version.outputs.SHORT_VERSION }} | |
build: | |
name: Build distribution | |
runs-on: ubuntu-latest | |
needs: bump | |
steps: | |
- name: Show version | |
run: echo ${{ needs.bump.outputs.VERSION }} | |
- uses: actions/checkout@v4 | |
with: | |
# want this to be the version that was just bumped | |
ref: main | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- uses: abatilo/actions-poetry@v2 | |
- name: Check version | |
run: poetry version -s | |
- name: Build wheels and source tarball | |
run: poetry build | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
publish-to-pypi: | |
name: Publish to PyPI | |
needs: build | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/networkframe | |
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 PyPI | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
github-release: | |
name: Release to GitHub | |
needs: | |
- publish-to-pypi | |
- bump | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # IMPORTANT: mandatory for making GitHub Releases | |
id-token: write # IMPORTANT: mandatory for sigstore | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Sign the dists with Sigstore | |
uses: sigstore/gh-action-sigstore-python@v1.2.3 | |
with: | |
inputs: >- | |
./dist/*.tar.gz | |
./dist/*.whl | |
- name: Find ref | |
run: echo ${{ github.ref }} | |
- name: Find proper version | |
run: echo ${{ needs.bump.outputs.VERSION }} | |
- name: Create GitHub Release | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: >- | |
gh release create | |
'v${{ needs.bump.outputs.VERSION }}' | |
--repo '${{ github.repository }}' | |
--notes "" | |
- name: Upload artifact signatures to GitHub Release | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
# Upload to GitHub Release using the `gh` CLI. | |
# `dist/` contains the built packages, and the | |
# sigstore-produced signatures and certificates. | |
run: >- | |
gh release upload | |
'v${{ needs.bump.outputs.VERSION }}' dist/** | |
--repo '${{ github.repository }}' | |
docs: | |
name: Release new docs version | |
needs: | |
- publish-to-pypi | |
- bump | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get repo | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
fetch-depth: 0 # for building docs with page updated info | |
- name: Get gh-pages branch | |
run: git fetch origin gh-pages --depth=1 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install Poetry | |
uses: abatilo/actions-poetry@v2 | |
- name: Setup a local virtual environment # for caching purposes | |
run: | | |
poetry config virtualenvs.create true --local | |
poetry config virtualenvs.in-project true --local | |
- name: Cache for virtual environment | |
uses: actions/cache@v3 | |
with: | |
path: ./.venv | |
key: venv-3.11-${{ hashFiles('poetry.lock') }} | |
- name: Install dependencies | |
run: poetry install --with dev | |
- name: Configure git for github-actions[bot] | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Get version | |
run: echo "new_version=$(poetry version -s)" >> $GITHUB_ENV | |
- name: Build and push versioned docs with mike | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
run: | | |
poetry run mike deploy --push --update-aliases ${{ needs.bump.outputs.SHORT_VERSION }} stable | |
poetry run mike set-default stable --push | |
- name: Test build versioned docs with mike | |
if: ${{ github.event.inputs.dry-run == 'true' }} | |
run: | | |
poetry run mike deploy --update-aliases ${{ needs.bump.outputs.SHORT_VERSION }} stable | |
poetry run mike set-default stable |