Skip to content

Remove Unused Tags

Remove Unused Tags #4

Workflow file for this run

name: Remove Unused Tags
on:
workflow_dispatch: # Allows manual trigger of the workflow.
jobs:
clean_unused_tags:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
- name: Get All Tags
id: get_tags
run: |
git fetch --tags
git tag -l > all_tags.txt
echo "Tags fetched:"
cat all_tags.txt
- name: Get Releases
id: get_releases
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/${{ github.repository }}/releases --paginate -q '.[].tag_name' > releases_tags.txt
echo "Release tags fetched:"
cat releases_tags.txt
- name: Compare Tags to Releases and Delete Unused Tags
run: |
# Identify unused tags
UNUSED_TAGS=$(grep -Fvx -f releases_tags.txt all_tags.txt || true)
echo "Unused Tags:"
echo "$UNUSED_TAGS"
# Delete unused tags locally and remotely
for TAG in $UNUSED_TAGS; do
echo "Deleting unused tag: $TAG"
git tag -d "$TAG" || echo "Failed to delete local tag $TAG"
git push --delete origin "$TAG" || echo "Failed to delete remote tag $TAG"
done
- name: Cleanup
run: |
rm -f all_tags.txt releases_tags.txt