Skip to content
name: Build Wheel, Release, Upload
on:
workflow_call:
inputs:
project:
description: 'Name of the project to test'
default: 'PROJECT_NAME'
required: false
type: string
c_extension:
description: 'Whether the project has a C extension'
default: false
required: false
type: boolean
secrets:
PYPI_TOKEN:
description: 'PyPI token'
required: true
PAT_TOKEN:
description: 'GitHub Personal Access Token'
required: true
jobs:
tag-privilege-check:
uses: ./.github/workflows/_release_tag_privilege_check.yml
build-pure-python-package:
needs: [tag-privilege-check]
if: inputs.c_extension == false
uses: ./.github/workflows/_build-pure-python-package.yml
build-non-pure-python-package:
needs: [tag-privilege-check]
if: inputs.c_extension == true
uses: ./.github/workflows/_build-non-pure-python-package.yml
update-changelog:
needs: [build-pure-python-package, build-non-pure-python-package]
# The always() function is necessary to ensure that we wait for both build jobs to complete, even if one of them is skipped.
# Without always(), if one of the needed jobs is skipped, the `update-changelog` job will not be executed.
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail update-changelog job if building failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package }}" == 'success' ]; then
echo "Ready to update CHANGELOG.rst..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.PAT_TOKEN }}
- name: Update CHANGELOG.rst with the latest news
run: |
wget https://raw.githubusercontent.com/Billingegroup/release-scripts/v0/.github/workflows/update-changelog.py
python update-changelog.py "${{ github.ref_name }}"
rm update-changelog.py
- name: Commit the changes in CHANGELOG.rst
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: update changelog
branch: main
github-pre-release:
needs: [build-pure-python-package, build-non-pure-python-package]
if: "always() && contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-pre-release job if building job failed
run: |
if [ "${{ needs.build-pure-python-package.result }}" == 'success' ] || [ "${{ needs.build-non-pure-python-package }}" == 'success' ]; then
echo "Ready to pre-release on GitHub..."
else
echo "Previous build-package job failed; exiting..."
exit 1
fi
- name: Generate GH release notes for pre-release
uses: softprops/action-gh-release@v2
with:
draft: true # FIXME: remove after testing
prerelease: true
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
github-release:
needs: [update-changelog]
if: "always() && !contains(github.ref, 'rc')"
runs-on: ubuntu-latest
steps:
- name: Fail github-release job if CHANGELOG udpate failed
run: |
if [ "${{ needs.update-changelog.result }}" == 'success' ]; then
echo "Ready to release on GitHub..."
else
echo "Previous update-changelog job failed; exiting..."
exit 1
fi
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: main
- name: Generate GH release notes for release
run: |
wget https://raw.githubusercontent.com/Billingegroup/release-scripts/v0/.github/workflows/get-latest-changelog.py
python get-latest-changelog.py "${{ github.ref_name }}"
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
draft: true # FIXME: remove after testing
token: ${{ secrets.GITHUB_TOKEN }}
pypi-publish:
needs: [github-pre-release, github-release]
runs-on: ubuntu-latest
if: always() # This job will always initiate regardless of the success or failure of the needed jobs
steps:
- name: Fail pypi-publish step if github-(pre)-release step failed
run: |
if [ "${{ needs.github-pre-release.result }}" == 'success' ] || [ "${{ needs.github-release.result }}" == 'success' ]; then
echo "Ready for PyPI release..."
else
echo "Previous github-(pre)-release step failed; exiting..."
exit 1
fi
- uses: actions/download-artifact@v4
with:
pattern: '**/*' # Make sure all files are downloaded, including wheels
path: dist
merge-multiple: true
- name: Setup Python for PyPI upload
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Twine
run: |
python -m pip install --upgrade pip
pip install twine
- name: Publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
# TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
# twine upload dist/* --verbose
run: |
twine upload --repository testpypi dist/* --verbose

Check failure on line 159 in .github/workflows/_build-wheel-release-upload.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/_build-wheel-release-upload.yml

Invalid workflow file

You have an error in your yaml syntax on line 159