Skip to content

Commit

Permalink
chore(ci): rewrite release script
Browse files Browse the repository at this point in the history
  • Loading branch information
smellai committed Jul 4, 2024
1 parent 0239914 commit 3f2d9d4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 101 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "eslint ./src/ --fix",
"prettier": "prettier --write src/",
"prepare": "husky",
"semantic-release": "node --loader ts-node/esm ./repo-scripts/release.ts",
"semantic-release": "node --loader ts-node/esm ./repo-scripts/npm-release.ts",
"test:watch": "jest --watch",
"test": "jest --coverage",
"typecheck": "tsc --noEmit",
Expand Down
48 changes: 48 additions & 0 deletions repo-scripts/npm-release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-process-exit */
import fs from 'fs';
import childProcess, { execSync } from 'child_process';
import type { PackageJson } from 'type-fest';

const packageJson: PackageJson = JSON.parse(
fs.readFileSync('package.json').toString()
);

const checkedPackageJson = childProcess.spawnSync('npm', [
'view',
`${packageJson.name}@${packageJson.version}`,
]);

if (checkedPackageJson.stdout.toString() !== '') {
console.log('Package version already exists in npm registry - skip release');
process.exit(0);
}

if (!packageJson.version) {
console.log('No version in package.json');
process.exit(1);
}

const branchName = execSync('git rev-parse --abbrev-ref HEAD')
.toString('utf-8')
.trim();

const tag =
packageJson.version.includes('alpha') && branchName.startsWith('alpha')
? 'alpha'
: packageJson.version.includes('beta') && branchName.startsWith('beta')
? 'beta'
: packageJson.version.includes('canary') &&
branchName.startsWith('canary')
? 'canary'
: packageJson.version.includes('next') && branchName.startsWith('next')
? 'next'
: packageJson.version.includes('rc') && branchName.startsWith('rc')
? 'rc'
: branchName === 'main'
? 'latest'
: '';

console.log(
`Publishing ${packageJson.name}@${packageJson.version} with tag ${tag}`
);
childProcess.execSync(`npm publish --tag ${tag}`);
98 changes: 0 additions & 98 deletions repo-scripts/release.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PackageJson } from 'type-fest';
import type { PackageJson } from 'type-fest';
import { octokit } from './octokitInit.js';
import { ErrorWithResponse, RelevantRepo } from './types';
import type { ErrorWithResponse, RelevantRepo } from './types';

export interface ReadPackageJsonParams {
org: string;
Expand Down

0 comments on commit 3f2d9d4

Please sign in to comment.