Skip to content

Commit

Permalink
feat: Simulate failure and try uninstall step
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarek-kindred committed Oct 23, 2023
1 parent aa42af6 commit d7c3f3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/npm_publish_light.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ on:
push:
env:
SDK_JS_PACKAGE_NAME: "@kindredgroup/cohort_sdk_js"
SDK_JS_PACKAGE_NAME_SHORT: "cohort_sdk_js"
SDK_CLIENT_PACKAGE_NAME: "@kindredgroup/cohort_sdk_client"
SDK_CLIENT_PACKAGE_NAME_SHORT: "cohort_sdk_client"
REGISTRY: "https://npm.pkg.github.com"
API_URL: "https://api.github.com/orgs/kindredgroup/packages/npm"
API_VERSION: "2022-11-28"
Expand Down Expand Up @@ -127,11 +129,11 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
cd ${{ matrix.settings.dirSdkJsClient }}
../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_CLIENT_PACKAGE_NAME" "$SDK_CLIENT_PACKAGE_VERSION"
../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_CLIENT_PACKAGE_NAME_SHORT" "$SDK_CLIENT_PACKAGE_VERSION"
echo ""
cd ${{ matrix.settings.dirSdkJs }}
../../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_JS_PACKAGE_NAME" "$SDK_JS_PACKAGE_VERSION"
../../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_JS_PACKAGE_NAME_SHORT" "$SDK_JS_PACKAGE_VERSION"
echo ""
- name: Build ${{ matrix.settings.dirCohortReplicator }}
Expand Down
19 changes: 11 additions & 8 deletions scripts/cohort/github-actions-ci/unpublish-sdk-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# This script is designed to be invoked from GitHub Actions CI only.
#
#
# Unpublishes given NPM from GitHub Packages NPM repository. Since simple npm unpublish
# is not supported by GitHub Packages we use "DELETE ../versions/$id" function
# from GitHub REST API
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

echo Executing "$0"

packangeName=$1
packageName=$1
versionName=$2

if [ "$packangeName" == "" ]; then
if [ "$packageName" == "" ]; then
echo "Missing the first parameter - package name to be unpublished"
exit 1
fi
Expand All @@ -20,17 +22,17 @@ if [ "$versionName" == "" ]; then
exit 1
fi

unpublishVersion="$packangeName@$versionName"
unpublishVersion="$packageName@$versionName"

echo "Current directory:"
pwd
ls -l
echo "Current version is"
npm version
echo "Unpublishing faulty version: $unpublishVersion"
allVersionsArray=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $NODE_AUTH_TOKEN" -H "X-GitHub-Api-Version: $API_VERSION" "$API_URL/$packangeName/versions")
allVersionsArray=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $NODE_AUTH_TOKEN" -H "X-GitHub-Api-Version: $API_VERSION" "$API_URL/$packageName/versions")
echo $allVersionsArray > ./tmp_all_versions.json
lookupPackageVersionId=$(echo "$allVersionsArray" | yq '.[] | select(.name=="$unpublishVersion") | .id')
lookupPackageVersionId=$(echo "$allVersionsArray" | yq '.[] | select(.name=="$versionName") | .id')
if [ "$lookupPackageVersionId" == "" ];
then
echo "E: Unable to find package version id"
Expand All @@ -39,10 +41,11 @@ then
rm ./tmp_all_versions.json
echo ""
echo "D: curl command used:"
echo "D: curl -L -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ...' -H 'X-GitHub-Api-Version: $API_VERSION' $API_URL/$packangeName/versions"
echo "D: curl -L -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ...' -H 'X-GitHub-Api-Version: $API_VERSION' $API_URL/$packageName/versions"
echo "existing with error..."
exit 1
else
echo "Deleting $lookupPackageVersionId of $unpublishVersion"
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $NODE_AUTH_TOKEN" -H "X-GitHub-Api-Version: $API_VERSION" "$API_URL/$packangeName/versions/$lookupPackageVersionId"
echo "D: curl -L -X DELETE -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ...' -H 'X-GitHub-Api-Version: $API_VERSION' $API_URL/$packageName/versions/$lookupPackageVersionId"
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $NODE_AUTH_TOKEN" -H "X-GitHub-Api-Version: $API_VERSION" "$API_URL/$packageName/versions/$lookupPackageVersionId"
fi

0 comments on commit d7c3f3e

Please sign in to comment.