Skip to content

Commit f04a76d

Browse files
committed
feat: use git remote for branch related config
This will check the origin remote if it exists and use that to determine which branches exist. These branches are then used to populate CI branches, branch protections, and dependabot. Using this for dependabot is a new feature which allows old release branches to get dependency updates for template-oss only. This also updates the dependabot config to only update the root directory instead of each workspace directory. The previous way was an attempt to get it to work with workspaces, but wasn't used in any our repos. Dependabot should now be able to update workspaces when configured to use a single root directory. Fixes #329
1 parent 4662ec3 commit f04a76d

21 files changed

+288
-239
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@ updates:
77
directory: /
88
schedule:
99
interval: daily
10-
allow:
11-
- dependency-type: direct
12-
versioning-strategy: increase-if-necessary
13-
commit-message:
14-
prefix: deps
15-
prefix-development: chore
16-
labels:
17-
- "Dependencies"
18-
- package-ecosystem: npm
19-
directory: workspace/test-workspace/
20-
schedule:
21-
interval: daily
10+
target-branch: "main"
2211
allow:
2312
- dependency-type: direct
2413
versioning-strategy: increase-if-necessary

.github/settings.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,3 @@ branches:
2525
apps: []
2626
users: []
2727
teams: [ "cli-team" ]
28-
- name: latest
29-
protection:
30-
required_status_checks: null
31-
enforce_admins: true
32-
block_creations: true
33-
required_pull_request_reviews:
34-
required_approving_review_count: 1
35-
require_code_owner_reviews: true
36-
require_last_push_approval: true
37-
dismiss_stale_reviews: true
38-
restrictions:
39-
apps: []
40-
users: []
41-
teams: [ "cli-team" ]
42-
- name: release/v*
43-
protection:
44-
required_status_checks: null
45-
enforce_admins: true
46-
block_creations: true
47-
required_pull_request_reviews:
48-
required_approving_review_count: 1
49-
require_code_owner_reviews: true
50-
require_last_push_approval: true
51-
dismiss_stale_reviews: true
52-
restrictions:
53-
apps: []
54-
users: []
55-
teams: [ "cli-team" ]

.github/workflows/ci-test-workspace.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- latest
14-
- release/v*
1513
paths:
1614
- workspace/test-workspace/**
1715
schedule:

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- latest
14-
- release/v*
1513
paths-ignore:
1614
- workspace/test-workspace/**
1715
schedule:

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ on:
66
push:
77
branches:
88
- main
9-
- latest
10-
- release/v*
119
pull_request:
1210
branches:
1311
- main
14-
- latest
15-
- release/v*
1612
schedule:
1713
# "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
1814
- cron: "0 10 * * 1"

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ on:
1111
push:
1212
branches:
1313
- main
14-
- latest
15-
- release/v*
1614

1715
permissions:
1816
contents: write

lib/config.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { relative, dirname, join, extname, posix, win32 } = require('path')
22
const { defaults, pick, omit, uniq } = require('lodash')
33
const semver = require('semver')
44
const parseCIVersions = require('./util/parse-ci-versions.js')
5-
const getGitUrl = require('./util/get-git-url.js')
5+
const parseDependabot = require('./util/dependabot.js')
6+
const git = require('./util/git.js')
67
const gitignore = require('./util/gitignore.js')
78
const { mergeWithArrays } = require('./util/merge.js')
89
const { FILE_KEYS, parseConfig: parseFiles, getAddedFiles, mergeFiles } = require('./util/files.js')
@@ -11,6 +12,7 @@ const CONFIG_KEY = 'templateOSS'
1112
const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {}
1213

1314
const { name: NAME, version: LATEST_VERSION } = require('../package.json')
15+
const { minimatch } = require('minimatch')
1416
const MERGE_KEYS = [...FILE_KEYS, 'defaultContent', 'content']
1517
const DEFAULT_CONTENT = require.resolve(NAME)
1618

@@ -153,6 +155,12 @@ const getFullConfig = async ({
153155
const publicPkgs = pkgs.filter(p => !p.pkgJson.private)
154156
const allPrivate = pkgs.every(p => p.pkgJson.private)
155157

158+
const branches = uniq([...pkgConfig.branches ?? [], pkgConfig.releaseBranch]).filter(Boolean)
159+
const gitBranches = await git.getBranches(rootPkg.path, branches)
160+
const currentBranch = await git.currentBranch(rootPkg.path)
161+
const isReleaseBranch = currentBranch ? minimatch(currentBranch, pkgConfig.releaseBranch) : false
162+
const defaultBranch = await git.defaultBranch(rootPkg.path) ?? 'main'
163+
156164
// all derived keys
157165
const derived = {
158166
isRoot,
@@ -170,6 +178,14 @@ const getFullConfig = async ({
170178
allPrivate,
171179
// controls whether we are in a monorepo with any public workspaces
172180
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
181+
// git
182+
defaultBranch,
183+
baseBranch: isReleaseBranch ? currentBranch : defaultBranch,
184+
branches: gitBranches.branches,
185+
branchPatterns: gitBranches.patterns,
186+
isReleaseBranch,
187+
// dependabot
188+
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
173189
// repo
174190
repoDir: rootPkg.path,
175191
repoFiles,
@@ -261,7 +277,7 @@ const getFullConfig = async ({
261277
}
262278
}
263279

264-
const gitUrl = await getGitUrl(rootPkg.path)
280+
const gitUrl = await git.getUrl(rootPkg.path)
265281
if (gitUrl) {
266282
derived.repository = {
267283
type: 'git',

lib/content/_on-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pull_request:
1212
{{/if}}
1313
push:
1414
branches:
15-
{{#each branches}}
15+
{{#each branchPatterns}}
1616
- {{ . }}
1717
{{/each}}
1818
{{#if isWorkspace}}

lib/content/ci-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
ref:
88
required: true
99
type: string
10-
default: {{ defaultBranch }}
10+
default: {{ baseBranch }}
1111
workflow_call:
1212
inputs:
1313
ref:

lib/content/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: CodeQL
33
on:
44
push:
55
branches:
6-
{{#each branches}}
6+
{{#each branchPatterns}}
77
- {{ . }}
88
{{/each}}
99
pull_request:
1010
branches:
11-
{{#each branches}}
11+
{{#each branchPatterns}}
1212
- {{ . }}
1313
{{/each}}
1414
schedule:

0 commit comments

Comments
 (0)