From bf69a1a3addcc992282248d8ef602444ece3b876 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Wed, 4 Dec 2024 19:15:59 +0100 Subject: [PATCH] chore: Use prerelease mode when publishing --- .github/workflows/manual-publish.yml | 25 ++++++++++-- .../{preview.yml => set-prerelease.yml} | 14 +++---- package-lock.json | 2 +- scripts/package.json | 2 +- scripts/set-prerelease-mode.js | 39 +++++++++++++++++++ scripts/set-preview-mode.js | 38 ------------------ 6 files changed, 70 insertions(+), 50 deletions(-) rename .github/workflows/{preview.yml => set-prerelease.yml} (62%) create mode 100755 scripts/set-prerelease-mode.js delete mode 100755 scripts/set-preview-mode.js diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 86f3f73b4a..87fe383b15 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -24,6 +24,21 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: + prerelease: + runs-on: ubuntu-latest + outputs: + prerelease: ${{ steps.check-prerelease.outputs.prerelease }} + steps: + - name: Check package.json for prerelease + id: check-prerelease + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const manifest = JSON.parse(fs.readFileSync('package.json', 'utf8')); + const isPrerelease = manifest['prerelease'] || false; + core.setOutput('prerelease', isPrerelease); + check_version: runs-on: ubuntu-latest outputs: @@ -73,8 +88,12 @@ jobs: publish: runs-on: ubuntu-latest - needs: check_version + needs: + - check_version + - prerelease if: ${{ needs.check_version.outputs.validVersion == 'true' }} + env: + PRERELEASE: ${{ needs.prerelease.outputs.prerelease && needs.prerelease.outputs.prerelease != 'false' && '--pre-release' || '' }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -95,14 +114,14 @@ jobs: run: npm run package-extension - name: Publish VSCE run: > - find ./build -name "*.vsix" | xargs npx vsce publish --skip-duplicate -p ${{ secrets.VSCE_TOKEN }} --packagePath + find ./build -name "*.vsix" | xargs npx vsce publish --skip-duplicate -p ${{ secrets.VSCE_TOKEN }} ${{ env.PRERELEASE}} --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 }} + find ./build -name "*.vsix" | xargs npx ovsx publish --skip-duplicate -p ${{ secrets.OVSX_TOKEN }} ${{ env.PRERELEASE}} || echo "PUB_FAIL_OVSX=true" >> $GITHUB_ENV - name: Check Publish Result OVSX if: ${{ env.PUB_FAIL_OVSX }} diff --git a/.github/workflows/preview.yml b/.github/workflows/set-prerelease.yml similarity index 62% rename from .github/workflows/preview.yml rename to .github/workflows/set-prerelease.yml index 468e4868cf..ae2c7de1fa 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/set-prerelease.yml @@ -1,4 +1,4 @@ -name: ' 👀 Set Pre-Release' +name: ' 👀 Set Prerelease' on: # rebuild any PRs and main branch changes workflow_dispatch: inputs: @@ -8,7 +8,7 @@ on: # rebuild any PRs and main branch changes default: true jobs: - set-preview: + set-prerelease-mode: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -18,16 +18,16 @@ jobs: with: node-version: ${{ vars.DEFAULT_NODE_VERSION }} - - run: node ./scripts/set-preview-mode.js ${{ inputs.prerelease }} + - run: node ./scripts/set-prerelease-mode.js ${{ inputs.prerelease }} - name: PR uses: streetsidesoftware/actions/.github/actions/pr@v1 with: - commit-message: 'fix: Set Preview Mode to `${{ inputs.prerelease }}`' - branch: update-preview-mode + commit-message: 'fix: Set Prerelease Mode to `${{ inputs.prerelease }}`' + branch: update-prerelease-mode base: main - title: 'fix: Set Preview Mode to `${{ inputs.prerelease }}`' + title: 'fix: Set Prerelease Mode to `${{ inputs.prerelease }}`' body: | - Set Preview Mode to `${{ inputs.prerelease }}` + Set Prerelease Mode to `${{ inputs.prerelease }}` app_id: ${{ secrets.AUTOMATION_APP_ID }} app_private_key: ${{ secrets.AUTOMATION_PRIVATE_KEY }} diff --git a/package-lock.json b/package-lock.json index 8365a29d66..97717b3c66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28744,7 +28744,7 @@ "version": "1.0.0", "license": "MIT", "bin": { - "set-preview": "set-preview-mode.js" + "set-prerelease": "set-prerelease-mode.js" } }, "tools/build-tools": { diff --git a/scripts/package.json b/scripts/package.json index 8363378357..5aa5bc66bb 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "description": "Internal Scripts", "bin": { - "set-preview": "./set-preview-mode.js" + "set-prerelease": "./set-prerelease-mode.js" }, "type": "module", "scripts": { diff --git a/scripts/set-prerelease-mode.js b/scripts/set-prerelease-mode.js new file mode 100755 index 0000000000..a40101cba0 --- /dev/null +++ b/scripts/set-prerelease-mode.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +import fs from 'node:fs/promises'; + +const pkgUrl = new URL('../package.json', import.meta.url); + +function assertArgs() { + if (process.argv.length !== 3 || !['true', 'false'].includes(process.argv[2])) { + console.error('Usage: set-prerelease-mode.js '); + throw new Error('Invalid arguments'); + } +} + +async function run() { + assertArgs(); + const isPrereleaseMode = process.argv[2] === 'true' || undefined; + + const content = JSON.parse(await fs.readFile(pkgUrl, 'utf-8')); + + if (!!content['prerelease'] === isPrereleaseMode) { + console.log(`Prerelease mode is already ${isPrereleaseMode}`); + return; + } + + if (isPrereleaseMode) { + content['prerelease'] = true; + } else { + delete content['prerelease']; + } + + await fs.writeFile(pkgUrl, JSON.stringify(content, null, 2) + '\n'); + + console.log(`Prerelease mode is now ${isPrereleaseMode || false}`); +} + +run().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/set-preview-mode.js b/scripts/set-preview-mode.js deleted file mode 100755 index f1624a1f6f..0000000000 --- a/scripts/set-preview-mode.js +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env node - -import fs from 'node:fs/promises'; - -const pkgUrl = new URL('../package.json', import.meta.url); - -function assertArgs() { - if (process.argv.length !== 3 || !['true', 'false'].includes(process.argv[2])) { - console.error('Usage: set-preview-mode.js '); - throw new Error('Invalid arguments'); - } -} - -async function run() { - assertArgs(); - const isPreviewMode = process.argv[2] === 'true'; - - const content = await fs.readFile(pkgUrl, 'utf-8'); - - const updatedContent = content.replace( - isPreviewMode ? '"pre-release": false' : '"pre-release": true', - `"pre-release": ${isPreviewMode}`, - ); - - if (content === updatedContent) { - console.log('Nothing to update'); - return; - } - - await fs.writeFile(pkgUrl, updatedContent); - - console.log(`Preview mode is now ${isPreviewMode}`); -} - -run().catch((error) => { - console.error(error); - process.exitCode = 1; -});