From 0b1048c8a80f4307b39a00329d386e521916bd25 Mon Sep 17 00:00:00 2001 From: Joel Cox Date: Sun, 14 Apr 2024 22:13:26 +0800 Subject: [PATCH] fix: release --- .github/workflows/main.yml | 2 +- packages/eslint-config/package.json | 10 +++++- packages/lint/package.json | 10 +++++- packages/release/index.js | 47 +++++++++++++++++++++++++++++ packages/release/package.json | 17 +++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100755 packages/release/index.js create mode 100644 packages/release/package.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1da1955..4f6c369 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - name: yarn run: yarn - name: release - run: yarn workspaces run semantic-release -e semantic-release-monorepo + run: yarn release env: GH_TOKEN: ${{ secrets.GH_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 22204fe..0a294d0 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,7 +1,7 @@ { "name": "@joelbot/eslint-config", "version": "0.0.0", - "private": true, + "private": false, "main": "index.js", "description": "A personal opinionated eslint configuration.", "author": "Joel Cox ", @@ -31,5 +31,13 @@ }, "peerDependencies": { "typescript": "^5.0.0" + }, + "publishConfig": { + "access": "public" + }, + "release": { + "branches": [ + "main" + ] } } diff --git a/packages/lint/package.json b/packages/lint/package.json index ca3c0a6..1ea05ed 100644 --- a/packages/lint/package.json +++ b/packages/lint/package.json @@ -1,7 +1,7 @@ { "name": "@joelbot/lint", "version": "0.0.0", - "private": true, + "private": false, "main": "index.js", "description": "A personal opinionated linting tool.", "keywords": [ @@ -30,5 +30,13 @@ }, "engines": { "node": ">=18" + }, + "publishConfig": { + "access": "public" + }, + "release": { + "branches": [ + "main" + ] } } diff --git a/packages/release/index.js b/packages/release/index.js new file mode 100755 index 0000000..91a7e74 --- /dev/null +++ b/packages/release/index.js @@ -0,0 +1,47 @@ +#!/usr/bin/env node + +import * as fs from 'fs'; +import * as cp from 'child_process'; +import root from 'app-root-path'; +import Debug from 'debug'; + +const debug = Debug(`@joelbot/release`); + +debug('running in directory', process.cwd()); +debug('project root directory is', root.path); + +if (!fs.existsSync('package.json')) { + debug('package.json does not exist, doing nothing'); + process.exit(0); +} + +const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + +if (packageJson.workspaces) { + debug('running in a workspace, looping through workspaces and re-running release'); + const result = cp.spawnSync('yarn', ['workspaces', 'run', 'release'], { + stdio: 'inherit', + }); + process.exit(result.status); +} + +if (packageJson.publishConfig?.access !== 'public') { + debug('publishConfig.access is not public, doing nothing'); + process.exit(0); +} + +debug('publishConfig.access is public, running semantic-release'); + +if (process.cwd() !== root.path) { + debug('running in a workspace folder, using semantic-release-monorepo'); + const result = cp.spawnSync('yarn', ['semantic-release', '-e', 'semantic-release-monorepo'], { + stdio: 'inherit', + }); + process.exit(result.status); +} else { + debug('running semantic-release in project root'); + const result = cp.spawnSync('yarn', ['semantic-release'], { + stdio: 'inherit', + }); + process.exit(result.status); +} diff --git a/packages/release/package.json b/packages/release/package.json new file mode 100644 index 0000000..6bd0287 --- /dev/null +++ b/packages/release/package.json @@ -0,0 +1,17 @@ +{ + "name": "@joelbot/release", + "version": "0.0.0", + "private": true, + "main": "index.js", + "description": "An opinionated semantic-release wrapper / helper tool for my personal projects.", + "author": "Joel Cox ", + "license": "0BSD", + "type": "module", + "dependencies": { + "app-root-path": "^3.1.0", + "debug": "^4.3.4" + }, + "bin": { + "release": "index.js" + } +}