From b0f502a9afa0d49fa5a249ccafc6625411db79a4 Mon Sep 17 00:00:00 2001 From: Patrick Suter Date: Fri, 12 Jul 2024 11:35:44 +0200 Subject: [PATCH 1/5] feat(branch-utilities): added branchName and isPr override via ENV --- .../branch-utilities/src/lib/base.utils.ts | 21 ++++++++++++++++++- .../src/lib/types/sc-override-env-var.type.ts | 6 +++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index e8c58b3..783b528 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -43,7 +43,12 @@ export function createStageInfo(stage: string): StageInfo { */ export function getBranchInfo(env: unknown, branchName?: string): BranchInfo { let isPr = false - if (isGithubWorkflow(env)) { + + if (isFullBranchOverrideDefined(env)) { + // full branch name override via en vars SC_OVERRIDE_BRANCH_NAME and SC_OVERRIDE_IS_PR + branchName = getBranchNameOverride(env) + isPr = getIsPrOverride(env) + } else if (isGithubWorkflow(env)) { // github workflow environment branchName = branchName ?? getGithubBranchName(env) isPr = isGithubPullRequest(env) @@ -75,6 +80,20 @@ export function getBranchInfo(env: unknown, branchName?: string): BranchInfo { } } +export function isFullBranchOverrideDefined(envVars: unknown): envVars is CustomScOverrideEnv { + return envVars !== null + && typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_BRANCH_NAME ==='string' + && typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_IS_PR ==='string' +} + +export function getBranchNameOverride(env: CustomScOverrideEnv): string { + return env.SC_OVERRIDE_BRANCH_NAME +} + +export function getIsPrOverride(env: CustomScOverrideEnv): boolean { + return env.SC_OVERRIDE_IS_PR === 'true' +} + /** * @return Returns the branch name. The name is resolved depending on provided environment (github actions | local). */ diff --git a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts index ab5886c..3d7bd80 100644 --- a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts +++ b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts @@ -1,5 +1,9 @@ export interface CustomScOverrideEnv { - /** stringified object of type {@link GitHubContext} */ + /** flag to allow usage of master branch locally */ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE: 'true' | any + /** flag to override branchName for getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ + SC_OVERRIDE_BRANCH_NAME: string | any + /** flag to override isPr getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ + SC_OVERRIDE_IS_PR: string | any } From a27601504cda2221dd0cdeda24ab24a029d4f8d0 Mon Sep 17 00:00:00 2001 From: Patrick Suter Date: Fri, 12 Jul 2024 11:38:25 +0200 Subject: [PATCH 2/5] feat(branch-utilities): make eslint happy --- .../branch-utilities/src/lib/types/sc-override-env-var.type.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts index 3d7bd80..9d6278e 100644 --- a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts +++ b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts @@ -3,7 +3,9 @@ export interface CustomScOverrideEnv { // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE: 'true' | any /** flag to override branchName for getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE_BRANCH_NAME: string | any /** flag to override isPr getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE_IS_PR: string | any } From 65f3bde7ab6da506ac5015e0e75f95ca1f66bd10 Mon Sep 17 00:00:00 2001 From: Patrick Suter Date: Fri, 12 Jul 2024 14:32:38 +0200 Subject: [PATCH 3/5] feat(branch-utilities): add tests and fix typos --- .../branch-utilities/src/lib/base.utils.spec.ts | 17 +++++++++++++++++ packages/branch-utilities/src/lib/base.utils.ts | 2 +- .../src/lib/types/sc-override-env-var.type.ts | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/branch-utilities/src/lib/base.utils.spec.ts b/packages/branch-utilities/src/lib/base.utils.spec.ts index e3b0e20..fdaf49b 100644 --- a/packages/branch-utilities/src/lib/base.utils.spec.ts +++ b/packages/branch-utilities/src/lib/base.utils.spec.ts @@ -10,6 +10,8 @@ describe('base utils', () => { test('works when master run locally with override', () => { const env: CustomScOverrideEnv = { SC_OVERRIDE: 'true', + SC_OVERRIDE_BRANCH_NAME: undefined, + SC_OVERRIDE_IS_PR: undefined, } expect(getBranchInfo(env, 'master')).toEqual({ stage: 'master', @@ -61,6 +63,21 @@ describe('base utils', () => { name: 'master', }) }) + + test('works with env var overrides', () => { + const env: CustomScOverrideEnv = { + SC_OVERRIDE: 'true', + SC_OVERRIDE_BRANCH_NAME: '#1313-on-branch-to-override-them-all', + SC_OVERRIDE_IS_PR: 'true', + } + expect(getBranchInfo(env, 'master')).toEqual({ + stage: 'pr1313', + isPr: true, + isProd: false, + name: 'on-branch-to-override-them-all', + branchName: '#1313-on-branch-to-override-them-all', + }) + }) }) describe('parseBranchName', () => { diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index 783b528..df60bf8 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -45,7 +45,7 @@ export function getBranchInfo(env: unknown, branchName?: string): BranchInfo { let isPr = false if (isFullBranchOverrideDefined(env)) { - // full branch name override via en vars SC_OVERRIDE_BRANCH_NAME and SC_OVERRIDE_IS_PR + // full branch name override via env vars SC_OVERRIDE_BRANCH_NAME and SC_OVERRIDE_IS_PR branchName = getBranchNameOverride(env) isPr = getIsPrOverride(env) } else if (isGithubWorkflow(env)) { diff --git a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts index 9d6278e..d533d94 100644 --- a/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts +++ b/packages/branch-utilities/src/lib/types/sc-override-env-var.type.ts @@ -5,7 +5,7 @@ export interface CustomScOverrideEnv { /** flag to override branchName for getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE_BRANCH_NAME: string | any - /** flag to override isPr getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_IS_PR */ + /** flag to override isPr getBranchInfo(), needs to be used in conjunction with SC_OVERRIDE_BRANCH_NAME */ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents,@typescript-eslint/naming-convention SC_OVERRIDE_IS_PR: string | any } From 8f921f10320602223c610a9aa19f9094dc2ac368 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Fri, 12 Jul 2024 12:34:26 +0000 Subject: [PATCH 4/5] build(release): next version [skip_build] - @shiftcode/branch-utilities@2.2.0-pr30.0 - @shiftcode/publish-helper@2.1.1-pr30.0 --- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 135b566..16b47e3 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "2.1.0", + "version": "2.2.0-pr30.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 f1956e2..77e7496 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "2.1.0", + "version": "2.1.1-pr30.0", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.6.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^2.1.0", + "@shiftcode/branch-utilities": "^2.2.0-pr30.0", "@types/yargs": "^17.0.13" }, "peerDependencies": { From cf671a48b9b06c8963b059643dbc4716429eb25d Mon Sep 17 00:00:00 2001 From: Github Actions Date: Sat, 13 Jul 2024 07:54:48 +0000 Subject: [PATCH 5/5] build(release): next version [skip_build] - @shiftcode/branch-utilities@3.1.0-pr30.0 - @shiftcode/publish-helper@3.0.1-pr30.0 --- 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 e8d7c77..cf09db5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13172,7 +13172,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "3.0.0", + "version": "3.1.0-pr30.0", "license": "MIT", "peerDependencies": { "tslib": "^2.3.0" @@ -13234,7 +13234,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "3.0.0", + "version": "3.0.1-pr30.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^5.0.13", @@ -13245,7 +13245,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^3.0.0", + "@shiftcode/branch-utilities": "^3.1.0-pr30.0", "@types/yargs": "^17.0.32" }, "peerDependencies": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 12b025d..8f0523d 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "3.0.0", + "version": "3.1.0-pr30.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 17c05aa..9d5b38b 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "3.0.0", + "version": "3.0.1-pr30.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": "^3.0.0", + "@shiftcode/branch-utilities": "^3.1.0-pr30.0", "@types/yargs": "^17.0.32" }, "peerDependencies": {