From 01dc92dd8c99344d1d46dd24918357d39a4c6e12 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Sun, 5 Jan 2025 17:55:07 +0100 Subject: [PATCH] chore: Use `package.vsce` to set `preRelease` (#4003) --- .github/actions/vsce-args/action.yaml | 5 +++-- .github/workflows/manual-publish.yml | 10 +++------- .github/workflows/release-assets.yml | 6 +----- package.json | 3 +-- scripts/set-prerelease-mode.js | 18 +++++++++++++++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/actions/vsce-args/action.yaml b/.github/actions/vsce-args/action.yaml index 3cfe4e76e4..0b301f530a 100644 --- a/.github/actions/vsce-args/action.yaml +++ b/.github/actions/vsce-args/action.yaml @@ -3,7 +3,7 @@ description: Determine the arguments to pass to `vsce publish`. outputs: args: - description: A token for making Pull Requests + description: arguments to pass to `vsce publish` value: ${{ steps.check-prerelease.outputs.arg }} prerelease: description: Is the package a prerelease? ("true"/"false") @@ -18,6 +18,7 @@ runs: script: | const fs = require('fs'); const manifest = JSON.parse(fs.readFileSync('package.json', 'utf8')); - const isPrerelease = manifest['prerelease'] || false; + const vsce = manifest['vsce'] || {}; + const isPrerelease = vsce.preRelease || false; core.setOutput('arg', isPrerelease ? '--pre-release' : ''); core.setOutput('prerelease', isPrerelease); diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 35a66e3947..6bdeb3444d 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -93,22 +93,18 @@ jobs: npm install npm run build - - name: VSCE Args - id: vsce-args - uses: ./.github/actions/vsce-args - - name: Build Extension .vsix - run: npm run package-extension -- ${{ steps.vsce-args.outputs.args }} + run: npm run package-extension - name: Publish VSCE run: > - find ./build -name "*.vsix" | xargs npx vsce publish --skip-duplicate -p ${{ secrets.VSCE_TOKEN }} ${{ steps.vsce-args.outputs.args }} --packagePath + find ./build -name "*.vsix" | xargs npx vsce publish --skip-duplicate -p ${{ secrets.VSCE_TOKEN }} --packagePath || echo "PUB_FAIL_VSCE=true" >> $GITHUB_ENV - name: Check Publish Result VSCE if: ${{ env.PUB_FAIL_VSCE }} run: echo "::error title=VSCE::Failed to Publish to VS Code Marketplace." - name: Publish OVSX run: > - find ./build -name "*.vsix" | xargs npx ovsx publish --skip-duplicate -p ${{ secrets.OVSX_TOKEN }} ${{ steps.vsce-args.outputs.args }} + find ./build -name "*.vsix" | xargs npx ovsx publish --skip-duplicate -p ${{ secrets.OVSX_TOKEN }} || echo "PUB_FAIL_OVSX=true" >> $GITHUB_ENV - name: Check Publish Result OVSX if: ${{ env.PUB_FAIL_OVSX }} diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index 2435bad516..8caa00ef0c 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -51,12 +51,8 @@ jobs: - name: Install run: npm i - - name: VSCE Args - id: vsce-args - uses: ./.github/actions/vsce-args - - name: Build Extension .vsix - run: npm run package-extension -- ${{ steps.vsce-args.outputs.args }} + run: npm run package-extension - run: zip code-spell-checker build/* diff --git a/package.json b/package.json index 423ddffc2e..0670d9312f 100644 --- a/package.json +++ b/package.json @@ -4019,6 +4019,5 @@ "@cspell/dict-cspell-bundle": "1.0.20", "cspell": "^8.17.1", "regexp-worker": "^3.0.0" - }, - "prerelease": true + } } diff --git a/scripts/set-prerelease-mode.js b/scripts/set-prerelease-mode.js index a40101cba0..5e6b1f2f32 100755 --- a/scripts/set-prerelease-mode.js +++ b/scripts/set-prerelease-mode.js @@ -1,7 +1,17 @@ #!/usr/bin/env node +// @ts-check import fs from 'node:fs/promises'; +/** + * @template T + * @typedef {{ -readonly [K in keyof T]: T[K] }} Mutable + */ + +/** + * @typedef {Mutable} VSCEPackageOptions + */ + const pkgUrl = new URL('../package.json', import.meta.url); function assertArgs() { @@ -16,16 +26,18 @@ async function run() { const isPrereleaseMode = process.argv[2] === 'true' || undefined; const content = JSON.parse(await fs.readFile(pkgUrl, 'utf-8')); + const vsce = /** @type {VSCEPackageOptions} */ (content['vsce'] || {}); + content['vsce'] = vsce; - if (!!content['prerelease'] === isPrereleaseMode) { + if (!!vsce.preRelease === isPrereleaseMode) { console.log(`Prerelease mode is already ${isPrereleaseMode}`); return; } if (isPrereleaseMode) { - content['prerelease'] = true; + vsce.preRelease = true; } else { - delete content['prerelease']; + vsce.preRelease = undefined; } await fs.writeFile(pkgUrl, JSON.stringify(content, null, 2) + '\n');