diff --git a/.github/workflows/npm_publish_light.yml b/.github/workflows/npm_publish_light.yml index 93b87820..61f96e49 100644 --- a/.github/workflows/npm_publish_light.yml +++ b/.github/workflows/npm_publish_light.yml @@ -4,14 +4,19 @@ # could build it locally. # Performs a basic build test by installing "cohort_sdk_client" into # "cohort_banking_initiator_js", "cohort_banking_replicator_js" apps and then builds apps. +# If tests building of initiator and replicator fails then SDK version is removed from NPM. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name: Build and Publish Cohort SDK NPMs on: workflow_dispatch: 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://github.com/gitapi/orgs/kindredgroup/packages/npm" + API_VERSION: "2022-11-28" jobs: npm: strategy: @@ -52,7 +57,7 @@ jobs: pwd ls -l npm ci --foreground-scripts - ../../scripts/github-actions-ci/set-npm-dev-version.sh ${{ env.SDK_JS_PACKAGE_NAME }} "SDK_JS_PACKAGE_VERSION" + ../../scripts/cohort/github-actions-ci/set-npm-dev-version.sh ${{ env.SDK_JS_PACKAGE_NAME }} "SDK_JS_PACKAGE_VERSION" echo "" - name: Build and Publish ${{ matrix.settings.dirSdkJs }} @@ -82,7 +87,7 @@ jobs: rm package-lock.json || true echo "D: npm install $SDK_JS_PACKAGE_NAME@$SDK_JS_PACKAGE_VERSION --foreground-scripts" npm install "$SDK_JS_PACKAGE_NAME@$SDK_JS_PACKAGE_VERSION" --foreground-scripts - ../scripts/github-actions-ci/set-npm-dev-version.sh ${{ env.SDK_CLIENT_PACKAGE_NAME }} "SDK_CLIENT_PACKAGE_VERSION" + ../scripts/cohort/github-actions-ci/set-npm-dev-version.sh ${{ env.SDK_CLIENT_PACKAGE_NAME }} "SDK_CLIENT_PACKAGE_VERSION" echo "" - name: Build and Publish ${{ matrix.settings.dirSdkJsClient }} NPM @@ -115,6 +120,23 @@ jobs: npm install "$SDK_CLIENT_PACKAGE_NAME@$SDK_CLIENT_PACKAGE_VERSION" --foreground-scripts npm run build --foreground-scripts + - name: Unublish SDK NPMs on failure + if: ${{ failure() }} + shell: bash + env: + SDK_JS_PACKAGE_VERSION: ${{ steps.sdk-js-version.outputs.SDK_JS_PACKAGE_VERSION }} + SDK_CLIENT_PACKAGE_VERSION: ${{ steps.sdk-client-version.outputs.SDK_CLIENT_PACKAGE_VERSION }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: |- + currentDir=$(pwd) + cd ${{ matrix.settings.dirSdkJsClient }} + ../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_CLIENT_PACKAGE_NAME_SHORT" "$SDK_CLIENT_PACKAGE_VERSION" + echo "" + cd $currentDir + + cd ${{ matrix.settings.dirSdkJs }} + ../../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_JS_PACKAGE_NAME_SHORT" "$SDK_JS_PACKAGE_VERSION" + - name: Build ${{ matrix.settings.dirCohortReplicator }} env: SDK_CLIENT_PACKAGE_VERSION: ${{ steps.sdk-client-version.outputs.SDK_CLIENT_PACKAGE_VERSION }} @@ -128,4 +150,21 @@ jobs: rm package-lock.json || true echo "D: npm install $SDK_CLIENT_PACKAGE_NAME@$SDK_CLIENT_PACKAGE_VERSION --foreground-scripts" npm install "$SDK_CLIENT_PACKAGE_NAME@$SDK_CLIENT_PACKAGE_VERSION" --foreground-scripts - npm run build --foreground-scripts \ No newline at end of file + npm run build --foreground-scripts + + - name: Unublish SDK NPMs on failure + if: ${{ failure() }} + shell: bash + env: + SDK_JS_PACKAGE_VERSION: ${{ steps.sdk-js-version.outputs.SDK_JS_PACKAGE_VERSION }} + SDK_CLIENT_PACKAGE_VERSION: ${{ steps.sdk-client-version.outputs.SDK_CLIENT_PACKAGE_VERSION }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: |- + currentDir=$(pwd) + cd ${{ matrix.settings.dirSdkJsClient }} + ../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_CLIENT_PACKAGE_NAME_SHORT" "$SDK_CLIENT_PACKAGE_VERSION" + echo "" + cd $currentDir + + cd ${{ matrix.settings.dirSdkJs }} + ../../scripts/cohort/github-actions-ci/unpublish-sdk-version.sh "$SDK_JS_PACKAGE_NAME_SHORT" "$SDK_JS_PACKAGE_VERSION" \ No newline at end of file diff --git a/scripts/github-actions-ci/set-npm-dev-version.sh b/scripts/cohort/github-actions-ci/set-npm-dev-version.sh similarity index 100% rename from scripts/github-actions-ci/set-npm-dev-version.sh rename to scripts/cohort/github-actions-ci/set-npm-dev-version.sh diff --git a/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh b/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh new file mode 100755 index 00000000..e7bfb9db --- /dev/null +++ b/scripts/cohort/github-actions-ci/unpublish-sdk-version.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# 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" + +packageName=$1 +versionName=$2 + +if [ "$packageName" == "" ]; then + echo "Missing the first parameter - package name to be unpublished" + exit 1 +fi + +if [ "$versionName" == "" ]; then + echo "Missing the second parameter - version name to be unpublished" + exit 1 +fi + +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/$packageName/versions") +echo $allVersionsArray > ./tmp_all_versions.json +lookupPackageVersionId=$(echo "$allVersionsArray" | jq --arg versionName "$versionName" '.[] | select(.name == $versionName) | .id') +if [ "$lookupPackageVersionId" == "" ]; +then + echo "E: Unable to find package version id" + echo "D: allVersionsArray=" + cat ./tmp_all_versions.json + + # echo "" + # echo "D: echo allVersionsArray | yq .[]" + # echo "$allVersionsArray" | jq '.[]' + # echo "" + # echo "D: versionName=$versionName" + # echo "D: echo allVersionsArray | yq .[] | select(.name == versionName)" + # echo "$allVersionsArray" | jq --arg versionName "$versionName" '.[] | select(.name == $versionName)' + # echo "" + # echo "D: full jq command result" + # echo "$allVersionsArray" | jq --arg versionName "$versionName" '.[] | select(.name == $versionName) | .id' + + 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/$packageName/versions" +else + echo "Deleting $lookupPackageVersionId of $unpublishVersion" + 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