From 0215c5ca1b18b62cac0b26887b3258a563d6a303 Mon Sep 17 00:00:00 2001 From: Dan van der Merwe Date: Thu, 19 Mar 2026 14:07:11 -0400 Subject: [PATCH] ci: publish @hypervideo/drizzle-orm from beta --- .../workflows/publish-hyper-drizzle-orm.yaml | 103 ++++++++++++++++++ drizzle-orm/scripts/prepare-hyper-package.mjs | 48 ++++++++ 2 files changed, 151 insertions(+) create mode 100644 .github/workflows/publish-hyper-drizzle-orm.yaml create mode 100644 drizzle-orm/scripts/prepare-hyper-package.mjs diff --git a/.github/workflows/publish-hyper-drizzle-orm.yaml b/.github/workflows/publish-hyper-drizzle-orm.yaml new file mode 100644 index 0000000000..9a411cadd6 --- /dev/null +++ b/.github/workflows/publish-hyper-drizzle-orm.yaml @@ -0,0 +1,103 @@ +name: Publish Hyper Drizzle ORM Beta + +on: + push: + branches: + - beta + paths: + - '.github/workflows/publish-hyper-drizzle-orm.yaml' + - 'drizzle-orm/**' + - 'package.json' + - 'pnpm-lock.yaml' + workflow_dispatch: + +permissions: + contents: read + packages: write + +concurrency: + group: publish-hyper-drizzle-orm + cancel-in-progress: false + +jobs: + publish: + runs-on: ubuntu-22.04 + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-node@v6 + with: + node-version: '20.19' + registry-url: 'https://npm.pkg.github.com' + scope: '@hypervideo' + + - uses: pnpm/action-setup@v3 + with: + version: 10.6.3 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT" + + - uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build package + run: pnpm --dir drizzle-orm build + + - name: Pack package + run: pnpm --dir drizzle-orm pack + + - name: Compute Hyper version + id: version + shell: bash + run: | + set -euo pipefail + + base_version="$(node -p "require('./drizzle-orm/package.json').version")" + published_versions="$(npm view @hypervideo/drizzle-orm versions --json 2>/dev/null || true)" + + if [[ -z "$published_versions" ]]; then + published_versions='[]' + fi + + next_version="$(BASE_VERSION="$base_version" PUBLISHED_VERSIONS="$published_versions" node <<'NODE' + const baseVersion = process.env.BASE_VERSION; + const published = JSON.parse(process.env.PUBLISHED_VERSIONS ?? '[]'); + const versions = Array.isArray(published) ? published : [published]; + const prefix = `${baseVersion}-hyper.`; + let max = -1; + + for (const version of versions) { + if (typeof version !== 'string' || !version.startsWith(prefix)) { + continue; + } + + const suffix = Number(version.slice(prefix.length)); + if (Number.isInteger(suffix)) { + max = Math.max(max, suffix); + } + } + + process.stdout.write(`${baseVersion}-hyper.${max + 1}`); + NODE + )" + + echo "version=$next_version" >> "$GITHUB_OUTPUT" + + - name: Prepare Hyper tarball + run: node drizzle-orm/scripts/prepare-hyper-package.mjs drizzle-orm/package.tgz "${{ steps.version.outputs.version }}" + + - name: Publish package + run: npm publish ./drizzle-orm/package.tgz --tag hyper diff --git a/drizzle-orm/scripts/prepare-hyper-package.mjs b/drizzle-orm/scripts/prepare-hyper-package.mjs new file mode 100644 index 0000000000..12cd765f3c --- /dev/null +++ b/drizzle-orm/scripts/prepare-hyper-package.mjs @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +import { execFileSync } from 'node:child_process'; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join, resolve } from 'node:path'; + +const [tarballPathArg, versionArg, repositoryUrlArg] = process.argv.slice(2); + +if (!tarballPathArg || !versionArg) { + console.error('Usage: prepare-hyper-package.mjs [repository-url]'); + process.exit(1); +} + +const tarballPath = resolve(tarballPathArg); +const repositoryUrl = repositoryUrlArg ?? 'https://github.com/hypervideo/drizzle-orm.git'; +const repositoryGitUrl = repositoryUrl.startsWith('git+') + ? repositoryUrl + : `git+${repositoryUrl}`; + +const tempRoot = join(tmpdir(), `hyper-drizzle-${process.pid}-${Date.now()}`); +mkdirSync(tempRoot, { recursive: true }); + +try { + execFileSync('tar', ['-xzf', tarballPath, '-C', tempRoot], { stdio: 'inherit' }); + + const packageJsonPath = join(tempRoot, 'package', 'package.json'); + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); + + packageJson.name = '@hypervideo/drizzle-orm'; + packageJson.version = versionArg; + packageJson.publishConfig = { + ...(packageJson.publishConfig ?? {}), + registry: 'https://npm.pkg.github.com', + }; + packageJson.repository = { + type: 'git', + url: repositoryGitUrl, + }; + + writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`); + + execFileSync('tar', ['-czf', tarballPath, '-C', tempRoot, 'package'], { stdio: 'inherit' }); + + console.log(`Prepared ${packageJson.name}@${packageJson.version}`); +} finally { + rmSync(tempRoot, { recursive: true, force: true }); +}