Skip to content

Commit 2374a02

Browse files
authored
ci: update sdk version in constants file during deploy (#35)
1 parent 77c8977 commit 2374a02

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
3434
env:
3535
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36-
- run: pnpm lerna publish -y --create-release github --ignore-scripts --no-verify-access
36+
- run: pnpm lerna publish -y --create-release github
3737
env:
3838
HUSKY: 0
3939
GH_TOKEN: ${{ secrets.GH_TOKEN }}

packages/clients/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"main": "dist/index.cjs",
1212
"module": "dist/index.js",
1313
"types": "dist/index.d.ts",
14+
"scripts": {
15+
"version": "./scripts/update-constants-file.sh"
16+
},
1417
"files": [
1518
"dist"
1619
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
echo "Updating version in constants.ts"
6+
7+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
8+
PACKAGE_PATH="${SCRIPT_DIR}/../package.json"
9+
CONSTANTS_PATH="${SCRIPT_DIR}/../src/scw/constants.ts"
10+
11+
# Search for the new version
12+
NEW_VERSION=$(node -e "console.log(require('${PACKAGE_PATH}').version);")
13+
[ -z "${NEW_VERSION}" ] && echo "New version cannot be found, abording" && exit 1
14+
echo "Found version: ${NEW_VERSION}"
15+
16+
# Replace the old version with the new one
17+
OLD_LINE_EXP="\(^export const version.*$\)"
18+
NEW_LINE="export const version = 'v${NEW_VERSION}'"
19+
NEW_FILE=$( cat "${CONSTANTS_PATH}" | sed -e "s/${OLD_LINE_EXP}/${NEW_LINE}/" )
20+
if [[ "$NEW_FILE" != *"$NEW_LINE"* ]]; then
21+
echo "New file content doesn't contain expected version:"
22+
echo "${NEW_FILE}"
23+
exit 2
24+
fi
25+
26+
# Copy content to file
27+
echo "${NEW_FILE}" > "${CONSTANTS_PATH}"
28+
echo "Updated version in constants file"
29+
30+
# Add change to commit
31+
git add "${CONSTANTS_PATH}"

0 commit comments

Comments
 (0)