From d7c3f3e0da78b0fad3578e1c4ab6e166610ea3ab Mon Sep 17 00:00:00 2001 From: Marek Fedorovic Date: Mon, 23 Oct 2023 11:13:55 +1100 Subject: [PATCH] feat: Simulate failure and try uninstall step --- .github/workflows/npm_publish_light.yml | 6 ++++-- .../unpublish-sdk-version.sh | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/npm_publish_light.yml b/.github/workflows/npm_publish_light.yml index e0026cb1..f8636f23 100644 --- a/.github/workflows/npm_publish_light.yml +++ b/.github/workflows/npm_publish_light.yml @@ -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" @@ -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 }} diff --git a/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh b/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh index 0985ba29..6ba1d86e 100755 --- a/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh +++ b/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh @@ -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 @@ -20,7 +22,7 @@ if [ "$versionName" == "" ]; then exit 1 fi -unpublishVersion="$packangeName@$versionName" +unpublishVersion="$packageName@$versionName" echo "Current directory:" pwd @@ -28,9 +30,9 @@ 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" @@ -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 \ No newline at end of file