Delete packages and releases #1
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
name: Delete packages and releases | |
on: | |
workflow_call: | |
inputs: | |
tag: | |
description: 'Tag to delete' | |
required: true | |
type: string | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Tag to delete' | |
required: true | |
permissions: | |
id-token: write | |
contents: write | |
packages: write | |
jobs: | |
delete: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete npm packages | |
continue-on-error: true | |
run: | | |
echo "Deleting all npm packages whose name ends with '-${{inputs.tag}}.0'" | |
VERSION_IDS=($(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/CheckmarxDev/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions | jq '.[]|select(.name | contains("-${{inputs.tag}}.0"))|.id')) | |
for versionId in "${VERSION_IDS[@]}" | |
do | |
echo "Deleting version $versionId..." | |
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/orgs/CheckmarxDev/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions/$versionId" | |
echo "Version $versionId deleted successfully!" | |
done | |
- name: Delete releases and tags | |
continue-on-error: true | |
uses: dev-drprasad/delete-older-releases@dfbe6be2a006e9475dfcbe5b8d201f1824c2a9fe #v0.3.4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
with: | |
keep_latest: 0 | |
delete_tag_pattern: "-${{inputs.tag}}.0" | |
delete_tags: true |