Skip to content

Commit b204bef

Browse files
authored
Merge pull request microsoft#74022 from microsoft/octref/devops-publish-types
Types publisher
2 parents 42c957d + 5cbc0aa commit b204bef

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as cp from 'child_process';
9+
10+
let tag = '';
11+
try {
12+
tag = cp
13+
.execSync('git describe --tags `git rev-list --tags --max-count=1`')
14+
.toString()
15+
.trim();
16+
17+
if (!isValidTag(tag)) {
18+
throw Error(`Invalid tag ${tag}`);
19+
}
20+
} catch (err) {
21+
console.error(err);
22+
console.error('Failed to update types');
23+
process.exit(1);
24+
}
25+
26+
function isValidTag(t: string) {
27+
if (t.split('.').length !== 3) {
28+
return false;
29+
}
30+
31+
const [major, minor, bug] = t.split('.');
32+
33+
// Only release for tags like 1.34.0
34+
if (bug !== '0') {
35+
return false;
36+
}
37+
38+
if (parseInt(major, 10) === NaN || parseInt(minor, 10) === NaN) {
39+
return false;
40+
}
41+
42+
return true;
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Publish @types/vscode for each release
2+
3+
trigger:
4+
branches:
5+
include: ['refs/tags/*']
6+
7+
steps:
8+
- task: NodeTool@0
9+
inputs:
10+
versionSpec: "10.15.1"
11+
12+
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-installer-task.YarnInstaller@2
13+
inputs:
14+
versionSpec: "1.10.1"
15+
16+
- bash: |
17+
# Install build dependencies
18+
(cd build && yarn)
19+
node build/azure-pipelines/publish-types/check-version.js
20+
displayName: Check version
21+
22+
- bash: |
23+
git config --global user.email "vscode@microsoft.com"
24+
git config --global user.name "VSCode"
25+
26+
git clone https://github.com/DefinitelyTyped/DefinitelyTyped.git
27+
node build/azure-pipelines/publish-types/update-types.js
28+
29+
TAG_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
30+
31+
cd DefinitelyTyped
32+
33+
git diff --color | cat
34+
git add -A
35+
git status
36+
git commit -m "VS Code $TAG_VERSION Extension API"
37+
git push origin master
38+
39+
git remote add vscode https://$(GITHUB_TOKEN)@github.com/octref/vscode-DefinitelyTyped.git
40+
git push -f vscode master
41+
42+
displayName: Update vscode-DefinitelyTyped
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as fs from 'fs';
9+
import * as cp from 'child_process';
10+
import * as path from 'path';
11+
12+
let tag = '';
13+
try {
14+
tag = cp
15+
.execSync('git describe --tags `git rev-list --tags --max-count=1`')
16+
.toString()
17+
.trim();
18+
19+
const dtsUri = `https://raw.githubusercontent.com/microsoft/vscode/${tag}/src/vs/vscode.d.ts`;
20+
const outPath = path.resolve(process.cwd(), 'DefinitelyTyped/types/vscode/index.d.ts');
21+
cp.execSync(`curl ${dtsUri} --output ${outPath}`);
22+
23+
updateDTSFile(outPath, tag);
24+
25+
console.log(`Done updating vscode.d.ts at ${outPath}`);
26+
} catch (err) {
27+
console.error(err);
28+
console.error('Failed to update types');
29+
process.exit(1);
30+
}
31+
32+
function updateDTSFile(outPath: string, tag: string) {
33+
const oldContent = fs.readFileSync(outPath, 'utf-8');
34+
const newContent = getNewFileContent(oldContent, tag);
35+
36+
fs.writeFileSync(outPath, newContent);
37+
}
38+
39+
function getNewFileContent(content: string, tag: string) {
40+
const oldheader = [
41+
`/*---------------------------------------------------------------------------------------------`,
42+
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
43+
` * Licensed under the MIT License. See License.txt in the project root for license information.`,
44+
` *--------------------------------------------------------------------------------------------*/`
45+
].join('\n');
46+
47+
return getNewFileHeader(tag) + content.slice(oldheader.length);
48+
}
49+
50+
function getNewFileHeader(tag: string) {
51+
const [major, minor] = tag.split('.');
52+
const shorttag = `${major}.${minor}`;
53+
54+
const header = [
55+
`// Type definitions for Visual Studio Code ${shorttag}`,
56+
`// Project: https://github.com/microsoft/vscode`,
57+
`// Definitions by: Visual Studio Code Team, Microsoft <https://github.com/Microsoft>`,
58+
`// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped`,
59+
``,
60+
`/*---------------------------------------------------------------------------------------------`,
61+
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
62+
` * Licensed under the MIT License.`,
63+
` * See https://github.com/Microsoft/vscode/blob/master/LICENSE.txt for license information.`,
64+
` *--------------------------------------------------------------------------------------------*/`,
65+
``,
66+
`/**`,
67+
` * Type Definition for Visual Studio Code ${shorttag} Extension API`,
68+
` * See https://code.visualstudio.com/api for more information`,
69+
` */`
70+
].join('\n');
71+
72+
return header;
73+
}

0 commit comments

Comments
 (0)