Skip to content

Instantly share code, notes, and snippets.

@wenqiglantz
Created February 25, 2023 20:55
Show Gist options
  • Select an option

  • Save wenqiglantz/1760fe4d5d0c39691dd837bf440a43c2 to your computer and use it in GitHub Desktop.

Select an option

Save wenqiglantz/1760fe4d5d0c39691dd837bf440a43c2 to your computer and use it in GitHub Desktop.
- name: set project version as environment variable
run: |
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Delete lib in github packages so the new version can be added
run: |
set -e
RESPONSE=$(curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.NPM_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/<ORG>/packages/maven/<PACKAGE_NAME>/versions")
echo "$RESPONSE"
# find out the size (number of different versions of the artifact) in the response
RESPONSE_ARRAY_LENGTH=$(echo "$RESPONSE" | jq '. | length')
echo "$RESPONSE_ARRAY_LENGTH"
# Parse the response to find the ID matching the version name
PACKAGE_VERSION_ID=$(echo "$RESPONSE" | jq '.[] | select(.name == "${{ env.PROJECT_VERSION }}") | .id')
echo "$PACKAGE_VERSION_ID"
if [[ "$PACKAGE_VERSION_ID" != "" && "$RESPONSE_ARRAY_LENGTH" == 1 ]]; then
echo "Package found, only has one version. Deleting package..."
DELETE_RESPONSE=$(curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.NPM_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/<ORG>/packages/maven/<PACKAGE_NAME>)
elif [[ "$PACKAGE_VERSION_ID" != "" ]]; then
echo "Package found, multiple versions. Deleting package version matching pom version..."
DELETE_RESPONSE=$(curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.NPM_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/<ORG>/packages/maven/<PACKAGE_NAME>/versions/$PACKAGE_VERSION_ID)
else
echo "Package not found."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment