Main packaging #35
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
# SPDX-FileCopyrightText: 2024 geisserml <[email protected]> | |
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause | |
name: Main packaging | |
on: | |
workflow_dispatch: | |
inputs: | |
pre_test: | |
default: false | |
type: boolean | |
test: | |
default: true | |
type: boolean | |
publish: | |
default: false | |
type: boolean | |
conda: | |
default: false | |
type: boolean | |
py_version: | |
default: '3.10' | |
type: string | |
runner: | |
default: 'ubuntu-latest' | |
type: string | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
# TODO sync sourcebuild patches & third-party licenses with pdfium-binaries on before release? | |
# TODO(201): schedule test_setup and test_sourcebuild separately | |
test_setup: | |
if: ${{ inputs.pre_test }} | |
uses: ./.github/workflows/test_setup.yaml | |
test_sourcebuild: | |
if: ${{ inputs.pre_test }} | |
uses: ./.github/workflows/test_sourcebuild.yaml | |
build: | |
runs-on: ${{ inputs.runner }} | |
outputs: | |
new_version: ${{ steps.get_version.outputs.new_version }} | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ inputs.py_version }} | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
fetch-depth: 0 | |
- name: Install/update dependencies | |
run: python3 -m pip install -U -r req/setup.txt -r req/test.txt -r req/utilities.txt | |
# NOTE autorelease sets a tag, but it's just temporary for informational purpose and does not match the actually published tag | |
# We can't push the tag at this stage because we don't know the outcome of the following jobs yet | |
- name: Run autorelease script | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "geisserml" | |
git reset --hard HEAD | |
python3 setupsrc/pypdfium2_setup/autorelease.py --register | |
git checkout autorelease_tmp | |
- name: Get new version | |
id: get_version | |
run: echo "new_version=$(git describe --abbrev=0)" >> $GITHUB_OUTPUT | |
- name: Install pypdfium2 | |
run: python3 -m pip install --no-build-isolation -e . | |
- name: Run test suite | |
run: ./run test | |
- name: Run PyPI packaging script | |
run: ./run packaging_pypi | |
- name: Upload release notes | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release_notes | |
path: RELEASE.md | |
- name: Upload packages | |
uses: actions/upload-artifact@v4 | |
with: | |
name: packages | |
path: dist/* | |
# tag deliberately not pushed (see above) | |
- name: Push autorelease_tmp branch | |
run: git push -u origin autorelease_tmp | |
test: | |
if: ${{ inputs.test }} | |
needs: build | |
strategy: | |
fail-fast: false | |
matrix: | |
# NOTE On GH actions, macOS <=13 is Intel, whereas macOS >=14 will be ARM64 | |
os: ['ubuntu-latest', 'macos-13', 'macos-14', 'windows-latest'] | |
py: ['3.8', '3.9', '3.10', '3.11'] | |
include: | |
- os: ubuntu-latest | |
wheel: dist/*manylinux_*_x86_64*.whl | |
- os: macos-13 | |
wheel: dist/*macosx_*_x86_64*.whl | |
- os: macos-14 | |
wheel: dist/*macosx_*_arm64*.whl | |
- os: windows-latest | |
wheel: dist/*win_amd64.whl | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.py }} | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
ref: autorelease_tmp | |
- name: Download packages | |
uses: actions/download-artifact@v4 | |
with: | |
name: packages | |
path: dist/ | |
- name: Install dependencies | |
run: | | |
python3 -m pip install -U pip setuptools | |
python3 -m pip install -U pytest pillow numpy wheel | |
- name: Install pypdfium2 from artifact | |
run: python3 -m pip install ${{ matrix.wheel }} | |
- name: Run Test Suite | |
run: ./run test | |
publish: | |
needs: [test_setup, test_sourcebuild, build, test] | |
if: ${{ inputs.publish && !cancelled() && !contains(needs.*.result, 'failure') }} | |
runs-on: ${{ inputs.runner }} | |
environment: release # PyPI upload via "trusted publishing" | |
permissions: | |
id-token: write # PyPI upload via "trusted publishing" | |
contents: write # autorelease repository changes | |
actions: write # GH pages workflow-dispatch | |
steps: | |
- name: Check out repository (deep) | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ inputs.py_version }} | |
- name: Download packages | |
uses: actions/download-artifact@v4 | |
with: | |
name: packages | |
path: dist/ | |
- name: Download release notes | |
uses: actions/download-artifact@v4 | |
with: | |
name: release_notes | |
- name: Apply and push repository changes | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "geisserml" | |
git checkout main | |
git merge origin/autorelease_tmp | |
git tag -a ${{ needs.build.outputs.new_version }} -m "Autorelease" | |
git push | |
git push --tags | |
git checkout stable | |
git reset --hard main | |
git push --force | |
git checkout main | |
# Upload to TestPyPI / PyPI via "trusted publishing". | |
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/ | |
# https://docs.pypi.org/trusted-publishers/using-a-publisher/ | |
# https://github.com/pypa/gh-action-pypi-publish | |
- name: Publish to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
packages-dir: dist/ # the default | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: dist/ # the default | |
- name: Publish to GitHub | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: 'dist/*' | |
bodyFile: 'RELEASE.md' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ needs.build.outputs.new_version }} | |
prerelease: ${{ contains(needs.build.outputs.new_version, 'b') }} | |
- name: Trigger GH Pages rebuild | |
uses: benc-uk/workflow-dispatch@v1 | |
with: | |
workflow: gh_pages.yaml # takes no inputs | |
conda_trigger: | |
needs: [build, test, publish] | |
if: ${{ inputs.conda && !cancelled() && !contains(needs.*.result, 'failure') }} | |
runs-on: ${{ inputs.runner }} | |
steps: | |
- name: Trigger conda pypdfium2_helpers build | |
uses: benc-uk/workflow-dispatch@v1 | |
with: | |
# FIXME input not respected for py_version here | |
workflow: conda.yaml | |
inputs: | | |
{ | |
"package": "helpers", | |
"pdfium_ver": "latest", | |
"test": "true", | |
"publish": "${{ inputs.publish }}", | |
"py_version": "3.11" | |
} | |
cleanup: | |
needs: [build, test, publish, conda_trigger] | |
if: ${{ !cancelled() }} | |
runs-on: ${{ inputs.runner }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
- name: Remove temporary branch | |
run: git push origin --delete autorelease_tmp |