Skip to content

Commit

Permalink
Only upload weekly tag to PyPi when code changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Wittgen committed Aug 27, 2024
1 parent 9a700aa commit 9bf4af1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ jobs:
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: |
# Get SHA hashes for all weekly tags
weekly_sha=$(git tag -l 'w.*' | while read tag; do
git rev-list -n 1 "${tag}"
done)
# Extract the current tag and its SHA
current_tag=${GITHUB_REF#refs/tags/}
current_sha=$(git rev-list -1 "${current_tag}")
# Count occurrences of the current SHA in the weekly SHA list
n=$(echo "${weekly_sha}" | grep -c "${current_sha}")
echo "Current tag ${current_tag} (${current_sha}) SHA found ${n} time(s)"
# Determine whether to skip the upload based on the count
if [ "${n}" -gt 1 ]; then
echo "Skip upload"
echo "skip=true" >> "${GITHUB_ENV}"
else
echo "Enable upload"
echo "skip=false" >> "${GITHUB_ENV}"
fi
pypi_wheel_build:
strategy:
matrix:
Expand Down Expand Up @@ -111,7 +145,8 @@ jobs:
path: dist/*

pipy_upload:
needs: [pypi_sdist_build, pypi_wheel_build]
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
Expand Down

0 comments on commit 9bf4af1

Please sign in to comment.