Created
March 30, 2024 21:15
-
-
Save xlionjuan/3273178a112e0bdec6decdc52e860678 to your computer and use it in GitHub Desktop.
Delete old Release with actions/github-script@v7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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."); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 newergithub-scriptis using octokit/rest.js now, so I provide bothgetLatestReleaseanddeleteReleasefrom the API docs to ChatGPT.https://github.com/ame-yu/action-delete-latest-release