Skip to content

Commit 60d9ffa

Browse files
chore(travis): set correct version in package.json
The environment variable `RELEASE_BUILD` is used in Jenkins job, when CLI has to be build with strict official version. It's been deleted in a previous commit, which broke this logic - get it back and add comment why we need it. Also ensure Travis will not push strict version in `npm` by calling `set_package_version` in the travisPack grunt task. In case it is not called, the Travis job, that is executed on push in master/release/release-patch branch, will execute `npm publish` only (as the `travisPack` will not do anything). The prepack script will trigger `grunt prepare` logic, which will not change the version in package.json, so it will remain `5.1.1` for example. We cannot change the version in the prepack script (i.e. to call `set_package_version` in the `grunt prepare` task, as npm has problem with this approach - it produces `.tgz` of the built package with correct version, however it still tries to publish the version that was originally in the package.json.
1 parent ae83e0a commit 60d9ffa

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Gruntfile.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,23 @@ module.exports = function (grunt) {
164164
grunt.loadNpmTasks("grunt-template");
165165

166166
grunt.registerTask("set_package_version", function (version) {
167+
// NOTE: DO NOT call this task in npm's prepack script - it will change the version in package.json,
168+
// but npm will still try to publish the version that was originally specified in the package.json/
169+
// Also this may break some Jenkins builds as the produced package will have unexpected name.
167170
var buildVersion = version !== undefined ? version : buildNumber;
168171
if (process.env["BUILD_CAUSE_GHPRBCAUSE"]) {
169172
buildVersion = "PR" + buildVersion;
170173
}
171174

172175
var packageJson = grunt.file.readJSON("package.json");
173176
var versionParts = packageJson.version.split("-");
174-
versionParts[1] = buildVersion;
175-
packageJson.version = versionParts.join("-");
177+
178+
// The env is used in Jenkins job to produce package that will be releasd with "latest" tag in npm (i.e. strict version).
179+
if (!process.env["RELEASE_BUILD"]) {
180+
versionParts[1] = buildVersion;
181+
packageJson.version = versionParts.join("-");
182+
}
183+
176184
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
177185
});
178186

@@ -221,8 +229,10 @@ module.exports = function (grunt) {
221229
if (travis && process.env.TRAVIS_PULL_REQUEST_BRANCH) {
222230
return grunt.task.run("pack");
223231
}
224-
225-
console.log(`Skipping travisPack step as the current build is not from PR, so it will be packed from the deploy provider.`);
232+
233+
// Set correct version in Travis job, so the deploy will not publish strict version (for example 5.2.0).
234+
grunt.task.run("set_package_version");
235+
console.log(`Skipping pack step as the current build is not from PR, so it will be packed from the deploy provider.`);
226236
});
227237
grunt.registerTask("lint", ["tslint:build"]);
228238
grunt.registerTask("all", ["clean", "test", "lint"]);

0 commit comments

Comments
 (0)