From b39c51774742ba3acff820600e4fcee8399b08e3 Mon Sep 17 00:00:00 2001 From: Dario Fazio Date: Mon, 4 Aug 2025 10:56:54 +0200 Subject: [PATCH 1/8] feat(package): add stage-override-to-pr-base script --- packages/branch-utilities/package.json | 6 +++++ .../branch-utilities/src/scripts/index.ts | 1 + .../stage-override-to-pr-base.function.ts | 23 +++++++++++++++++++ .../src/stage-override-to-pr-base.ts | 19 +++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 packages/branch-utilities/src/scripts/index.ts create mode 100644 packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts create mode 100644 packages/branch-utilities/src/stage-override-to-pr-base.ts diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 90743636..1c52f024 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -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..b17371e9 --- /dev/null +++ b/packages/branch-utilities/src/scripts/stage-override-to-pr-base.function.ts @@ -0,0 +1,23 @@ +import { execReturn } from '../lib/helpers.js' + +export interface StageOverrideToPrBaseOptions { + branchNameOverride?: string +} + +export async function stageOverrideToPrBase( + options: StageOverrideToPrBaseOptions | Promise, +): Promise { + const opts = await options + + const gitHubPrJson = execReturn('gh pr list --json headRefName,title,isDraft,closed') + const gitHubPrs = JSON.parse(gitHubPrJson) + + const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF'] + const isPrOverride = !!gitHubPrs.find((pr: any) => pr.headRefName === branchNameOverride) + + // export to env + process.stdout.write(` + 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 From 7af26f3d849be05f4783736a0ecd1f09409b4b40 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Mon, 4 Aug 2025 08:59:43 +0000 Subject: [PATCH 2/8] build(release): next version [skip_build] - @shiftcode/branch-utilities@4.1.0-pr181.0 - @shiftcode/publish-helper@4.0.1-pr181.0 --- package-lock.json | 12 +++++++++--- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5924ce5..b31cc71d 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.0", "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.0.1-pr181.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,7 +14938,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.0", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 1c52f024..cc674a20 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.0", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index b846663a..ac374235 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.0.1-pr181.0", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.0", "@types/yargs": "^17.0.32" }, "peerDependencies": { From 925837bf36a1b3cf05123900cdfc4cbcb1af5053 Mon Sep 17 00:00:00 2001 From: Dario Fazio Date: Mon, 4 Aug 2025 11:24:58 +0200 Subject: [PATCH 3/8] refactor(stage-override): change return type to string and update output handling --- .../src/scripts/stage-override-to-pr-base.function.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 index b17371e9..8f224d93 100644 --- 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 @@ -6,7 +6,7 @@ export interface StageOverrideToPrBaseOptions { export async function stageOverrideToPrBase( options: StageOverrideToPrBaseOptions | Promise, -): Promise { +): Promise { const opts = await options const gitHubPrJson = execReturn('gh pr list --json headRefName,title,isDraft,closed') @@ -15,9 +15,8 @@ export async function stageOverrideToPrBase( const branchNameOverride = opts.branchNameOverride || process.env['GITHUB_BASE_REF'] const isPrOverride = !!gitHubPrs.find((pr: any) => pr.headRefName === branchNameOverride) - // export to env - process.stdout.write(` + return ` export SC_OVERRIDE_BRANCH_NAME=${branchNameOverride} export SC_OVERRIDE_IS_PR=${isPrOverride} - `) + ` } From 01ba9964baf0a045ff07b50c1d0a032f611c9cf6 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Mon, 4 Aug 2025 09:28:53 +0000 Subject: [PATCH 4/8] build(release): next version [skip_build] - @shiftcode/branch-utilities@4.1.0-pr181.1 - @shiftcode/publish-helper@4.0.1-pr181.1 --- package-lock.json | 6 +++--- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b31cc71d..9b7db3e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.0", + "version": "4.1.0-pr181.1", "license": "MIT", "dependencies": { "yargs": "^17.7.2" @@ -14927,7 +14927,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr181.0", + "version": "4.0.1-pr181.1", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14938,7 +14938,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.1", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index cc674a20..6350165c 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.0", + "version": "4.1.0-pr181.1", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index ac374235..c92fbe46 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr181.0", + "version": "4.0.1-pr181.1", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.0", + "@shiftcode/branch-utilities": "^4.1.0-pr181.1", "@types/yargs": "^17.0.32" }, "peerDependencies": { From e3f08f78ed0239dd337b495f814bd3ef6ed32c03 Mon Sep 17 00:00:00 2001 From: Dario Fazio Date: Mon, 4 Aug 2025 11:42:27 +0200 Subject: [PATCH 5/8] feat(publish-helper): update peer dependency version for branch-utilities --- packages/publish-helper/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index c92fbe46..d4e22a49 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -34,7 +34,7 @@ "@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" }, From 664678b16007d12f0cd05c6bc492583581b4a77b Mon Sep 17 00:00:00 2001 From: Github Actions Date: Mon, 4 Aug 2025 09:45:49 +0000 Subject: [PATCH 6/8] build(release): next version [skip_build] - @shiftcode/branch-utilities@4.1.0-pr181.2 - @shiftcode/publish-helper@4.1.0-pr181.0 --- package-lock.json | 8 ++++---- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9b7db3e2..cd79e331 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.1", + "version": "4.1.0-pr181.2", "license": "MIT", "dependencies": { "yargs": "^17.7.2" @@ -14927,7 +14927,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr181.1", + "version": "4.1.0-pr181.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14938,14 +14938,14 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.1", + "@shiftcode/branch-utilities": "^4.1.0-pr181.2", "@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 6350165c..4a8c9883 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.1", + "version": "4.1.0-pr181.2", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index d4e22a49..4b46cc1d 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr181.1", + "version": "4.1.0-pr181.0", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.1", + "@shiftcode/branch-utilities": "^4.1.0-pr181.2", "@types/yargs": "^17.0.32" }, "peerDependencies": { From 3717a5c72167a6700a4078223fded35c36b4b98d Mon Sep 17 00:00:00 2001 From: Dario Fazio Date: Mon, 4 Aug 2025 11:57:55 +0200 Subject: [PATCH 7/8] refactor(stage-override-to-pr-base): replace execReturn with execSync to avoid command log statement --- .../src/scripts/stage-override-to-pr-base.function.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 8f224d93..4311b7f6 100644 --- 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 @@ -1,4 +1,4 @@ -import { execReturn } from '../lib/helpers.js' +import { execSync } from 'node:child_process' export interface StageOverrideToPrBaseOptions { branchNameOverride?: string @@ -9,7 +9,7 @@ export async function stageOverrideToPrBase( ): Promise { const opts = await options - const gitHubPrJson = execReturn('gh pr list --json headRefName,title,isDraft,closed') + 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'] From 87d4e2718f06786a7dbba245b1a3bbe4edfa9364 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Mon, 4 Aug 2025 10:00:14 +0000 Subject: [PATCH 8/8] build(release): next version [skip_build] - @shiftcode/branch-utilities@4.1.0-pr181.3 - @shiftcode/publish-helper@4.1.0-pr181.1 --- package-lock.json | 6 +++--- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd79e331..df3089ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.2", + "version": "4.1.0-pr181.3", "license": "MIT", "dependencies": { "yargs": "^17.7.2" @@ -14927,7 +14927,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr181.0", + "version": "4.1.0-pr181.1", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14938,7 +14938,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.2", + "@shiftcode/branch-utilities": "^4.1.0-pr181.3", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 4a8c9883..a4563039 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "4.1.0-pr181.2", + "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", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index 4b46cc1d..38289673 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr181.0", + "version": "4.1.0-pr181.1", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.1.0-pr181.2", + "@shiftcode/branch-utilities": "^4.1.0-pr181.3", "@types/yargs": "^17.0.32" }, "peerDependencies": {