-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
run_install: false | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
registry-url: https://registry.npmjs.org/ | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install --recursive --frozen-lockfile | ||
|
||
- run: pnpm publish-package -- --dry-run | ||
working-directory: ./packages/typed-binary | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const colors = { | ||
Reset: '\u001b[0m', | ||
|
||
Black: '\u001b[30m', | ||
Red: '\u001b[31m', | ||
Green: '\u001b[32m', | ||
Yellow: '\u001b[33m', | ||
Blue: '\u001b[34m', | ||
Magenta: '\u001b[35m', | ||
Cyan: '\u001b[36m', | ||
White: '\u001b[37m', | ||
|
||
BrightBlack: '\u001b[30;1m', | ||
BrightRed: '\u001b[31;1m', | ||
BrightGreen: '\u001b[32;1m', | ||
BrightYellow: '\u001b[33;1m', | ||
BrightBlue: '\u001b[34;1m', | ||
BrightMagenta: '\u001b[35;1m', | ||
BrightCyan: '\u001b[36;1m', | ||
BrightWhite: '\u001b[37;1m', | ||
|
||
BgBlack: '\u001b[40m', | ||
BgRed: '\u001b[41m', | ||
BgGreen: '\u001b[42m', | ||
BgYellow: '\u001b[43m', | ||
BgBlue: '\u001b[44m', | ||
BgMagenta: '\u001b[45m', | ||
BgCyan: '\u001b[46m', | ||
BgWhite: '\u001b[47m', | ||
|
||
BgBrightBlack: '\u001b[40;1m', | ||
BgBrightRed: '\u001b[41;1m', | ||
BgBrightGreen: '\u001b[42;1m', | ||
BgBrightYellow: '\u001b[43;1m', | ||
BgBrightBlue: '\u001b[44;1m', | ||
BgBrightMagenta: '\u001b[45;1m', | ||
BgBrightCyan: '\u001b[46;1m', | ||
BgBrightWhite: '\u001b[47;1m', | ||
|
||
Bold: '\u001b[1m', | ||
}; | ||
|
||
export default colors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// @ts-check | ||
import { spawn } from 'node:child_process'; | ||
import fs from 'node:fs/promises'; | ||
import process from 'node:process'; | ||
import arg from 'arg'; | ||
import z from 'zod'; | ||
import colors from './_colors.mjs'; | ||
|
||
const ReleaseChannel = z.enum(['alpha']); | ||
|
||
/** @typedef {z.infer<typeof ReleaseChannel>} ReleaseChannel */ | ||
|
||
const args = arg({}); | ||
const cwd = new URL(`file:${process.cwd()}/`); | ||
const packageJsonUrl = new URL('./package.json', cwd); | ||
|
||
const pkg = JSON.parse(await fs.readFile(packageJsonUrl, 'utf-8')); | ||
|
||
/** | ||
* @param {string} version | ||
* @returns {z.infer<typeof ReleaseChannel> | null} | ||
*/ | ||
function extractChannel(version) { | ||
if (/[a-zA-Z]/.test(version)) { | ||
const channel = Object.values(ReleaseChannel.Values).find((c) => | ||
version.includes(c), | ||
); | ||
|
||
if (!channel) { | ||
throw new Error(`Unrecognized channel: ${channel}`); | ||
} | ||
|
||
return channel; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
const channel = extractChannel(pkg.version); | ||
|
||
/** | ||
* @param {string} command The command to run | ||
* @param {string[]} params The command to run | ||
* @returns {Promise<number>} The exit code of the process | ||
*/ | ||
function promiseSpawn(command, params) { | ||
return new Promise((resolve, reject) => { | ||
const childProcess = spawn(command, params); | ||
|
||
childProcess.on('close', (code) => { | ||
if (code === undefined || code !== 0) { | ||
reject(code); | ||
} else { | ||
resolve(code ?? 1); | ||
} | ||
}); | ||
|
||
childProcess.stdout?.pipe(process.stdout); | ||
childProcess.stderr?.pipe(process.stderr); | ||
}); | ||
} | ||
|
||
async function main() { | ||
console.log( | ||
`\ | ||
Release channel: ${colors.Cyan}${channel ?? '<LATEST>'}${colors.Reset} | ||
`, | ||
); | ||
|
||
try { | ||
await promiseSpawn('pnpm', [ | ||
'publish', | ||
'--provenance', | ||
...(channel ? ['--tag', channel] : []), | ||
...args._, | ||
]); | ||
} catch (e) { | ||
console.error('pnpm publish error code:', e); | ||
process.exit(1); | ||
} | ||
|
||
console.log( | ||
` | ||
------------------------------------------------------------------------- | ||
Package published! | ||
`, | ||
); | ||
} | ||
|
||
main(); |