Skip to content

Commit d68ad53

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 d68ad53

20 files changed

+286
-238
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: 16 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,11 @@ 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+
156163
// all derived keys
157164
const derived = {
158165
isRoot,
@@ -170,6 +177,13 @@ const getFullConfig = async ({
170177
allPrivate,
171178
// controls whether we are in a monorepo with any public workspaces
172179
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
180+
// git
181+
defaultBranch: isReleaseBranch ? currentBranch : await git.defaultBranch(rootPkg.path),
182+
branches: gitBranches.branches,
183+
branchPatterns: gitBranches.patterns,
184+
isReleaseBranch,
185+
// dependabot
186+
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
173187
// repo
174188
repoDir: rootPkg.path,
175189
repoFiles,
@@ -261,7 +275,7 @@ const getFullConfig = async ({
261275
}
262276
}
263277

264-
const gitUrl = await getGitUrl(rootPkg.path)
278+
const gitUrl = await git.getUrl(rootPkg.path)
265279
if (gitUrl) {
266280
derived.repository = {
267281
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)