Skip to content

Commit

Permalink
ci: fix JSR.io publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Aug 14, 2024
1 parent fcefc4a commit 5e65f23
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 33 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore(release): ${{ steps.set-version.outputs.version }}" -m "[skip ci]"
git commit -m "chore(release): ${{ steps.set-version.outputs.version }}"
git push
- name: Publish to NPM
Expand All @@ -121,9 +121,15 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create Git Tags
- name: Track Version in Database
run: |
pnpm install -C scripts/versions
pnpm install -C scripts/radashi-db
./scripts/versions/node_modules/.bin/tsx ./scripts/versions/ci-set-latest.ts ${{ steps.set-version.outputs.version }} ${{ github.sha }}
- name: Update Beta Tag
run: |
TAG=v${{ steps.set-version.outputs.version }}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag beta -f
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/publish-jsr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish to JSR

on:
workflow_dispatch:
push:
tags: '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Publish to JSR
env:
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
run: |
pnpm install -C scripts/versions
pnpm install -C scripts/radashi-db
./scripts/versions/node_modules/.bin/tsx ./scripts/versions/ci-publish-jsr.ts
30 changes: 0 additions & 30 deletions .github/workflows/publish-to-jsr.yml

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ npm publish
git cliff 2be4acf455ebec86e846854dbab57bd0bfbbceb7..HEAD --tag v$NEXT_VERSION --output CHANGELOG.md
git add package.json CHANGELOG.md
git commit -m "chore(release): $NEXT_VERSION"

./scripts/versions/node_modules/.bin/tsx ./scripts/versions/ci-set-latest.ts $NEXT_VERSION $(git rev-parse HEAD)

git tag v$NEXT_VERSION
git push
git push --tags
41 changes: 41 additions & 0 deletions scripts/versions/ci-publish-jsr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { execa } from 'execa'
import fs from 'node:fs/promises'
import { supabase } from 'radashi-db/supabase.js'

main()

async function main() {
const versionResult = await supabase
.from('meta')
.select('value')
.eq('id', 'latest_version')
.limit(1)
.single()

if (versionResult.error) {
console.error('Error fetching latest version:', versionResult.error)
process.exit(1)
}

const { version, ref } = versionResult.data.value as {
version: string
ref: string
}

console.log('Publishing v%s using ref %s', version, ref)

await execa('git', ['fetch', 'origin', ref], { stdio: 'inherit' })
await execa('git', ['checkout', ref], { stdio: 'inherit' })

const denoJson = {
...JSON.parse(await fs.readFile('deno.json', 'utf8')),
version,
}

await fs.writeFile('deno.json', JSON.stringify(denoJson, null, 2))
console.log('Updated version in deno.json')

await execa('pnpm', ['dlx', 'jsr', 'publish', '--allow-dirty'], {
stdio: 'inherit',
})
}
27 changes: 27 additions & 0 deletions scripts/versions/ci-set-latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { supabase } from 'radashi-db/supabase.js'

main()

async function main() {
const [version, ref] = process.argv.slice(2)
const channel = version.match(/-(\w+)/)?.[1] ?? 'stable'

const value = { version, ref }
console.log('Updating with:', value)

const { error: upsertError } = await supabase.from('meta').upsert([
{
id: 'latest_version',
value,
},
{
id: channel + '_version',
value,
},
])

if (upsertError) {
console.error('Error upserting version data:', upsertError)
process.exit(1)
}
}
9 changes: 9 additions & 0 deletions scripts/versions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"type": "module",
"dependencies": {
"execa": "^9.3.0",
"radashi-db": "link:../radashi-db",
"tsx": "^4.17.0"
}
}
Loading

0 comments on commit 5e65f23

Please sign in to comment.