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
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
Generated by ChatGPT
Sure, I'll translate the provided text and the comments within the YAML script into English for you.
Translated Text
Based on your request, if your goal is to use GitHub Actions with
actions/github-script@v7and theoctokitclient to fetch and delete the latest release from a repository, here is an adjusted and regenerated code snippet. This example will first fetch the latest release information for the repository and then delete that release.Explanation of the Code
octokit.rest.repos.getLatestReleasemethod to get information about the latest release of the repository.latestRelease.data.idexists.octokit.rest.repos.deleteReleasemethod to delete the specified release using its ID found inlatestRelease.data.id.Ensure your GitHub Actions workflow configuration file syntax is correct and that you have the necessary permissions to perform these actions. This code should be placed in the appropriate section of your GitHub Actions workflow
.ymlfile.