-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
04209ea
commit afbda49
Showing
18 changed files
with
633 additions
and
38 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,19 @@ | ||
name: PNPM setup | ||
description: 'Set up pnpm with cache' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: pnpm/action-setup@v2.2.4 | ||
with: | ||
version: 8.0.0 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: pnpm install |
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,13 @@ | ||
{ | ||
"name": "fusion-workspace-helpers", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"private": true, | ||
"dependencies": { | ||
"@actions/core": "^1.10.1", | ||
"@actions/github": "^6.0.0", | ||
"commander": "^11.1.0", | ||
"markdown-table": "^3.0.3", | ||
"tsx": "^4.6.2" | ||
} | ||
} |
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,97 @@ | ||
#!/usr/bin/env node | ||
|
||
const defaultReleaseSchema: ReleaseSchema = { | ||
packages: [], | ||
}; | ||
|
||
import { Command } from 'commander'; | ||
import { execSync } from 'child_process'; | ||
import { setSecret } from '@actions/core'; | ||
import { writeFileSync, existsSync, readFileSync } from 'fs'; | ||
import { parsePackageJson } from './utils/parse-package-json.js'; | ||
import { logInfo } from './utils/logInfo.js'; | ||
|
||
const program = new Command(); | ||
|
||
program.name('PR'); | ||
|
||
program | ||
.command('publish') | ||
.option('-T, --token <token>', 'NPM auth token') | ||
.action(async (args) => { | ||
if (!args.token) { | ||
throw new Error('Missing npm token'); | ||
} | ||
setSecret(args.token); | ||
execSync(`pnpm config set '//registry.npmjs.org/:_authToken' "${args.token}"`, { stdio: 'inherit' }); | ||
createFusionApp(); | ||
}); | ||
|
||
await program.parseAsync(); | ||
|
||
/** | ||
* Returns the next patch of packagejson version | ||
*/ | ||
function packageJsonNextPatch() { | ||
const packageJson = parsePackageJson(); | ||
let version = packageJson.version.split('-')[0]; | ||
|
||
const splitVersion = version.split('.'); | ||
|
||
splitVersion[2] = (parseInt(splitVersion[2]) + 1).toString(); | ||
return splitVersion.join('.'); | ||
} | ||
|
||
export async function createFusionApp() { | ||
preparePackageForVerBump(); | ||
bumpPackageJson(); | ||
publishPrPackage(); | ||
} | ||
|
||
function publishPrPackage() { | ||
const releaseMessage = execSync('pnpm publish --tag pr --json --dry-run --no-git-checks'); | ||
|
||
const npmRelease: NpmRelease = JSON.parse(releaseMessage.toString('utf-8')); | ||
logInfo(npmRelease.id, 'Green'); | ||
appendReleaseLog(npmRelease); | ||
} | ||
|
||
type ReleaseSchema = { | ||
packages: string[]; | ||
}; | ||
|
||
function appendReleaseLog(npmRelease: NpmRelease) { | ||
const fileName = '../../release.json'; | ||
if (!existsSync(fileName)) { | ||
writeFileSync(fileName, JSON.stringify(defaultReleaseSchema, null, 2)); | ||
} | ||
const release = readFileSync(fileName).toString('utf-8'); | ||
const contents: ReleaseSchema = JSON.parse(release); | ||
contents.packages.push(npmRelease.id); | ||
writeFileSync(fileName, JSON.stringify(contents)); | ||
} | ||
|
||
function preparePackageForVerBump() { | ||
const packageJson = parsePackageJson(); | ||
const nextPatch = packageJsonNextPatch(); | ||
const maybeVersion = execSync(`pnpm show ${packageJson.name} --json dist-tags.pr`).toString('utf-8'); | ||
|
||
if (maybeVersion === '') return; | ||
|
||
//There is a pr tag release including the package json ver | ||
if (maybeVersion.includes(nextPatch)) { | ||
packageJson.version = maybeVersion.replaceAll(`"`, ''); | ||
writeFileSync('./package.json', JSON.stringify(packageJson, null, 2)); | ||
} | ||
} | ||
|
||
function bumpPackageJson() { | ||
execSync('pnpm version prerelease --preid pr'); | ||
} | ||
|
||
type NpmRelease = { | ||
id: string; | ||
name: string; | ||
version: number; | ||
unpackedSize: number; | ||
}; |
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,26 @@ | ||
const ColorReset = '\x1b[0m'; | ||
type TextColor = | ||
| 'Red' | ||
| 'Green' | ||
| 'Black' | ||
| 'Yellow' | ||
| 'Blue' | ||
| 'Magenta' | ||
| 'Cyan' | ||
| 'White'; | ||
|
||
const textColor = { | ||
Red: '\x1b[31m', | ||
Black: '\x1b[30m', | ||
Green: '\x1b[32m', | ||
Yellow: '\x1b[33m', | ||
Blue: '\x1b[34m', | ||
Magenta: '\x1b[35m', | ||
Cyan: '\x1b[36m', | ||
White: '\x1b[37m', | ||
} satisfies Record<TextColor, string>; | ||
|
||
export function logInfo(message: string, color: TextColor): void { | ||
console.log(`${textColor[color]}${message}${ColorReset}`); | ||
} | ||
|
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,12 @@ | ||
import fs from 'fs'; | ||
|
||
export type PackageJson = { | ||
name?: string; | ||
version?: string; | ||
type?: 'module' | 'commonjs'; | ||
} & Record<string, any>; | ||
|
||
export function parsePackageJson(path: string = './package.json'): PackageJson { | ||
const blob = fs.readFileSync(path); | ||
return JSON.parse(blob.toString('utf-8')); | ||
} |
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"target": "ESNext" | ||
}, | ||
"include": ["src"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Publish PR build | ||
on: | ||
workflow_dispatch: | ||
permissions: | ||
actions: read | ||
checks: write | ||
contents: read | ||
deployments: write | ||
id-token: write | ||
statuses: write | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
environment: npm | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: PNPM setup | ||
uses: ./.github/actions/pnpm-setup | ||
|
||
- name: Build monorepo | ||
run: pnpm build | ||
|
||
- name: Publish PR version | ||
run: | | ||
pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" | ||
pnpm preship --no-git-checks |
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
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
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
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
Oops, something went wrong.