Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/publish-hyper-drizzle-orm.yaml
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions drizzle-orm/scripts/prepare-hyper-package.mjs
Original file line number Diff line number Diff line change
@@ -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 <tarball-path> <version> [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 });
}
Loading