Skip to content

Instantly share code, notes, and snippets.

@xlionjuan
Created March 30, 2024 21:15
Show Gist options
  • Select an option

  • Save xlionjuan/3273178a112e0bdec6decdc52e860678 to your computer and use it in GitHub Desktop.

Select an option

Save xlionjuan/3273178a112e0bdec6decdc52e860678 to your computer and use it in GitHub Desktop.
Delete old Release with actions/github-script@v7
steps:
- name: Delete old Release
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo
// Fetch the latest release information
const latestRelease = await github.rest.repos.getLatestRelease({
owner,
repo,
});
// Check if the latest release information was successfully retrieved
if (latestRelease && latestRelease.data && latestRelease.data.id) {
// If there is a latest release, then delete it
await github.rest.repos.deleteRelease({
owner,
repo,
release_id: latestRelease.data.id,
});
console.log(`Release id ${latestRelease.data.id} has been deleted.`);
} else {
// If no latest release was found or retrieval failed, output a message
console.log("No latest release found or failed to retrieve it.");
}
@xlionjuan
Copy link
Author

First, I found this action, but it is deprecated and recommend to use github-script, it works, but it is using v4, so I upgrade to v7, than it broke because newer github-script is using octokit/rest.js now, so I provide both getLatestRelease and deleteRelease from the API docs to ChatGPT.
https://github.com/ame-yu/action-delete-latest-release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment