mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 13:55:41 +01:00
Compute state based on github event
This commit is contained in:
parent
d5dd935683
commit
119b4dbe5f
3 changed files with 107 additions and 1 deletions
10
.github/workflows/publish.yml
vendored
10
.github/workflows/publish.yml
vendored
|
|
@ -25,12 +25,22 @@ jobs:
|
||||||
repository: 'microsoft/monaco-editor'
|
repository: 'microsoft/monaco-editor'
|
||||||
path: './monaco-editor'
|
path: './monaco-editor'
|
||||||
|
|
||||||
|
- name: Compute state
|
||||||
|
id: state
|
||||||
|
run: node ./monaco-editor/.github/workflows/publish/computeState.js "${{github.event_name}}" "${{github.event.inputs.nightly}}"
|
||||||
|
# outputs: version, vscode_branch, skip_monaco_editor_core, skip_monaco_editor
|
||||||
|
|
||||||
- name: (vscode) checkout
|
- name: (vscode) checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
repository: 'microsoft/vscode'
|
repository: 'microsoft/vscode'
|
||||||
|
ref: ${{ steps.state.outputs.vscode_branch }}"
|
||||||
path: './vscode'
|
path: './vscode'
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
- name: Early stop
|
||||||
|
run: exit 1
|
||||||
|
|
||||||
- name: (vscode-loc) checkout
|
- name: (vscode-loc) checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
96
.github/workflows/publish/computeState.js
vendored
Normal file
96
.github/workflows/publish/computeState.js
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//@ts-check
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const cp = require('child_process');
|
||||||
|
const packageJson = require('../../../package.json');
|
||||||
|
|
||||||
|
if (process.argv.length !== 4) {
|
||||||
|
console.error(`usage: node computeState.js <"workflow_dispatch"|"schedule"> <"true"|"false">`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const EVENT_NAME = /** @type {'workflow_dispatch'|'schedule'} */ (process.argv[2]);
|
||||||
|
const STR_NIGHTLY = /** @type {'true'|'false'|''} */ (process.argv[3]);
|
||||||
|
|
||||||
|
if (!/^((workflow_dispatch)|(schedule))$/.test(EVENT_NAME)) {
|
||||||
|
console.error(`usage: node computeState.js <"workflow_dispatch"|"schedule"> <"true"|"false">`);
|
||||||
|
process.exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^((true)|(false)|())$/.test(STR_NIGHTLY)) {
|
||||||
|
console.error(`usage: node computeState.js <"workflow_dispatch"|"schedule"> <"true"|"false">`);
|
||||||
|
process.exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
const NIGHTLY = EVENT_NAME === 'schedule' || STR_NIGHTLY === 'true';
|
||||||
|
|
||||||
|
const latestMonacoEditorVersion = npmGetLatestVersion('monaco-editor');
|
||||||
|
const version = (() => {
|
||||||
|
if (NIGHTLY) {
|
||||||
|
const pieces = latestMonacoEditorVersion.split('.');
|
||||||
|
const minor = parseInt(pieces[1], 10);
|
||||||
|
const date = new Date();
|
||||||
|
const yyyy = date.getUTCFullYear();
|
||||||
|
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
|
||||||
|
const dd = String(date.getUTCDate()).padStart(2, '0');
|
||||||
|
return `0.${minor + 1}.0-dev.${yyyy}${mm}${dd}`;
|
||||||
|
} else {
|
||||||
|
return packageJson.version;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const vscodeBranch = (() => {
|
||||||
|
if (NIGHTLY) {
|
||||||
|
return 'main';
|
||||||
|
} else {
|
||||||
|
return packageJson.vscode;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const skipMonacoEditorCore = (() => {
|
||||||
|
return /** @type {'true'|'false'} */ (String(npmExists('monaco-editor-core', version)));
|
||||||
|
})();
|
||||||
|
|
||||||
|
const skipMonacoEditor = (() => {
|
||||||
|
return /** @type {'true'|'false'} */ (String(npmExists('monaco-editor-core', version)));
|
||||||
|
})();
|
||||||
|
|
||||||
|
console.log(`
|
||||||
|
::set-output name=version::${version}
|
||||||
|
::set-output name=vscode_branch::${vscodeBranch}
|
||||||
|
::set-output name=skip_monaco_editor_core::${skipMonacoEditorCore}
|
||||||
|
::set-output name=skip_monaco_editor::${skipMonacoEditor}
|
||||||
|
`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} packageName
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function npmGetLatestVersion(packageName) {
|
||||||
|
const output = cp.execSync(`npm show ${packageName} version`).toString();
|
||||||
|
const version = output.split(/\r\n|\r|\n/g)[0];
|
||||||
|
if (!/^0\.(\d+)\.(\d+)$/.test(version)) {
|
||||||
|
console.error(`version ${version} does not match 0.x.y`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} packageName
|
||||||
|
* @param {string} version
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function npmExists(packageName, version) {
|
||||||
|
const output = cp.execSync(`npm show ${packageName}@${version} version`).toString();
|
||||||
|
const result = output.split(/\r\n|\r|\n/g)[0];
|
||||||
|
if (result.trim().length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ const fs = require('fs');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
|
||||||
if (process.argv.length !== 3) {
|
if (process.argv.length !== 3) {
|
||||||
console.error(`usage: node updateVersion.js <PATH_TO_PACKAGE_JSON_FILE>`);
|
console.error(`usage: node setNightlyVersion.js <PATH_TO_PACKAGE_JSON_FILE>`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue