From f8af8f10facddecbd06b075323e20c701b40e332 Mon Sep 17 00:00:00 2001 From: Matthias Wittgen Date: Tue, 20 Aug 2024 16:35:57 -0700 Subject: [PATCH] Only upload weekly tag to PyPi when code changed --- .github/workflows/build.yaml | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9456158..cfdf989 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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_OUTPUT}" + else + echo "Enable upload" + echo "skip=false" >> "${GITHUB_OUTPUT}" + fi + pypi_wheel_build: strategy: matrix: @@ -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