Skip to content

Commit

Permalink
use correct repo for delete drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
dekm committed Nov 18, 2023
1 parent c08a759 commit e2eaaa0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 55 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/delete-drafts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
delete-draft-releases:
runs-on: ubuntu-latest
steps:
- name: Delete Draft Releases
uses: dev-drprasad/delete-draft-releases@v0.2.0
- name: Delete Draft Releases
uses: hugo19941994/delete-draft-releases@v1.0.1
with:
delete_tags: true # Set this to false if you don't want to delete the tags associated with the drafts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


53 changes: 0 additions & 53 deletions .github/workflows/release.yml

This file was deleted.

42 changes: 42 additions & 0 deletions clean_git_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Check if both tag and repo are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Please provide a tag to keep and the repository name. Usage: $0 <tag-to-keep> <repository-name>"
exit 1
fi

TAG_TO_KEEP=$1
GITHUB_REPO=$2 # Repository name in 'username/repo' format

# Function to delete tag
delete_tag() {
local tag=$1
git tag -d "$tag" # Delete tag locally
git push origin --delete "$tag" # Delete tag remotely
}

# Function to delete GitHub release
delete_release() {
local tag=$1
# Get release ID by tag
local release_id=$(curl -s \
"https://api.github.com/repos/$GITHUB_REPO/releases/tags/$tag" |
jq -r '.id')

# If release exists, delete it
if [ "$release_id" != "null" ]; then
curl -s -X DELETE \
"https://api.github.com/repos/$GITHUB_REPO/releases/$release_id"
fi
}

echo "All draft releases deleted."
# Get all tags, exclude the one to keep, and delete the rest
git fetch --tags
git tag | grep -v "$TAG_TO_KEEP" | while read -r tag; do
delete_release "$tag"
delete_tag "$tag"
done

echo "All tags and corresponding releases deleted except for $TAG_TO_KEEP in repository $GITHUB_REPO"

0 comments on commit e2eaaa0

Please sign in to comment.