From 38485f6754cdbb8988f70b9ea3bd227e6701a4aa Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Wed, 27 Jul 2022 20:58:17 +0200 Subject: [PATCH] ci: update sdk version in constants file during deploy --- .github/workflows/deploy.yml | 2 +- packages/clients/package.json | 3 ++ .../clients/scripts/update-constants-file.sh | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 packages/clients/scripts/update-constants-file.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f08da3870..a64f414bb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: - run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: pnpm lerna publish -y --create-release github --ignore-scripts --no-verify-access + - run: pnpm lerna publish -y --create-release github env: HUSKY: 0 GH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/packages/clients/package.json b/packages/clients/package.json index 1c60c10b4..18dc12449 100644 --- a/packages/clients/package.json +++ b/packages/clients/package.json @@ -11,6 +11,9 @@ "main": "dist/index.cjs", "module": "dist/index.js", "types": "dist/index.d.ts", + "scripts": { + "version": "./scripts/update-constants-file.sh" + }, "files": [ "dist" ], diff --git a/packages/clients/scripts/update-constants-file.sh b/packages/clients/scripts/update-constants-file.sh new file mode 100755 index 000000000..ee04aac95 --- /dev/null +++ b/packages/clients/scripts/update-constants-file.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -e + +echo "Updating version in constants.ts" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PACKAGE_PATH="${SCRIPT_DIR}/../package.json" +CONSTANTS_PATH="${SCRIPT_DIR}/../src/scw/constants.ts" + +# Search for the new version +NEW_VERSION=$(node -e "console.log(require('${PACKAGE_PATH}').version);") +[ -z "${NEW_VERSION}" ] && echo "New version cannot be found, abording" && exit 1 +echo "Found version: ${NEW_VERSION}" + +# Replace the old version with the new one +OLD_LINE_EXP="\(^export const version.*$\)" +NEW_LINE="export const version = 'v${NEW_VERSION}'" +NEW_FILE=$( cat "${CONSTANTS_PATH}" | sed -e "s/${OLD_LINE_EXP}/${NEW_LINE}/" ) +if [[ "$NEW_FILE" != *"$NEW_LINE"* ]]; then + echo "New file content doesn't contain expected version:" + echo "${NEW_FILE}" + exit 2 +fi + +# Copy content to file +echo "${NEW_FILE}" > "${CONSTANTS_PATH}" +echo "Updated version in constants file" + +# Add change to commit +git add "${CONSTANTS_PATH}"