diff --git a/package-lock.json b/package-lock.json index e5924ce5..df3089ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,8 +14836,14 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.0.0", + "version": "4.1.0-pr181.3", "license": "MIT", + "dependencies": { + "yargs": "^17.7.2" + }, + "bin": { + "stage-override-to-pr-base": "dist/stage-override-to-pr-base.js" + }, "engines": { "node": "^20.0.0 || ^22.0.0" }, @@ -14921,7 +14927,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.0", + "version": "4.1.0-pr181.1", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,14 +14938,14 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.3", "@types/yargs": "^17.0.32" }, "engines": { "node": "^20.0.0 || ^22.0.0" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^4.0.0-pr45", + "@shiftcode/branch-utilities": "^4.1.0 || ^4.1.0-pr181", "lerna": "^8.1.6", "tslib": "^2.3.0" } diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 90743636..a4563039 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "4.0.0", + "version": "4.1.0-pr181.3", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -13,6 +13,9 @@ "default": "./dist/index.js" } }, + "bin": { + "stage-override-to-pr-base": "./dist/stage-override-to-pr-base.js" + }, "scripts": { "prebuild": "rm -rf ./dist", "build": "tsc", @@ -28,6 +31,9 @@ "test:ci": "npm run test", "test:watch": "npm run test -- --watch" }, + "dependencies": { + "yargs": "^17.7.2" + }, "peerDependencies": { "tslib": "^2.3.0" }, diff --git a/packages/branch-utilities/src/scripts/index.ts b/packages/branch-utilities/src/scripts/index.ts new file mode 100644 index 00000000..2fe551fd --- /dev/null +++ b/packages/branch-utilities/src/scripts/index.ts @@ -0,0 +1 @@ +export * from './stage-override-to-pr-base.function.js' \ No newline at end of file diff --git a/packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts b/packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts new file mode 100644 index 00000000..4311b7f6 --- /dev/null +++ b/packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts @@ -0,0 +1,22 @@ +import { execSync } from 'node:child_process' + +export interface StageOverrideToPrBaseOptions { + branchNameOverride?: string +} + +export async function stageOverrideToPrBase( + options: StageOverrideToPrBaseOptions | Promise, +): Promise { + const opts = await options + + const gitHubPrJson = execSync('gh pr list --json headRefName,title,isDraft,closed', { encoding: 'utf8' }).trim() + const gitHubPrs = JSON.parse(gitHubPrJson) + + const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF'] + const isPrOverride = !!gitHubPrs.find((pr: any) => pr.headRefName === branchNameOverride) + + return ` + export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride} + export SC_OVERRIDE_IS_PR=${isPrOverride} + ` +} diff --git a/packages/branch-utilities/src/stage-override-to-pr-base.ts b/packages/branch-utilities/src/stage-override-to-pr-base.ts new file mode 100644 index 00000000..347fef17 --- /dev/null +++ b/packages/branch-utilities/src/stage-override-to-pr-base.ts @@ -0,0 +1,19 @@ +#!/usr/bin/env node +/* eslint-disable no-console */ +import yargs from 'yargs' +import { stageOverrideToPrBase } from './scripts/index.js' + +const args = yargs(process.argv) + .option('branchNameOverride', { + alias: 'b', + type: 'string', + description: 'branch name override to be used as PR base', + }).argv + +try { + const responseMsg = await stageOverrideToPrBase(args) + console.info(responseMsg) +}catch (err){ + console.error(err) + process.exit(1) +} \ No newline at end of file diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index b846663a..38289673 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.0.0", + "version": "4.1.0-pr181.1", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,11 +30,11 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.3", "@types/yargs": "^17.0.32" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^4.0.0-pr45", + "@shiftcode/branch-utilities": "^4.1.0 || ^4.1.0-pr181", "lerna": "^8.1.6", "tslib": "^2.3.0" },