DM-42695: Only upload weekly tag to PyPi when code changed #597
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
name: build_and_test | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "*" | |
pull_request: | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Need to clone everything to determine version from git. | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" | |
cache-dependency-path: "setup.cfg" | |
allow-prereleases: true | |
- name: Build and install | |
run: | | |
python -m pip install --upgrade pip setuptools uv | |
uv pip install --system .[yaml,test] | |
- name: Run tests | |
run: pytest -r a -v | |
pypi_sdist_build: | |
runs-on: ubuntu-latest | |
needs: [build_and_test] | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.8 | |
cache: "pip" | |
cache-dependency-path: "setup.cfg" | |
- name: Install dependencies | |
run: | | |
pip install --upgrade setuptools wheel build | |
- name: Build and create distribution | |
run: | | |
python -m build --sdist | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: sphgeom-sdist | |
path: dist/* | |
check-changes: | |
outputs: | |
skip: ${{ steps.check.outputs.skip }} | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if weekly changed | |
id: check | |
run: | | |
prev_tag=$(git tag -l 'w.*' | sort | tail -2 | head -1) | |
prev_sha=$(git rev-list -1 "$prev_tag") | |
echo "Previous tag ${prev_tag} (${prev_sha})" | |
current_tag=${GITHUB_REF#refs/tags/} | |
current_sha=$(git rev-list -1 "$current_tag") | |
echo "Current tag ${current_tag} (${current_sha})" | |
if [ "$current_sha" = "$prev_sha" ]; then | |
echo "Skip upload" | |
echo "skip=true" >> "$GITHUB_ENV" | |
else | |
echo "Enable upload" | |
echo "skip=false" >> "$GITHUB_ENV" | |
fi | |
pypi_wheel_build: | |
strategy: | |
matrix: | |
os: ["ubuntu-latest", "macos-12"] | |
runs-on: ${{ matrix.os }} | |
needs: [build_and_test] | |
if: startsWith(github.ref, 'refs/tags/') | |
env: | |
CIBW_BUILD: "cp3{8,9,10,11,12,13}-{manylinux_x86_64,manylinux_aarch64,macosx_arm64,macosx_x86_64}" | |
CIBW_ARCHS_MACOS: "x86_64 arm64" | |
# use line below to enable aarch64 builds | |
# CIBW_ARCHS_LINUX: "auto aarch64" | |
CIBW_ARCHS_LINUX: "auto" | |
steps: | |
# uncomment when building aarch64 | |
# - name: Set up QEMU | |
# uses: docker/setup-qemu-action@v2 | |
# if: runner.os == 'Linux' | |
# with: | |
# platforms: arm64 | |
- uses: actions/checkout@v4 | |
with: | |
# Need to clone everything to embed the versiona | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
pip install --upgrade setuptools wheel cibuildwheel | |
- name: Build and create distribution | |
run: | | |
python -m cibuildwheel --output-dir dist | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: sphgeom-${{ matrix.os }} | |
path: dist/* | |
pipy_upload: | |
needs: [pypi_sdist_build, pypi_wheel_build, check-changes] | |
if: "!startsWith(github.ref, 'refs/tags/w.') || needs.check-changes.outputs.skip == 'false'" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
pattern: sphgeom-* | |
merge-multiple: true | |
- uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_UPLOADS }} |