Skip to content

Commit

Permalink
chore: Use package.vsce to set preRelease (#4003)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jan 5, 2025
1 parent 3cfd2ce commit 01dc92d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/actions/vsce-args/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
10 changes: 3 additions & 7 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4019,6 +4019,5 @@
"@cspell/dict-cspell-bundle": "1.0.20",
"cspell": "^8.17.1",
"regexp-worker": "^3.0.0"
},
"prerelease": true
}
}
18 changes: 15 additions & 3 deletions scripts/set-prerelease-mode.js
Original file line number Diff line number Diff line change
@@ -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<T>
*/

/**
* @typedef {Mutable<import('@vscode/vsce').IPackageOptions>} VSCEPackageOptions
*/

const pkgUrl = new URL('../package.json', import.meta.url);

function assertArgs() {
Expand All @@ -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');
Expand Down

0 comments on commit 01dc92d

Please sign in to comment.