diff --git a/.github/workflows/cleanup-prerelease-tags.yml b/.github/workflows/cleanup-prerelease-tags.yml new file mode 100644 index 00000000..522f04cf --- /dev/null +++ b/.github/workflows/cleanup-prerelease-tags.yml @@ -0,0 +1,55 @@ +name: Preview prerelease tag cleanup + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Resolve version metadata + id: version + run: | + SHOULD_RUN=true + VERSION="all-prerelease-tags" + + echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + if [[ "$VERSION" =~ ^v[0-9]+(\.[0-9]+)*$ ]]; then + echo "is_prerelease=false" >> "$GITHUB_OUTPUT" + else + echo "is_prerelease=true" >> "$GITHUB_OUTPUT" + fi + + - name: Preview prerelease releases and tags + if: steps.version.outputs.should_run == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mapfile -t TAGS < <(git tag --list 'v*' | sort -V) + MATCHED=0 + + for TAG in "${TAGS[@]}"; do + if [[ "$TAG" =~ ^v[0-9]+(\.[0-9]+)*$ ]]; then + echo "Keep formal release tag: $TAG" + continue + fi + + if gh release view "$TAG" >/dev/null 2>&1; then + echo "Would delete prerelease tag and release: $TAG" + else + echo "Would delete prerelease tag only: $TAG (no GitHub Release found)" + fi + + MATCHED=$((MATCHED + 1)) + done + + echo "Found $MATCHED prerelease tag(s) that would be deleted."