Skip to content

Commit d08b2e1

Browse files
chore: use gh api for package deletion (#107)
1 parent f1d2152 commit d08b2e1

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

.github/workflows/unpublish-rc-manual.yaml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,47 @@ jobs:
5656
if: github.event.inputs.action_type == 'unpublish' && github.event.inputs.version != ''
5757
run: |
5858
VERSION="${{ github.event.inputs.version }}"
59-
echo "🗑️ Attempting to unpublish @envoy/envoy-integrations-sdk@${VERSION}"
59+
PACKAGE_NAME="envoy-integrations-sdk"
60+
ORG="envoy"
6061
61-
if npm unpublish @envoy/envoy-integrations-sdk@${VERSION} --force; then
62-
echo "✅ Successfully unpublished ${VERSION}" >> $GITHUB_STEP_SUMMARY
62+
echo "🗑️ Attempting to delete @${ORG}/${PACKAGE_NAME}@${VERSION}"
63+
64+
# Get all package versions to find the version ID
65+
echo "Fetching package versions..."
66+
VERSIONS_JSON=$(gh api \
67+
-H "Accept: application/vnd.github+json" \
68+
-H "X-GitHub-Api-Version: 2022-11-28" \
69+
"/orgs/${ORG}/packages/npm/${PACKAGE_NAME}/versions")
70+
71+
# Find the version ID for the specific version
72+
VERSION_ID=$(echo "$VERSIONS_JSON" | jq -r ".[] | select(.name == \"${VERSION}\") | .id")
73+
74+
if [ -z "$VERSION_ID" ] || [ "$VERSION_ID" == "null" ]; then
75+
echo "❌ Failed to find version ${VERSION}" >> $GITHUB_STEP_SUMMARY
76+
echo "" >> $GITHUB_STEP_SUMMARY
77+
echo "Version may not exist or may already be deleted." >> $GITHUB_STEP_SUMMARY
78+
exit 1
79+
fi
80+
81+
echo "Found version ID: ${VERSION_ID}"
82+
83+
# Delete the package version using GitHub API
84+
if gh api \
85+
--method DELETE \
86+
-H "Accept: application/vnd.github+json" \
87+
-H "X-GitHub-Api-Version: 2022-11-28" \
88+
"/orgs/${ORG}/packages/npm/${PACKAGE_NAME}/versions/${VERSION_ID}"; then
89+
echo "✅ Successfully deleted ${VERSION}" >> $GITHUB_STEP_SUMMARY
6390
else
64-
echo "❌ Failed to unpublish ${VERSION}" >> $GITHUB_STEP_SUMMARY
91+
echo "❌ Failed to delete ${VERSION}" >> $GITHUB_STEP_SUMMARY
6592
echo "" >> $GITHUB_STEP_SUMMARY
6693
echo "This may fail if:" >> $GITHUB_STEP_SUMMARY
67-
echo "- Version doesn't exist" >> $GITHUB_STEP_SUMMARY
68-
echo "- Other packages depend on it" >> $GITHUB_STEP_SUMMARY
69-
echo "- It had >300 downloads in last week" >> $GITHUB_STEP_SUMMARY
7094
echo "- Insufficient permissions" >> $GITHUB_STEP_SUMMARY
71-
echo "" >> $GITHUB_STEP_SUMMARY
72-
echo "Consider using 'deprecate' action instead." >> $GITHUB_STEP_SUMMARY
95+
echo "- Package version is in use" >> $GITHUB_STEP_SUMMARY
7396
exit 1
7497
fi
7598
env:
76-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77100

78101
- name: Deprecate RC version
79102
if: github.event.inputs.action_type == 'deprecate' && github.event.inputs.version != ''

0 commit comments

Comments
 (0)