Skip to content

feat: Publish sdk to GH Actions Packages #32

feat: Publish sdk to GH Actions Packages

feat: Publish sdk to GH Actions Packages #32

name: Build and Publish Cohort SDK NPMs
on:
#workflow_call:
push:
env:
SDK_JS_PACKAGE_NAME: "@kindredgroup/cohort_sdk_js"
SDK_CLIENT_PACKAGE_NAME: "@kindredgroup/cohort_sdk_client"
jobs:
npm:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
dirSdkJs: packages/cohort_sdk_js
dirSdkJsClient: cohort_sdk_client
customiseHostCommand: echo "No customizations needed"
name: stable - ${{ matrix.settings.target }} - node@16
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
check-latest: true
registry-url: "https://npm.pkg.github.com"
- name: Customise host image
shell: bash
run: ${{ matrix.settings.customiseHostCommand }}
- name: Setup version for ${{ matrix.settings.dirSdkJs }}
id: sdk-js-version
shell: bash
run: |-
echo "Building SDK JS Library"
echo "NPM_CONFIG_USERCONFIG=$NPM_CONFIG_USERCONFIG"
cat $NPM_CONFIG_USERCONFIG
echo ""
cd ${{ matrix.settings.dirSdkJs }}
pwd
ls -l
npm ci --foreground-scripts
selectNodeName=${{ env.SDK_JS_PACKAGE_NAME }}
currentVersion=$(npm version | yq .$selectNodeName)
currentSha=$(git rev-parse --short HEAD)
newVersion="$currentVersion-$currentSha"
echo "D: selectNodeName=$selectNodeName"
echo "D: currentVersion=$currentVersion"
echo "D: currentSha=$currentSha"
echo "D: newVersion=$newVersion"
npm version $newVersion
echo "SDK_JS_PACKAGE_VERSION=$newVersion" >> "$GITHUB_OUTPUT"
echo ""
- name: Publishing ${{ matrix.settings.dirSdkJs }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |-
cd ${{ matrix.settings.dirSdkJs }}
pwd
ls -l
echo "Current version is"
npm version
npm publish --foreground-scripts
echo ""
- name: Setup version for ${{ matrix.settings.dirSdkJsClient }}
env:
SDK_JS_PACKAGE_VERSION: ${{ steps.sdk-js-version.outputs.SDK_JS_PACKAGE_VERSION }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |-
echo "Building SDK Client"
cd ${{ matrix.settings.dirSdkJsClient }}
pwd
ls -lah
rm package-lock.json || true
echo "Running: npm install "$SDK_JS_PACKAGE_NAME@$SDK_JS_PACKAGE_VERSION" --foreground-scripts"
npm install "$SDK_JS_PACKAGE_NAME@$SDK_JS_PACKAGE_VERSION" --foreground-scripts
selectNodeName=${{ env.SDK_CLIENT_PACKAGE_NAME }}
currentVersion=$(npm version | yq .$selectNodeName)
currentSha=$(git rev-parse --short HEAD)
newVersion="$currentVersion-$currentSha"
echo "D: selectNodeName=$selectNodeName"
echo "D: currentVersion=$currentVersion"
echo "D: currentSha=$currentSha"
echo "D: newVersion=$newVersion"
npm version $newVersion
ls -lah
echo ""
- name: Build and Publishing ${{ matrix.settings.dirSdkJsClient }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |-
cd ${{ matrix.settings.dirSdkJsClient }}
pwd
ls -l
echo "Current version is"
npm version
npm ci --foreground-scripts
npm run build --foreground-scripts
npm publish --foreground-scripts
echo ""