Skip to content

Commit 651d818

Browse files
committed
mod: error check when bumping versions
1 parent 33c005d commit 651d818

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ci/bump_version.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ if [ ! -f "package.json" ]; then
88
echo "Error: should be run from the root of the repo"
99
exit 1
1010
fi
11-
node ci/version-bump.mjs
11+
node ci/version-bump.mjs
12+
# exit if current-version.txt doesn't exist
13+
if [ ! -f "current-version.txt" ]; then
14+
echo "Error: current-version.txt not found"
15+
exit 1
16+
fi
1217
targetVersion=$(<"current-version.txt") # read the current version from the file
1318
echo "Bumping version to $targetVersion"
1419

@@ -17,3 +22,5 @@ git commit -m "Bump version to $targetVersion"
1722
#git push
1823
git tag -a "$targetVersion" -m "Bump version tag to $targetVersion"
1924
#git push --tags
25+
26+
rm current-version.txt

ci/version-bump.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {readFileSync, writeFileSync} from "fs";
22

33
// This is the version defined in package.json
4-
const targetVersion = process.env.npm_package_version;
4+
const targetVersion = process.env.npm_package_version ?? JSON.parse(readFileSync('./package.json', 'utf-8')).version;
5+
if (targetVersion === undefined || targetVersion === null) {
56

7+
console.error(`target version: ${targetVersion} is invalid`)
8+
process.exit(1)
9+
}
610
// read minAppVersion from manifest.json and bump version to target version
711
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
812
const {minAppVersion} = manifest;
@@ -13,4 +17,4 @@ writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
1317
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
1418
versions[targetVersion] = minAppVersion;
1519
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
16-
writeFileSync("current-version.txt", targetVersion);
20+
writeFileSync("current-version.txt", targetVersion);

0 commit comments

Comments
 (0)