Skip to content

Commit f3e839c

Browse files
Merge pull request #4336 from NativeScript/vladimirov/travis-fix
chore: fix travis build of next/rc/release-patch versions
2 parents 37d0f6f + 01a7310 commit f3e839c

File tree

4 files changed

+27
-45
lines changed

4 files changed

+27
-45
lines changed

.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: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,15 @@ 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 --no-color
3024
before_deploy:
3125
- node .travis/add-publishConfig.js $TRAVIS_BRANCH
3226
deploy:
3327
- provider: npm
3428
skip_cleanup: true
3529
3630
on:
37-
branch: master
38-
api_key:
39-
secure: "FM9QLOkFq6JpHlfHkT1i2Ht1ZlttZLq7K3kQNLabw7Z5+BPMcy/f3LRJkAkYMezrKLKRkq1uXmhY0BapoTnR9AVEO/t4g6dtbZ1TZ3xBH/HHnFofTFubOrc7+61DJzKduYtnQ/sn3EEOkN8jrXSY9uas4qZh7PSm1hcfjPI8gdI="
40-
- provider: npm
41-
skip_cleanup: true
42-
43-
on:
44-
branch: release
45-
api_key:
46-
secure: "FM9QLOkFq6JpHlfHkT1i2Ht1ZlttZLq7K3kQNLabw7Z5+BPMcy/f3LRJkAkYMezrKLKRkq1uXmhY0BapoTnR9AVEO/t4g6dtbZ1TZ3xBH/HHnFofTFubOrc7+61DJzKduYtnQ/sn3EEOkN8jrXSY9uas4qZh7PSm1hcfjPI8gdI="
47-
- provider: npm
48-
skip_cleanup: true
49-
50-
on:
51-
branch: release-patch
31+
all_branches: true
5232
api_key:
5333
secure: "FM9QLOkFq6JpHlfHkT1i2Ht1ZlttZLq7K3kQNLabw7Z5+BPMcy/f3LRJkAkYMezrKLKRkq1uXmhY0BapoTnR9AVEO/t4g6dtbZ1TZ3xBH/HHnFofTFubOrc7+61DJzKduYtnQ/sn3EEOkN8jrXSY9uas4qZh7PSm1hcfjPI8gdI="

Gruntfile.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const childProcess = require("child_process");
22
const EOL = require("os").EOL;
33
const now = new Date().toISOString();
44

5-
const CONFIG_JSON_PATH = "config/config.json";
6-
75
const ENVIRONMENTS = {
86
live: "live",
97
dev: "dev"
@@ -143,7 +141,7 @@ module.exports = function (grunt) {
143141
"isWindows": true,
144142
"isMacOS": true,
145143
"isLinux": true,
146-
"formatListOfNames": () => {},
144+
"formatListOfNames": () => { },
147145
"constants": ""
148146
}
149147
},
@@ -166,57 +164,49 @@ module.exports = function (grunt) {
166164
grunt.loadNpmTasks("grunt-template");
167165

168166
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.
169170
var buildVersion = version !== undefined ? version : buildNumber;
170171
if (process.env["BUILD_CAUSE_GHPRBCAUSE"]) {
171172
buildVersion = "PR" + buildVersion;
172173
}
173174

174175
var packageJson = grunt.file.readJSON("package.json");
175176
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 {
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"]) {
180180
versionParts[1] = buildVersion;
181181
packageJson.version = versionParts.join("-");
182182
}
183+
183184
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
184185
});
185186

186187
grunt.registerTask("tslint:build", function (version) {
187188
childProcess.execSync("npm run tslint", { stdio: "inherit" });
188189
});
189190

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-
201191
const setConfig = (key, value) => {
202192
const configJson = grunt.file.readJSON(CONFIG_DATA.filePath);
203193
configJson[key] = value;
204194
const stringConfigContent = JSON.stringify(configJson, null, " ") + EOL;
205195
grunt.file.write(CONFIG_DATA.filePath, stringConfigContent);
206196
}
207197

208-
grunt.registerTask("set_live_ga_id", function() {
198+
grunt.registerTask("set_live_ga_id", function () {
209199
setConfig(CONFIG_DATA.gaKey, GA_TRACKING_IDS[ENVIRONMENTS.live]);
210200
});
211201

212-
grunt.registerTask("set_dev_ga_id", function() {
202+
grunt.registerTask("set_dev_ga_id", function () {
213203
setConfig(CONFIG_DATA.gaKey, GA_TRACKING_IDS[ENVIRONMENTS.dev]);
214204
});
215205

216-
grunt.registerTask("verify_live_ga_id", function() {
206+
grunt.registerTask("verify_live_ga_id", function () {
217207
var configJson = grunt.file.readJSON(CONFIG_DATA.filePath);
218208

219-
if(configJson[CONFIG_DATA.gaKey] !== GA_TRACKING_IDS[ENVIRONMENTS.live]) {
209+
if (configJson[CONFIG_DATA.gaKey] !== GA_TRACKING_IDS[ENVIRONMENTS.live]) {
220210
throw new Error("Google Analytics id is not configured correctly.");
221211
}
222212
});
@@ -234,6 +224,16 @@ module.exports = function (grunt) {
234224
"set_package_version",
235225
"shell:build_package"
236226
]);
227+
228+
grunt.registerTask("travisPack", function () {
229+
if (travis && process.env.TRAVIS_PULL_REQUEST_BRANCH) {
230+
return grunt.task.run("pack");
231+
}
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.`);
236+
});
237237
grunt.registerTask("lint", ["tslint:build"]);
238238
grunt.registerTask("all", ["clean", "test", "lint"]);
239239
grunt.registerTask("rebuild", ["clean", "ts:devlib"]);

0 commit comments

Comments
 (0)