Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 6c63b41

Browse files
christopherandersonmunozemilio
authored andcommitted
ci: publish artifacts (#396)
* build: add version script * build: add error message to rush * ci: add artifact publishing * ci: ensure doesn't run version on PR * ci: just use version to detect whether to publish * ci: fix variable syntax * ci: fix job name * build: add rimraf to lu/qnamaker * ci: change to use build number * ci: fix syntax * ci: typo * ci: syntax error * ci: fix syntax error * ci: fix syntax error * ci: fix syntax error * ci: fix syntax error... * ci: fix syntax error * ci: fix syntax error * ci: fix syntax error * ci: fallback to buildVersion * ci: fix buildId * ci: try a different syntax * build: remove parallelism because deadlock * fix: do not hang on non-tty * revert: revert the tty fix * build: remove doc gen in CI for time being * build: remove docs from version
1 parent 50358cf commit 6c63b41

File tree

7 files changed

+225
-396
lines changed

7 files changed

+225
-396
lines changed

azure-pipelines.yml

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,66 @@ schedules:
1414
include:
1515
- master
1616

17-
strategy:
18-
matrix:
19-
linux:
20-
imageName: "windows-2019"
21-
nodeVersion: "12.x"
22-
maxParallel: 3
17+
jobs:
18+
- job: CLI
19+
strategy:
20+
matrix:
21+
windows:
22+
imageName: "windows-2019"
23+
nodeVersion: "12.x"
24+
maxParallel: 3
25+
pool:
26+
vmImage: $(imageName)
27+
variables:
28+
buildVersion: '4.7.0-preview.$(Build.BuildId)'
29+
_version: ${{coalesce(variables.version, variables.buildVersion)}}
30+
steps:
31+
#Your build pipeline references the ‘version’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
32+
- task: colinsalmcorner.colinsalmcorner-buildtasks.tag-build-task.tagBuildOrRelease@0
33+
displayName: 'Tag Build with version number'
34+
inputs:
35+
tags: 'Version=$(_version)'
2336

24-
pool:
25-
vmImage: $(imageName)
37+
- task: NodeTool@0
38+
displayName: 'Use Node $(nodeVersion)'
39+
inputs:
40+
versionSpec: $(nodeVersion)
2641

27-
steps:
28-
- powershell: 'Get-ChildItem env:* | sort-object name'
29-
displayName: 'Log environment variables'
30-
continueOnError: true
42+
- task: Npm@1
43+
displayName: 'Install rush'
44+
inputs:
45+
command: custom
46+
verbose: false
47+
customCommand: 'install --global @microsoft/rush'
3148

32-
- task: NodeTool@0
33-
displayName: 'Use Node 12.x'
34-
inputs:
35-
versionSpec: $(nodeVersion)
49+
- script: 'rush update'
50+
displayName: 'rush update'
3651

37-
- task: Npm@1
38-
displayName: 'Install rush'
39-
inputs:
40-
command: custom
41-
verbose: false
42-
customCommand: 'install --global @microsoft/rush'
52+
- script: 'rush build'
53+
displayName: 'rush build'
4354

44-
- script: 'rush update'
45-
displayName: 'rush update'
55+
- script: 'rush test'
56+
displayName: 'rush test'
4657

47-
- script: 'rush build'
48-
displayName: 'rush build'
58+
- script: 'node ./common/scripts/version-and-pack.js --version $(_version)'
59+
displayName: 'Version and Pack'
4960

50-
- script: 'rush test'
51-
displayName: 'rush test'
61+
- task: CopyFiles@2
62+
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
63+
inputs:
64+
SourceFolder: ./.output
65+
Contents: '**/*.tgz'
66+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
67+
flattenFolders: true
5268

53-
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
54-
displayName: 'Component Detection'
69+
- task: PublishBuildArtifacts@1
70+
displayName: 'Publish Artifact: drop'
71+
inputs:
72+
artifactName: 'drop'
5573

56-
- script: 'rush report:coverage'
57-
displayName: 'rush report:coverage'
58-
enabled: false
74+
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
75+
displayName: 'Component Detection'
5976

60-
- task: PublishBuildArtifacts@1
61-
enabled: false
62-
displayName: 'Publish Artifact: nyc_output'
63-
inputs:
64-
PathtoPublish: '$(Build.SourcesDirectory)\.nyc_output'
65-
ArtifactName: 'nyc_output'
77+
- script: 'rush report:coverage'
78+
displayName: 'rush report:coverage'
79+
enabled: false

common/config/rush/command-line.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"summary": "Cleans non-rush content. Use rush unlink/purge/tableflip.",
2626
"enableParallelism": true
2727
},
28+
{
29+
"commandKind": "global",
30+
"name": "pack",
31+
"summary": "Create .tgz packages for publishing in CI",
32+
"description":"This doesn't currently work because rush doesn't allow the passing of arbitrary commands like version numbers yet. \n Use node ./common/scripts/version-and-pack.js --version X.X.X-tag instead.",
33+
"shellCommand": "node -e \"throw new Error(`Not supported yet. \\nUse node ./common/scripts/version-and-pack.js --version X.X.X-tag instead`)\""
34+
},
2835
/**
2936
* Disable parallelism because it makes the results flakier
3037
*/

common/scripts/version-and-pack.js

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// @ts-check
2+
// Ensure using node 12 because of recursive mkdir
3+
if (
4+
!process.env.GEN_CLDR_DATA_IGNORE_NODE_VERSION &&
5+
process.version.split('.')[0] < 'v12'
6+
) {
7+
console.error(`
8+
Your node version appears to be below v12: ${ process.version}.
9+
This script will not run correctly on earlier versions of node.
10+
Set 'GEN_CLDR_DATA_IGNORE_NODE_VERSION' environment variable to truthy to override`);
11+
}
12+
13+
const fs = require('fs');
14+
const path = require('path');
15+
const cp = require('child_process');
16+
const os = require('os');
17+
18+
// from: https://semver.org/
19+
const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?$/
20+
const npm = (process.platform === 'win32' ? 'npm.cmd' : 'npm');
21+
const packDirName = "./.output";
22+
const packDir = path.join(__dirname, "../..", packDirName);
23+
24+
async function main() {
25+
const plog = prettyLogger('version-and-pack', 'main');
26+
27+
// Extract version from command line
28+
const version = extractVersion(process.argv);
29+
if (version === undefined) {
30+
throw new TypeError("You must specifiy --version as an argument");
31+
}
32+
if (!semverRegex.test(version)) {
33+
throw new RangeError(`Version must match semver V1 format (i.e. X.X.X-label). Received: "${version}"`);
34+
}
35+
plog(`Setting version: ${version}`);
36+
37+
// Load all modules we care about from rush
38+
let projects;
39+
try {
40+
const rushConfig = require('../../rush.json');
41+
projects = rushConfig.projects;
42+
plog("Loading projects:");
43+
plog(JSON.stringify(projects, null, ' '));
44+
} catch (e) {
45+
plog("Could not load projects from rush.json");
46+
throw e;
47+
}
48+
49+
try {
50+
plog("Creating output directory: " + packDir);
51+
createIfNotExistSync(packDir);
52+
} catch (e) {
53+
plog("Could not create output directory");
54+
throw e;
55+
}
56+
for (const project of projects) {
57+
plog("Bumping version for " + project.packageName + " to " + version);
58+
const pathToPackage = path.join(__dirname, "../../", project.projectFolder);
59+
await exec(npm, ['version', version, '--allow-same-version'], { cwd: pathToPackage });
60+
61+
plog("Updating dependencies in package.json");
62+
const packageJsonPath = path.join(pathToPackage, 'package.json');
63+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
64+
65+
for (const dep of projects) {
66+
if (packageJson.dependencies[dep.packageName]) {
67+
plog("Updating version in " + project.packageName + ": " + dep.packageName + " -> " + version);
68+
packageJson.dependencies[dep.packageName] = version;
69+
}
70+
}
71+
72+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, ' ') + '\n', {
73+
encoding: 'utf8'
74+
});
75+
76+
plog("Packing " + project.packageName);
77+
const output = await exec(npm, ['pack'], { cwd: pathToPackage });
78+
const tgz = parseTgz(output);
79+
plog('found tgz: ' + tgz);
80+
fs.copyFileSync(path.join(pathToPackage, tgz), path.join(packDir, tgz));
81+
}
82+
83+
plog('Complete');
84+
}
85+
86+
function extractVersion(argv) {
87+
for (let i = 1; i < argv.length; i++) {
88+
if (argv[i - 1] === '--version') {
89+
return argv[i].trim();
90+
}
91+
}
92+
}
93+
94+
function parseTgz(text) {
95+
const lines = text.split('\n');
96+
for (const line of lines) {
97+
if (line.endsWith('.tgz')) {
98+
return line;
99+
}
100+
}
101+
}
102+
103+
async function exec(command, args, opts) {
104+
const stdout = prettyLogger(command, 'stdout');
105+
const stderr = prettyLogger(command, 'stderr');
106+
const error = prettyLogger(command, 'error');
107+
108+
return new Promise((resolve, reject) => {
109+
const p = cp.spawn(command, args, opts);
110+
let buffer = '';
111+
112+
p.stdout.on('data', data => {
113+
buffer += data;
114+
stdout(`[${command}][stdout]: ${data}`);
115+
});
116+
117+
p.stderr.on('data', data => {
118+
stderr(`[${command}][stderr]: ${data}`);
119+
});
120+
121+
p.on('error', err => {
122+
error(err);
123+
});
124+
125+
p.on('close', code => {
126+
if (code !== 0) {
127+
return reject(new Error(`"${command} ${args.join(' ')}" returned unsuccessful error code: ${code}`));
128+
} else {
129+
resolve(buffer);
130+
}
131+
});
132+
});
133+
}
134+
135+
function createIfNotExistSync(path) {
136+
try {
137+
fs.mkdirSync(path, { recursive: true });
138+
} catch (e) {
139+
if (!e.code === 'EEXIST') {
140+
throw e;
141+
}
142+
}
143+
}
144+
145+
function prettyLogger(...labels) {
146+
const header = `[${labels.join('][')}]: `;
147+
return (content) => {
148+
if (typeof content !== 'string') {
149+
content = JSON.stringify(content, null, ' ');
150+
}
151+
const lines = content.split('\n');
152+
lines.forEach((v) => console.log(header + v));
153+
};
154+
}
155+
156+
main().catch(err => {
157+
console.error(err);
158+
process.exit(1);
159+
}).then(() => {
160+
process.exit(0);
161+
});

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"repository": "https://github.com/microsoft/botframework-cli/tree/master/packages/cli",
7575
"scripts": {
7676
"postinstall": "node scripts/postinstall.js",
77-
"prepack": "npm run clean && npm run build && npm run doc:readme",
77+
"prepack": "npm run clean && npm run build",
7878
"postpack": "rimraf oclif.manifest.json",
7979
"posttest": "tslint -p test -t stylish",
8080
"build":"tsc -b",
@@ -84,7 +84,7 @@
8484
"report:coverage":"npm run coverage && nyc report --reporter=text-lcov | coveralls",
8585
"doc": "npm run build && npm run doc:readme && rimraf oclif.manifest.json",
8686
"doc:readme":"oclif-dev manifest && oclif-dev readme",
87-
"version": "npm run doc:readme && git add README.md"
87+
"version": ""
8888
},
8989
"types": "lib/index.d.ts"
9090
}

packages/lu/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"mocha": "^6.2.2",
7575
"nock": "^11.7.0",
7676
"nyc": "^14.1.1",
77+
"rimraf": "^2.6.3",
7778
"ts-node": "^8.3.0",
7879
"tslint": "^5.18.0",
7980
"typescript": "^3.5.3"

packages/qnamaker/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"readline-sync": "^1.4.9",
6060
"request": "^2.88.0",
6161
"request-promise-native": "^1.0.5",
62+
"rimraf": "^2.6.3",
6263
"semver": "^5.5.1",
6364
"tslib": "^1.10.0",
6465
"window-size": "^1.1.0"

0 commit comments

Comments
 (0)