Build wheel and upload to PyPI #3
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
## Build wheel and upload to PyPI | |
## https://github.com/joerick/cibuildwheel/blob/master/examples/github-deploy.yml | |
## https://scikit-hep.org/developer/gha_wheels | |
name: Build wheel and upload to PyPI | |
# When pushing with a tag (i.e. new version) | |
on: | |
push: | |
tags: | |
- "*" | |
jobs: | |
check-current-branch: | |
runs-on: ubuntu-latest | |
outputs: | |
branch: ${{ steps.check_step.outputs.branch }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get current branch | |
id: check_step | |
# 1. Get the list of branches ref where this tag exists | |
# 2. Remove 'origin/' from that result | |
# 3. Put that string in output | |
# => We can now use function 'contains(list, item)'' | |
run: | | |
raw=$(git branch -r --contains ${{ github.ref }}) | |
branch="$(echo ${raw//origin\//} | tr -d '\n')" | |
echo "{name}=branch" >> $GITHUB_OUTPUT | |
echo "Branches where this tag exists : $branch." | |
build_wheels: | |
name: Build universal wheels | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: '3.11' | |
- name: Install Python dependencies | |
run: | | |
python3 -m pip install --upgrade pip setuptools wheel | |
- name: Build wheels | |
run: | | |
python3 setup.py bdist_wheel --universal | |
- uses: actions/upload-artifact@v3 | |
with: | |
path: dist | |
build_sdist: | |
name: Build source | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: '3.11' | |
- name: Install Python dependencies | |
run: | | |
python3 -m pip install --upgrade pip setuptools wheel | |
- name: Build sdist | |
run: | | |
python3 setup.py sdist | |
- uses: actions/upload-artifact@v3 | |
with: | |
path: dist/*.tar.gz | |
dist_check: | |
name: Check build with twine | |
runs-on: ubuntu-latest | |
needs: [build_wheels, build_sdist] | |
steps: | |
- uses: actions/setup-python@v5 | |
name: Install Python | |
with: | |
python-version: "3.11" | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install twine | |
- uses: actions/download-artifact@v3 | |
with: | |
name: artifact | |
path: dist | |
- name: Check dist | |
run: | | |
twine check dist/* | |
upload_pypi: | |
name: Upload to PyPI | |
needs: [dist_check] | |
runs-on: ubuntu-latest | |
# upload to PyPI on every tag starting with 'v' | |
if: contains(${{ needs.check.outputs.branch }}, 'main') | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: artifact | |
path: dist | |
- uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.pypi_password }} | |
# upload_pypi: | |
# name: Upload to PyPI | |
# needs: [check-current-branch, build_wheels, build_sdist] | |
# runs-on: ubuntu-latest | |
# if: contains(${{ needs.check.outputs.branch }}, 'main') | |
# environment: | |
# name: pypi | |
# url: https://pypi.org/p/geefcc | |
# permissions: | |
# id-token: write # Mandatory for trusted publishing. | |
# steps: | |
# - uses: actions/download-artifact@v3 | |
# with: | |
# name: artifact | |
# path: dist | |
# - uses: pypa/gh-action-pypi-publish@release/v1 | |
# End |