Skip to content

Commit

Permalink
Actions for PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed May 23, 2024
1 parent 4ab8494 commit 0580685
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions .github/workflows/wheel-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@ name: Build wheel and upload to PyPI
# Publish when a (published) GitHub Release is created
on:
push:
branches:
- master
tags:
- "v*"
release:

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
Expand All @@ -25,7 +45,7 @@ jobs:
python-version: '3.11'
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip wheel setuptools
python3 -m pip install --upgrade pip setuptools wheel
- name: Build wheels
run: |
python3 setup.py bdist_wheel --universal
Expand All @@ -38,17 +58,16 @@ jobs:
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: |
python -m pip install --upgrade pip setuptools
python3 -m pip install --upgrade pip setuptools wheel
- name: Build sdist
run: |
python setup.py sdist
python3 setup.py sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
Expand All @@ -58,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist]
steps:
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.11"
Expand All @@ -76,18 +95,19 @@ jobs:
upload_pypi:
name: Upload to PyPI
needs: [dist_check]
needs: [check-current-branch, build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
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@v2
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- uses: pypa/gh-action-pypi-publish@release/v1

# End

0 comments on commit 0580685

Please sign in to comment.