Skip to content

Commit

Permalink
feat: Implement uninstall step in the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarek-kindred committed Oct 23, 2023
1 parent f40de62 commit 15da225
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
47 changes: 43 additions & 4 deletions .github/workflows/npm_publish_light.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
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"
61 changes: 61 additions & 0 deletions scripts/cohort/github-actions-ci/unpublish-sdk-version.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15da225

Please sign in to comment.