Skip to content

Commit e510d4e

Browse files
committed
Merge branch 'Localization' of https://github.com/microsoft/azure-pipelines-tasks into Localization
2 parents 9460ac5 + a49c58a commit e510d4e

File tree

2,787 files changed

+1141702
-8842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,787 files changed

+1141702
-8842
lines changed

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@
8585
*.pdf diff=astextplain
8686
*.PDF diff=astextplain
8787
*.rtf diff=astextplain
88-
*.RTF diff=astextplain
88+
*.RTF diff=astextplain
89+
90+
*.lcl text=auto

Localize/LocProject.json

Lines changed: 962 additions & 0 deletions
Large diffs are not rendered by default.

Localize/bump-versions.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const run = require('../ci/ci-util').run;
4+
const semver = require('semver');
5+
6+
const currentSprint = parseInt(process.env['SPRINT']);
7+
8+
function getChangedFilesList() {
9+
return run('git --no-pager diff --name-only origin/master..Localization').split('\n');
10+
}
11+
12+
function getTaskOrPackagePaths(paths, rootFolder, exclusions) {
13+
let pathSet = new Set();
14+
paths.filter(p => p.startsWith(rootFolder))
15+
.map(p => p.slice(0, p.indexOf('/', rootFolder.length)))
16+
.filter(p => fs.existsSync(path.resolve(p)) && fs.statSync(path.resolve(p)).isDirectory())
17+
.forEach(p => pathSet.add(p));
18+
19+
for (let excludedTask of exclusions) {
20+
pathSet.delete(`${rootFolder}${excludedTask}`);
21+
}
22+
return Array.from(pathSet);
23+
}
24+
25+
function getTasksPaths(paths) {
26+
const taskFolder = 'Tasks/';
27+
const exclusions = ['Common'];
28+
29+
return getTaskOrPackagePaths(paths, taskFolder, exclusions);
30+
}
31+
32+
function getCommonPacks(paths) {
33+
const packFolder = 'common-npm-packages/';
34+
const exclusions = ['_download', 'node_modules', 'build-scripts'];
35+
36+
return getTaskOrPackagePaths(paths, packFolder, exclusions);
37+
}
38+
39+
function bumpTaskVersion(taskPath, minor) {
40+
const taskJsonPath = path.join(__dirname, '..', taskPath, 'task.json');
41+
const taskLocJsonPath = path.join(__dirname, '..', taskPath, 'task.loc.json');
42+
43+
if (!fs.existsSync(taskJsonPath) || !fs.existsSync(taskLocJsonPath)) {
44+
console.log(`Bumping version of ${taskPath} failed: task.json or task.loc.json doesn't exists.`);
45+
return;
46+
}
47+
48+
let taskJson = JSON.parse(fs.readFileSync(taskJsonPath));
49+
let taskLocJson = JSON.parse(fs.readFileSync(taskLocJsonPath));
50+
51+
if (typeof taskJson.version.Patch != 'number') {
52+
throw new Error(`Error processing '${taskJsonPath}'. version.Patch should be a number.`);
53+
}
54+
if (taskJson.version.Minor === minor) {
55+
taskJson.version.Patch = taskJson.version.Patch + 1;
56+
taskLocJson.version.Patch = taskLocJson.version.Patch + 1;
57+
} else {
58+
taskJson.version.Patch = 0;
59+
taskLocJson.version.Patch = 0;
60+
taskJson.version.Minor = minor;
61+
taskLocJson.version.Minor = minor;
62+
}
63+
64+
fs.writeFileSync(taskJsonPath, JSON.stringify(taskJson, null, 4));
65+
fs.writeFileSync(taskLocJsonPath, JSON.stringify(taskLocJson, null, 2));
66+
}
67+
68+
function bumpPackageVersion(packPath, minor) {
69+
const packageJsonPath = path.join(__dirname, '..', packPath, 'package.json');
70+
const packageLocJsonPath = path.join(__dirname, '..', packPath, 'package-lock.json');
71+
72+
if (!fs.existsSync(packageJsonPath) || !fs.existsSync(packageLocJsonPath)) {
73+
console.log(`Bumping version of ${packPath} failed: package.json or package-lock.json doesn't exists.`);
74+
return;
75+
}
76+
77+
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
78+
let packageLocJson = JSON.parse(fs.readFileSync(packageLocJsonPath));
79+
80+
let version = semver.parse(packageJson.version);
81+
82+
if (version.minor === minor) {
83+
version.patch++;
84+
} else {
85+
version.minor = minor;
86+
version.patch = 0;
87+
}
88+
packageJson.version = version.format();
89+
packageLocJson.version = version.format();
90+
91+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4));
92+
fs.writeFileSync(packageLocJsonPath, JSON.stringify(packageLocJson, null, 2));
93+
}
94+
95+
function main() {
96+
if (!currentSprint) {
97+
throw new Error('SPRINT variable is not set!')
98+
}
99+
100+
const fileList = getChangedFilesList();
101+
102+
const tasksPaths = getTasksPaths(fileList)
103+
const commonPackages = getCommonPacks(fileList)
104+
105+
tasksPaths.forEach(taskPath => {
106+
bumpTaskVersion(taskPath, currentSprint);
107+
});
108+
109+
commonPackages.forEach(packagePath => {
110+
bumpPackageVersion(packagePath, currentSprint);
111+
});
112+
}
113+
114+
main();

0 commit comments

Comments
 (0)