Skip to content

Commit

Permalink
chore: Use prerelease mode when publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Dec 4, 2024
1 parent 3caaa09 commit bf69a1a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 50 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ' 👀 Set Pre-Release'
name: ' 👀 Set Prerelease'
on: # rebuild any PRs and main branch changes
workflow_dispatch:
inputs:
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
39 changes: 39 additions & 0 deletions scripts/set-prerelease-mode.js
Original file line number Diff line number Diff line change
@@ -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 <true|false>');
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;
});
38 changes: 0 additions & 38 deletions scripts/set-preview-mode.js

This file was deleted.

0 comments on commit bf69a1a

Please sign in to comment.