Skip to content

Commit 857ddb7

Browse files
chore: fix travis build of next/rc/release-patch versions
Currently the Travis build of `next`, `rc` and `release-patch` versions takes way too long as the packaging and execution of unit tests is done twice - first time from `grunt pack` execution inside the script and the second time from the npm deploy provider. To fix this introduce new Grunt task - `travisPack` - it checks if `--travisBranch=<branch name>` is passed and in case it is one of the branches from which we'll release the package, the grunt pack task is skipped. Pass the `--travisBranch` option only to `grunt pack` command in the `.travis.yml` script section, so it will be skipped, but the one from npm deploy step will still be executed. Also delete some unused and not needed logic.
1 parent 1a08b52 commit 857ddb7

6 files changed

Lines changed: 36 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
!vendor/*.js
77
!resources/**
88
*.js.map
9-
9+
!.travis/**/*
1010
coverage
1111
lib-cov
1212
*.seed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ scratch/
3030
.travis.yml
3131
docs/html/
3232
dev/
33+
34+
.travis/**/*

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ before_script:
1919
- gem install xcodeproj
2020
- gem install cocoapods
2121
- npm install grunt
22-
- node_modules/.bin/grunt enableScripts:false
23-
- grunt rebuild
24-
- "./bin/nativescript error-reporting disable"
25-
- "./bin/nativescript usage-reporting disable"
26-
- npm test
27-
- node_modules/.bin/grunt enableScripts:true
2822
script:
29-
- node_modules/.bin/grunt lint && node_modules/.bin/grunt pack --no-color
23+
- node_modules/.bin/grunt lint && node_modules/.bin/grunt travisPack --travisBranch=$TRAVIS_PULL_REQUEST_BRANCH --no-color
3024
before_deploy:
3125
- node .travis/add-publishConfig.js $TRAVIS_BRANCH
3226
deploy:

.travis/add-publishConfig.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ if (!branch) {
1616
process.exit(1);
1717
}
1818

19-
switch (branch) {
20-
case "release":
21-
packageDef.publishConfig.tag = "rc";
22-
break;
23-
case "release-patch":
24-
packageDef.publishConfig.tag = "patch";
25-
break;
26-
case "master":
27-
packageDef.publishConfig.tag = "next";
28-
break;
29-
default:
30-
throw new Error(`Unable to publish as the branch ${branch} does not have corresponding tag. Supported branches are master (next tag), release (rc tag) and release-patch (patch tag)`);
19+
const releaseBranches = require("./travis-release-branches").releaseBranches;
20+
const tag = releaseBranches[branch];
21+
if (!tag) {
22+
throw new Error(`Unable to publish as the branch ${branch} does not have corresponding tag. Supported branches are ${JSON.stringify(releaseBranches, null, 2)}`);
3123
}
3224

25+
packageDef.publishConfig.tag = tag;
26+
3327
const newContent = JSON.stringify(packageDef, null, " ");
3428
fsModule.writeFileSync(path, newContent, fileOptions);

.travis/travis-release-branches.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const releaseBranches = {
2+
"master": "next",
3+
"release": "rc",
4+
"release-patch": "patch"
5+
};
6+
7+
module.exports.releaseBranches = releaseBranches;

Gruntfile.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const childProcess = require("child_process");
22
const EOL = require("os").EOL;
33
const now = new Date().toISOString();
4-
5-
const CONFIG_JSON_PATH = "config/config.json";
4+
const releaseBranches = require("./.travis/travis-release-branches").releaseBranches;
65

76
const ENVIRONMENTS = {
87
live: "live",
@@ -143,7 +142,7 @@ module.exports = function (grunt) {
143142
"isWindows": true,
144143
"isMacOS": true,
145144
"isLinux": true,
146-
"formatListOfNames": () => {},
145+
"formatListOfNames": () => { },
147146
"constants": ""
148147
}
149148
},
@@ -173,50 +172,34 @@ module.exports = function (grunt) {
173172

174173
var packageJson = grunt.file.readJSON("package.json");
175174
var versionParts = packageJson.version.split("-");
176-
if (process.env["RELEASE_BUILD"]) {
177-
// HACK - excluded until 1.0.0 release or we refactor our project infrastructure (whichever comes first)
178-
// packageJson.version = versionParts[0];
179-
} else {
180-
versionParts[1] = buildVersion;
181-
packageJson.version = versionParts.join("-");
182-
}
175+
versionParts[1] = buildVersion;
176+
packageJson.version = versionParts.join("-");
183177
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
184178
});
185179

186180
grunt.registerTask("tslint:build", function (version) {
187181
childProcess.execSync("npm run tslint", { stdio: "inherit" });
188182
});
189183

190-
grunt.registerTask("enableScripts", function (enable) {
191-
var enableTester = /false/i;
192-
var newScriptsAttr = !enableTester.test(enable) ? "scripts" : "skippedScripts";
193-
var packageJson = grunt.file.readJSON("package.json");
194-
var oldScriptsAttrValue = packageJson.scripts || packageJson.skippedScripts;
195-
delete packageJson.scripts;
196-
delete packageJson.skippedScripts;
197-
packageJson[newScriptsAttr] = oldScriptsAttrValue;
198-
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
199-
});
200-
201184
const setConfig = (key, value) => {
202185
const configJson = grunt.file.readJSON(CONFIG_DATA.filePath);
203186
configJson[key] = value;
204187
const stringConfigContent = JSON.stringify(configJson, null, " ") + EOL;
205188
grunt.file.write(CONFIG_DATA.filePath, stringConfigContent);
206189
}
207190

208-
grunt.registerTask("set_live_ga_id", function() {
191+
grunt.registerTask("set_live_ga_id", function () {
209192
setConfig(CONFIG_DATA.gaKey, GA_TRACKING_IDS[ENVIRONMENTS.live]);
210193
});
211194

212-
grunt.registerTask("set_dev_ga_id", function() {
195+
grunt.registerTask("set_dev_ga_id", function () {
213196
setConfig(CONFIG_DATA.gaKey, GA_TRACKING_IDS[ENVIRONMENTS.dev]);
214197
});
215198

216-
grunt.registerTask("verify_live_ga_id", function() {
199+
grunt.registerTask("verify_live_ga_id", function () {
217200
var configJson = grunt.file.readJSON(CONFIG_DATA.filePath);
218201

219-
if(configJson[CONFIG_DATA.gaKey] !== GA_TRACKING_IDS[ENVIRONMENTS.live]) {
202+
if (configJson[CONFIG_DATA.gaKey] !== GA_TRACKING_IDS[ENVIRONMENTS.live]) {
220203
throw new Error("Google Analytics id is not configured correctly.");
221204
}
222205
});
@@ -234,6 +217,17 @@ module.exports = function (grunt) {
234217
"set_package_version",
235218
"shell:build_package"
236219
]);
220+
221+
grunt.registerTask("travisPack", function () {
222+
const travisBranch = grunt.option("travisBranch");
223+
if (travisBranch && releaseBranches[travisBranch]) {
224+
console.log(`Skipping travisPack step as the current branch is ${travisBranch}, so it will be packed from the deploy provider.`);
225+
return 0;
226+
}
227+
228+
return grunt.task.run("pack");
229+
230+
});
237231
grunt.registerTask("lint", ["tslint:build"]);
238232
grunt.registerTask("all", ["clean", "test", "lint"]);
239233
grunt.registerTask("rebuild", ["clean", "ts:devlib"]);

0 commit comments

Comments
 (0)