Skip to content

Commit 8dc0546

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 102e1ae commit 8dc0546

20 files changed

+265
-233
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 & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,3 @@ branches:
2424
apps: []
2525
users: []
2626
teams: [ "cli-team" ]
27-
- name: latest
28-
protection:
29-
required_status_checks: null
30-
enforce_admins: true
31-
required_pull_request_reviews:
32-
required_approving_review_count: 1
33-
require_code_owner_reviews: true
34-
require_last_push_approval: true
35-
dismiss_stale_reviews: true
36-
restrictions:
37-
apps: []
38-
users: []
39-
teams: [ "cli-team" ]
40-
- name: release/v*
41-
protection:
42-
required_status_checks: null
43-
enforce_admins: true
44-
required_pull_request_reviews:
45-
required_approving_review_count: 1
46-
require_code_owner_reviews: true
47-
require_last_push_approval: true
48-
dismiss_stale_reviews: true
49-
restrictions:
50-
apps: []
51-
users: []
52-
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: 12 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')
@@ -153,6 +154,9 @@ const getFullConfig = async ({
153154
const publicPkgs = pkgs.filter(p => !p.pkgJson.private)
154155
const allPrivate = pkgs.every(p => p.pkgJson.private)
155156

157+
const branches = uniq([...pkgConfig.branches ?? [], pkgConfig.releaseBranch]).filter(Boolean)
158+
const gitBranches = await git.getBranches(rootPkg.path, branches)
159+
156160
// all derived keys
157161
const derived = {
158162
isRoot,
@@ -170,6 +174,12 @@ const getFullConfig = async ({
170174
allPrivate,
171175
// controls whether we are in a monorepo with any public workspaces
172176
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
177+
// git
178+
defaultBranch: await git.defaultBranch(rootPkg.path),
179+
branches: gitBranches.branches,
180+
branchPatterns: gitBranches.patterns,
181+
// dependabot
182+
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
173183
// repo
174184
repoDir: rootPkg.path,
175185
repoFiles,
@@ -261,7 +271,7 @@ const getFullConfig = async ({
261271
}
262272
}
263273

264-
const gitUrl = await getGitUrl(rootPkg.path)
274+
const gitUrl = await git.getUrl(rootPkg.path)
265275
if (gitUrl) {
266276
derived.repository = {
267277
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/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:

lib/content/dependabot.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
version: 2
22

33
updates:
4+
{{#each dependabot}}
45
- package-ecosystem: npm
5-
directory: {{ pkgDir }}
6+
directory: /
67
schedule:
78
interval: daily
9+
target-branch: "{{ branch }}"
810
allow:
911
- dependency-type: direct
10-
versioning-strategy: {{ dependabot }}
12+
{{#each allowNames }}
13+
dependency-name: "{{ . }}"
14+
{{/each}}
15+
versioning-strategy: {{ strategy }}
1116
commit-message:
1217
prefix: deps
1318
prefix-development: chore
1419
labels:
1520
- "Dependencies"
21+
{{#each labels }}
22+
- "{{ . }}"
23+
{{/each}}
24+
{{/each}}

0 commit comments

Comments
 (0)