Skip to content

Commit

Permalink
ci: create publish:jsr script
Browse files Browse the repository at this point in the history
  • Loading branch information
@casey_baggz_omni committed May 31, 2024
1 parent cf15808 commit d6658fb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/publish-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: pnpm/action-setup@v4
with:
version: 9.1.4
- uses: actions/setup-node@v4
with:
cache: 'pnpm'

- name: Publish package to JSR
run: npx jsr publish
- run: pnpm install
- run: pnpm run publish:jsr --next --commit ${{ github.sha }}
working-directory: ./configs
12 changes: 10 additions & 2 deletions .github/workflows/publish-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: pnpm/action-setup@v4
with:
version: 9.1.4
- uses: actions/setup-node@v4
with:
cache: 'pnpm'

- name: Publish package to JSR
run: npx jsr publish
- run: pnpm install
- run: pnpm run publish:jsr --stable
working-directory: ./configs
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<img width="1454" alt="banner" src="https://github.com/omnifed/cerberus/assets/4819738/b128be81-3c24-4fc7-8811-6c9a18d26c37">

![NPM Version](https://img.shields.io/npm/v/@cerberus-design/react)
[![JSR](https://jsr.io/badges/@cerberus/react)](https://jsr.io/@cerberus/react)
![NPM License](https://img.shields.io/npm/l/@cerberus-design/react)

## Architecture
Expand Down
3 changes: 2 additions & 1 deletion configs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"src/**/*"
],
"scripts": {
"publish": "bun ./src/publish.mjs"
"publish": "bun ./src/publish.mjs",
"publish:jsr": "bun ./src/publish-jsr.mjs"
},
"peerDependencies": {
"bun": "*",
Expand Down
70 changes: 70 additions & 0 deletions configs/src/publish-jsr.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { argv, file, write, $ } from 'bun'
import { resolve } from 'node:path'
import { exit } from 'node:process'
import { parseArgs } from 'util'
import { version, nextTag, packages } from './versions.mjs'

function _parseFlags(args) {
return parseArgs({
args,
options: {
next: {
type: 'boolean',
},
stable: {
type: 'boolean',
},
commit: {
type: 'string',
},
},
strict: true,
allowPositionals: true,
})
}

function _getReleaseVersion(values) {
if (values.next && !values.commit) throw new Error('Missing commit hash')
if (values.next && values.commit)
return `${version}-next-${values.commit.slice(0, 7)}`
if (values.stable) return version
exit(1)
}

function _getTags(values) {
if (values.next) {
return nextTag
}
if (values.stable) {
return 'latest'
}
exit(1)
}

function publish() {
const { values } = _parseFlags(argv)
const release = _getTags(values)
const nonJSXPackages = packages.filter((pkg) => !pkg.includes('react'))

nonJSXPackages.forEach(async (pkg) => {
const workspacePath = resolve(import.meta.dir, '..', '..', 'packages', pkg)
const jsrJsonPath = resolve(workspacePath, 'jsr.json')
const rawFile = file(jsrJsonPath)
const packageJson = await rawFile.json()
const json = JSON.stringify(
{ ...packageJson, version: _getReleaseVersion(values) },
null,
2,
)

// eslint-disable-next-line no-undef
console.log('Updating version in', jsrJsonPath)
write(jsrJsonPath, json)

// eslint-disable-next-line no-undef
console.log(`Publishing ${pkg} with tag ${release}`)
await $`cd ${workspacePath} && npx jsr publish --tag ${release}`
})
}

publish()

0 comments on commit d6658fb

Please sign in to comment.