From c39ce3034ccadb5a013e3cd17eafce67fc1ffe46 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Mon, 31 Jul 2023 15:41:27 +0200 Subject: [PATCH] Fixes pipelines --- .azure-pipelines/publish-nightly.yml | 10 ++++------ scripts/ci/env.ts | 19 ++++++++++++++----- scripts/ci/monaco-editor-core-prepare.ts | 9 ++++++--- scripts/ci/monaco-editor-prepare.ts | 7 +++++-- scripts/lib/index.ts | 3 +-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.azure-pipelines/publish-nightly.yml b/.azure-pipelines/publish-nightly.yml index d4358ce800..e5c622eb85 100644 --- a/.azure-pipelines/publish-nightly.yml +++ b/.azure-pipelines/publish-nightly.yml @@ -25,15 +25,13 @@ resources: parameters: - name: vscodeRef - displayName: The VS Code commit id. When left empty, the main branched is used. + displayName: The VS Code commit id. type: string - default: '' - required: false + default: 'main' - name: prereleaseVersion - displayName: The prerelease version. When left empty, dev-${today} is used. + displayName: The prerelease version. type: string - default: '' - required: false + default: 'dev-${today}' extends: template: azure-pipelines/npm-package/pipeline.yml@templates diff --git a/scripts/ci/env.ts b/scripts/ci/env.ts index 222743fab4..fc43a70980 100644 --- a/scripts/ci/env.ts +++ b/scripts/ci/env.ts @@ -1,6 +1,15 @@ -export function getEnv(): { - VSCODE_REF: string | undefined; - PRERELEASE_VERSION: string | undefined; -} { - return process.env as any; +interface Env { + VSCODE_REF: string; + PRERELEASE_VERSION: string; +} + +export function getNightlyEnv(): Env { + const env: Env = process.env as any; + if (!env.PRERELEASE_VERSION) { + throw new Error(`Missing PRERELEASE_VERSION in process.env`); + } + if (!env.VSCODE_REF) { + throw new Error(`Missing VSCODE_REF in process.env`); + } + return env; } diff --git a/scripts/ci/monaco-editor-core-prepare.ts b/scripts/ci/monaco-editor-core-prepare.ts index 1cae7348c1..eef4371ee4 100644 --- a/scripts/ci/monaco-editor-core-prepare.ts +++ b/scripts/ci/monaco-editor-core-prepare.ts @@ -1,7 +1,7 @@ import { mkdir, rm } from 'fs/promises'; import { join, resolve } from 'path'; import { PackageJson, group, gitShallowClone, run, writeJsonFile, getNightlyVersion } from '../lib'; -import { getEnv } from './env'; +import { getNightlyEnv } from './env'; const selfPath = __dirname; const rootPath = join(selfPath, '..', '..'); @@ -22,8 +22,11 @@ async function prepareMonacoEditorCoreReleaseStableOrNightly() { version = monacoEditorPackageJson.version; ref = monacoEditorPackageJson.vscodeRef; } else if (arg === 'nightly') { - version = getNightlyVersion(monacoEditorPackageJson.version, getEnv().PRERELEASE_VERSION); - ref = getEnv().VSCODE_REF || 'main'; + version = getNightlyVersion( + monacoEditorPackageJson.version, + getNightlyEnv().PRERELEASE_VERSION + ); + ref = getNightlyEnv().VSCODE_REF; } else { throw new Error('Invalid argument'); } diff --git a/scripts/ci/monaco-editor-prepare.ts b/scripts/ci/monaco-editor-prepare.ts index f7f81f1335..b5e2c32620 100644 --- a/scripts/ci/monaco-editor-prepare.ts +++ b/scripts/ci/monaco-editor-prepare.ts @@ -1,7 +1,7 @@ import { readFile } from 'fs/promises'; import { join, resolve } from 'path'; import { PackageJson, getNightlyVersion, group, run, writeJsonFile, gitCommitId } from '../lib'; -import { getEnv } from './env'; +import { getNightlyEnv } from './env'; const selfPath = __dirname; const rootPath = join(selfPath, '..', '..'); @@ -24,7 +24,10 @@ async function prepareMonacoEditorReleaseStableOrNightly() { if (arg === 'stable') { version = monacoEditorPackageJson.version; } else if (arg === 'nightly') { - version = getNightlyVersion(monacoEditorPackageJson.version, getEnv().PRERELEASE_VERSION); + version = getNightlyVersion( + monacoEditorPackageJson.version, + getNightlyEnv().PRERELEASE_VERSION + ); } else { throw new Error('Invalid argument'); } diff --git a/scripts/lib/index.ts b/scripts/lib/index.ts index ee1c30e7d1..9f1c8b7193 100644 --- a/scripts/lib/index.ts +++ b/scripts/lib/index.ts @@ -73,7 +73,7 @@ export async function writeJsonFile(filePath: string, jsonData: unknown): Promis await writeFile(filePath, JSON.stringify(jsonData, null, '\t') + '\n'); } -export function getNightlyVersion(version: string, prerelease: string | undefined): string { +export function getNightlyVersion(version: string, prerelease: string): string { const pieces = version.split('.'); const minor = parseInt(pieces[1], 10); const date = new Date(); @@ -81,7 +81,6 @@ export function getNightlyVersion(version: string, prerelease: string | undefine const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); const dd = String(date.getUTCDate()).padStart(2, '0'); - prerelease = prerelease || 'dev-${today}'; prerelease = prerelease.replace('${today}', `${yyyy}${mm}${dd}`); return `0.${minor + 1}.0-${prerelease}`;