Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/branch-utilities/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion packages/branch-utilities/src/lib/base.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof parseBranchName>)

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<typeof parseBranchName>)
})
test('throws when invalid pattern', () => {
expect(() => parseBranchName('whrjwe')).toThrow()
})
Expand Down
23 changes: 15 additions & 8 deletions packages/branch-utilities/src/lib/base.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]*\/?#(?<id>\d+)-(?<name>.*)$/
/**
* 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\/(?<name>fix)-(?<id>\d+)/

export interface StageInfo {
isProd: boolean
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/publish-helper/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down