Skip to content

Commit

Permalink
ci: pr previews
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Dec 4, 2024
1 parent a5a2d86 commit 91f684d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
git reset --hard origin/main
pnpm clean
pnpm changeset:prepublish
pnpx pkg-pr-new publish --pnpm --compact './packages/abitype'
PKG_PR_NEW=true pnpx pkg-pr-new publish --pnpm --compact './packages/abitype'
jsr:
name: JSR
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ jobs:
uses: ./.github/workflows/verify.yml
secrets: inherit

preview:
name: Preview
needs: verify
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
uses: wevm/actions/.github/actions/pnpm@main

- name: Publish preview
run: |
pnpm changeset:prepublish
PKG_PR_NEW=true pnpx pkg-pr-new publish --pnpm --compact './packages/abitype'
bench:
name: Benchmark
runs-on: ubuntu-latest
Expand Down
22 changes: 16 additions & 6 deletions scripts/updateVersion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { execSync } from 'node:child_process'
import path from 'node:path'
import { glob } from 'glob'

Expand All @@ -23,22 +24,31 @@ for (const packagePath of packagePaths) {
// Skip private packages
if (packageJson.private) continue

const version = (() => {
if (Bun.env.PKG_PR_NEW) {
const gitHash = execSync('git rev-parse --short HEAD').toString().trim()
const branch = execSync('git branch --show-current')
.toString()
.trim()
.replace(/[^a-zA-Z0-9]/g, '_')
return `0.0.0-${branch}.${gitHash}`
}
return packageJson.version
})()

count += 1
console.log(`${packageJson.name}${packageJson.version}`)
console.log(`${packageJson.name}${version}`)

const versionFilePath = path.resolve(
path.dirname(packagePath),
'src',
'version.ts',
)
await Bun.write(
versionFilePath,
`export const version = '${packageJson.version}'\n`,
)
await Bun.write(versionFilePath, `export const version = '${version}'\n`)

const jsrFilePath = path.resolve(path.dirname(packagePath), 'jsr.json')
const jsrJson = await Bun.file(jsrFilePath).json()
jsrJson.version = packageJson.version
jsrJson.version = version
Bun.write(jsrFilePath, JSON.stringify(jsrJson, null, 2))
}

Expand Down

0 comments on commit 91f684d

Please sign in to comment.