diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 01f9a327d..26685b192 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -70,29 +70,3 @@ extends: displayName: 'Test' - script: npm run lint displayName: 'Lint' - - - stage: Release - dependsOn: Build - jobs: - - job: Release - condition: eq(variables['Build.SourceBranch'], 'refs/heads/main') - # Output artifact to produce SBOM and to run SDL checks - templateContext: - outputs: - - output: pipelineArtifact - targetPath: $(Build.SourcesDirectory) - artifactName: drop - pool: - name: 1es-oss-ubuntu-22.04-x64 - os: Linux - steps: - - task: NodeTool@0 - inputs: - versionSpec: '20.x' - displayName: 'Install Node.js' - - script: | - npm i - displayName: 'Install dependencies and build' - - script: | - NPM_AUTH_TOKEN="$(NPM_AUTH_TOKEN)" node ./scripts/publish.js - displayName: 'Publish to npm' diff --git a/publish.yml b/publish.yml index 9406cc3b2..9e50de0b9 100644 --- a/publish.yml +++ b/publish.yml @@ -1,10 +1,9 @@ name: $(Date:yyyyMMdd)$(Rev:.r) +pr: none trigger: branches: - include: - - main -pr: none + include: ["main"] resources: repositories: diff --git a/scripts/publish.js b/scripts/publish.js deleted file mode 100644 index 0a1b2f449..000000000 --- a/scripts/publish.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2019, Microsoft Corporation (MIT License). - */ - -const cp = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const packageJson = require('../package.json'); - -// Setup auth -fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`); - -// Determine if this is a stable or beta release -const publishedVersions = getPublishedVersions(); -const isStableRelease = !publishedVersions.includes(packageJson.version); - -// Get the next version -const nextVersion = isStableRelease ? packageJson.version : getNextBetaVersion(); -console.log(`Setting version to ${nextVersion}`); - -// Set the version in package.json -const packageJsonFile = path.resolve(__dirname, '..', 'package.json'); -packageJson.version = nextVersion; -fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2)); - -// Publish -const args = ['publish']; -if (!isStableRelease) { - args.push('--tag', 'beta'); -} -const result = cp.spawn('npm', args, { stdio: 'inherit' }); -result.on('exit', code => process.exit(code)); - -function getNextBetaVersion() { - if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) { - console.error('The package.json version must be of the form x.y.z'); - process.exit(1); - } - const tag = 'beta'; - const stableVersion = packageJson.version.split('.'); - const nextStableVersion = `${stableVersion[0]}.${parseInt(stableVersion[1]) + 1}.0`; - const publishedVersions = getPublishedVersions(nextStableVersion, tag); - if (publishedVersions.length === 0) { - return `${nextStableVersion}-${tag}1`; - } - const latestPublishedVersion = publishedVersions.sort((a, b) => { - const aVersion = parseInt(a.substr(a.search(/[0-9]+$/))); - const bVersion = parseInt(b.substr(b.search(/[0-9]+$/))); - return aVersion > bVersion ? -1 : 1; - })[0]; - const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/[0-9]+$/)), 10); - return `${nextStableVersion}-${tag}${latestTagVersion + 1}`; -} - -function getPublishedVersions(version, tag) { - const isWin32 = process.platform === 'win32'; - const versionsProcess = isWin32 ? - cp.spawnSync('npm.cmd', ['view', packageJson.name, 'versions', '--json'], { shell: true }) : - cp.spawnSync('npm', ['view', packageJson.name, 'versions', '--json']); - const versionsJson = JSON.parse(versionsProcess.stdout); - if (tag) { - return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}[0-9]+`))); - } - return versionsJson; -}