diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..ed67729 --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,36 @@ +# https://docs.github.com/en/enterprise-cloud@latest/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment +# The copilot-setup-steps.yml workflow won't trigger unless it's present on your main branch. +name: "Copilot Setup Steps" + +# Automatically run the setup steps when they are changed to allow for easy validation, and +# allow manual testing through the repository's "Actions" tab +on: + workflow_dispatch: + push: + paths: + - .github/workflows/copilot-setup-steps.yml + pull_request: + paths: + - .github/workflows/copilot-setup-steps.yml + +jobs: + # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. + copilot-setup-steps: + runs-on: ubuntu-latest + + permissions: + contents: read + + # You can define any steps you want, and they will run before the agent starts. + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node and NPM Cache + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'npm' + + - name: GitHub registry Auth & Install Dependencies + run: npm ci \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e5924ce..267a072 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.0.0", + "version": "4.1.0-pr56.0", "license": "MIT", "engines": { "node": "^20.0.0 || ^22.0.0" @@ -14921,7 +14921,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.0", + "version": "4.0.1-pr56.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,7 +14932,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^4.1.0-pr56.0", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 9074363..6e15ba1 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-pr56.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/branch-utilities/src/lib/base.utils.spec.ts b/packages/branch-utilities/src/lib/base.utils.spec.ts index fdaf49b..24be4d9 100644 --- a/packages/branch-utilities/src/lib/base.utils.spec.ts +++ b/packages/branch-utilities/src/lib/base.utils.spec.ts @@ -81,12 +81,21 @@ describe('base utils', () => { }) describe('parseBranchName', () => { + test('works when valid pattern', () => { - expect(parseBranchName('#7-abc').branchId).toBe(7) + expect(parseBranchName('#7-abc')).toEqual({ branchId: 7, branchName: 'abc' } satisfies ReturnType) + expect(parseBranchName('#72-abc').branchId).toBe(72) + expect(parseBranchName('#000-int').branchId).toBe(0) + expect(parseBranchName('#001-test').branchId).toBe(1) + expect(parseBranchName('#72- whatever').branchId).toBe(72) expect(parseBranchName('feature/#72-ok').branchId).toBe(72) }) + + test('works for github copilot created branches', () => { + expect(parseBranchName('copilot/fix-123')).toEqual({ branchId: 123, branchName: 'fix' } satisfies ReturnType) + }) test('throws when invalid pattern', () => { expect(() => parseBranchName('whrjwe')).toThrow() }) diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index df60bf8..3bb9853 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -8,8 +8,17 @@ export const REGEX_MASTER = /^master$/ /** regex to match the main branch */ export const REGEX_MAIN = /^main$/ -/** regex to match our branch conventions with the following capture groups: fullMatch / branch id / branch name */ -export const REGEX_BRANCH_NAME = /^[a-z]*\/?#(\d+)-(.*)/ +/** + * regex to match our branch conventions with the following named capture groups: id, name + * @example #123-my-feature -> { id: '123', name: 'my-feature' } + * @example feature/#456-yanr -> { id: '456', name: 'yanr' } + */ +const REGEX_BRANCH_NAME_DEFAULT = /^[a-z]*\/?#(?\d+)-(?.*)$/ +/** + * regex to match the branch convention github copilot uses with the following named capture groups: id, name + * @example copilot/fix-789 -> { id: '789', name: 'fix' } + */ +const REGEX_BRANCH_NAME_COPILOT = /copilot\/(?fix)-(?\d+)/ export interface StageInfo { isProd: boolean @@ -134,13 +143,11 @@ export function isMainBranch(branchName: string): boolean { * @throws Throws an error if given branchName does not match our convention */ export function parseBranchName(branchName: string): { branchId: number; branchName: string } { - const matches = branchName.match(REGEX_BRANCH_NAME) - if (matches) { - // [0] full match / [1] branch id / [2] branch name - const [, branchId, branchN] = matches + const matches = REGEX_BRANCH_NAME_DEFAULT.exec(branchName) || REGEX_BRANCH_NAME_COPILOT.exec(branchName) + if (matches && matches.groups) { return { - branchId: parseInt(branchId, 10), - branchName: branchN, + branchId: parseInt(matches.groups['id'], 10), + branchName: matches.groups['name'], } } else { throw new Error( diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index b846663..4e44ea7 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-pr56.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-pr56.0", "@types/yargs": "^17.0.32" }, "peerDependencies": {