Skip to content

Commit 2cc3e54

Browse files
replace dev-drprasad/delete-older-releases with gh CLI
gh CLI is pre-installed on all GitHub-hosted runners — no external action needed
1 parent 74a8c8d commit 2cc3e54

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

.github/workflows/delete-packages-and-releases.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,42 @@ on:
1414
required: true
1515

1616
permissions:
17-
id-token: write
18-
contents: write
19-
packages: write
20-
17+
contents: read
2118

2219
jobs:
2320
delete:
21+
permissions:
22+
contents: write
23+
packages: write
2424
runs-on: cx-public-ubuntu-x64
2525
steps:
2626

2727
- name: Delete npm packages
2828
continue-on-error: true
29+
env:
30+
INPUT_TAG: ${{ inputs.tag }}
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2932
run: |
33+
echo "Deleting all npm packages whose name ends with '-${INPUT_TAG}.0'"
3034
31-
echo "Deleting all npm packages whose name ends with '-${{inputs.tag}}.0'"
32-
33-
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/Checkmarx/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions | jq '.[]|select(.name | contains("-${{inputs.tag}}.0"))|.id'))
35+
VERSION_IDS=($(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/Checkmarx/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions | jq ".[]|select(.name | contains(\"-${INPUT_TAG}.0\"))|.id"))
3436
3537
for versionId in "${VERSION_IDS[@]}"
3638
do
3739
echo "Deleting version $versionId..."
38-
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/Checkmarx/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions/$versionId"
40+
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/orgs/Checkmarx/packages/npm/ast-cli-javascript-wrapper-runtime-cli/versions/$versionId"
3941
echo "Version $versionId deleted successfully!"
4042
done
4143
4244
- name: Delete releases and tags
4345
continue-on-error: true
44-
uses: dev-drprasad/delete-older-releases@dfbe6be2a006e9475dfcbe5b8d201f1824c2a9fe #v0.3.4
4546
env:
46-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
47-
with:
48-
keep_latest: 0
49-
delete_tag_pattern: "-${{inputs.tag}}.0"
50-
delete_tags: true
47+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
INPUT_TAG: ${{ inputs.tag }}
49+
run: |
50+
gh release list --limit 100 --json tagName \
51+
--jq ".[] | select(.tagName | contains(\"-${INPUT_TAG}.0\")) | .tagName" \
52+
| while IFS= read -r tag; do
53+
echo "Deleting release and tag: $tag"
54+
gh release delete "$tag" --yes --cleanup-tag || true
55+
done

0 commit comments

Comments
 (0)