diff --git a/.github/workflows/delete-drafts.yml b/.github/workflows/delete-drafts.yml index 86b183c..eca6269 100644 --- a/.github/workflows/delete-drafts.yml +++ b/.github/workflows/delete-drafts.yml @@ -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 }} + + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 8ef93a3..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,53 +0,0 @@ -# This workflow is useful if you want to automate the process of: -# -# a) Creating a new prelease when you push a new tag with a "v" prefix (version). -# -# This type of prerelease is meant to be used for production: alpha, beta, rc, etc. types of releases. -# After the prerelease is created, you need to make your changes on the release page at the relevant -# Github page and publish your release. -# -# b) Creating/updating the "latest" prerelease when you push to your default branch. -# -# This type of prelease is useful to make your bleeding-edge binaries available to advanced users. -# -# The workflow will not run if there is no tag pushed with a "v" prefix and no change pushed to your -# default branch. -on: push - -jobs: - might_release: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Prepare Release Variables - id: vars - uses: ignite/cli/actions/release/vars@main - - - name: Issue Release Assets - uses: ignite/cli/actions/cli@main - if: ${{ steps.vars.outputs.should_release == 'true' }} - with: - args: chain build --release --release.prefix ${{ steps.vars.outputs.tarball_prefix }} -t linux:amd64 -t darwin:amd64 -t darwin:arm64 - - - name: Delete the "latest" Release - uses: dev-drprasad/delete-tag-and-release@v0.2.1 - if: ${{ steps.vars.outputs.is_release_type_latest == 'true' }} - with: - tag_name: ${{ steps.vars.outputs.tag_name }} - delete_release: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish the Release - uses: softprops/action-gh-release@v1 - if: ${{ steps.vars.outputs.should_release == 'true' }} - with: - tag_name: ${{ steps.vars.outputs.tag_name }} - files: release/* - prerelease: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/clean_git_repo.sh b/clean_git_repo.sh new file mode 100755 index 0000000..b15508a --- /dev/null +++ b/clean_git_repo.sh @@ -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 " + 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"