Skip to content

Instantly share code, notes, and snippets.

@airvzxf
Created August 6, 2023 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airvzxf/318dbaeb9d8773ead1a69ea50eac6842 to your computer and use it in GitHub Desktop.
Save airvzxf/318dbaeb9d8773ead1a69ea50eac6842 to your computer and use it in GitHub Desktop.
In GitHub it remove all the actions, tags and releases. Furthermore, it create a new release. It use the 'gh' command-line tool.
#!/usr/bin/env bash
set +xve
RELEASE_TAG='v1.0.0'
REPOSITORY_ID='airvzxf/archlinux-brightness-xrandr'
GITHUB_ACTIONS=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/actions/runs" |
jq '.workflow_runs[] | .id'
)
echo "GITHUB_ACTIONS: ${GITHUB_ACTIONS//[$'\n']/ }"
for action_id in ${GITHUB_ACTIONS}; do
echo "action_id: ${action_id}"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/actions/runs/${action_id}"
done
GITHUB_RELEASES=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/releases" |
jq '.[] | .id'
)
echo "GITHUB_RELEASES: ${GITHUB_RELEASES//[$'\n']/ }"
for release_id in ${GITHUB_RELEASES}; do
echo "release_id: ${release_id}"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/releases/${release_id}"
done
GITHUB_TAGS=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/tags" |
jq --raw-output '.[] | .name'
)
echo "GITHUB_TAGS: ${GITHUB_TAGS//[$'\n']/ }"
for tag_id in ${GITHUB_TAGS}; do
echo "tag_id: ${tag_id}"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${REPOSITORY_ID}/git/refs/tags/${tag_id}"
done
gh release create "${RELEASE_TAG}" --latest --target main --title "Release ${RELEASE_TAG}" --generate-notes --repo "${REPOSITORY_ID}"
sleep 2
gh release edit "${RELEASE_TAG}" --draft=false --latest --repo "${REPOSITORY_ID}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment