-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Fixes #329
- Loading branch information
1 parent
102e1ae
commit 2c7aadf
Showing
20 changed files
with
265 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ on: | |
push: | ||
branches: | ||
- main | ||
- latest | ||
- release/v* | ||
paths: | ||
- workspace/test-workspace/** | ||
schedule: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ on: | |
push: | ||
branches: | ||
- main | ||
- latest | ||
- release/v* | ||
|
||
permissions: | ||
contents: write | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
version: 2 | ||
|
||
updates: | ||
{{#each dependabot}} | ||
- package-ecosystem: npm | ||
directory: {{ pkgDir }} | ||
directory: / | ||
schedule: | ||
interval: daily | ||
target-branch: "{{ branch }}" | ||
allow: | ||
- dependency-type: direct | ||
versioning-strategy: {{ dependabot }} | ||
{{#each allowNames }} | ||
dependency-name: "{{ . }}" | ||
{{/each}} | ||
versioning-strategy: {{ strategy }} | ||
commit-message: | ||
prefix: deps | ||
prefix-development: chore | ||
labels: | ||
- "Dependencies" | ||
{{#each labels }} | ||
- "{{ . }}" | ||
{{/each}} | ||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
type: string | ||
push: | ||
branches: | ||
{{#each branches}} | ||
{{#each branchPatterns}} | ||
- {{ . }} | ||
{{/each}} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { name: NAME } = require('../../package.json') | ||
const { minimatch } = require('minimatch') | ||
|
||
const parseDependabotConfig = (v) => typeof v === 'string' ? { strategy: v } : (v ?? {}) | ||
|
||
module.exports = (config, defaultConfig, branches) => { | ||
const { dependabot } = config | ||
const { dependabot: defaultDependabot } = defaultConfig | ||
|
||
if (!dependabot) { | ||
return false | ||
} | ||
|
||
return branches | ||
.filter((b) => dependabot[b] !== false) | ||
.map(branch => { | ||
const isRelease = minimatch(branch, config.releaseBranch) | ||
|
||
return { | ||
branch, | ||
allowNames: isRelease ? [NAME] : [], | ||
labels: isRelease ? ['Backport', branch] : [], | ||
...parseDependabotConfig(defaultDependabot), | ||
...parseDependabotConfig(dependabot), | ||
...parseDependabotConfig(dependabot[branch]), | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const hgi = require('hosted-git-info') | ||
const git = require('@npmcli/git') | ||
const { minimatch } = require('minimatch') | ||
|
||
const cache = new Map() | ||
|
||
const tryGit = async (path, ...args) => { | ||
if (!await git.is({ cwd: path })) { | ||
throw new Error('no git') | ||
} | ||
const key = [path, ...args].join(',') | ||
if (cache.has(key)) { | ||
return cache.get(key) | ||
} | ||
const res = git.spawn(args, { cwd: path }).then(r => r.stdout.trim()) | ||
cache.set(key, res) | ||
return res | ||
} | ||
|
||
// parse a repo from a git origin into a format | ||
// for a package.json#repository object | ||
const getUrl = async (path) => { | ||
try { | ||
const urlStr = await tryGit(path, 'remote', 'get-url', 'origin') | ||
const { domain, user, project } = hgi.fromUrl(urlStr) | ||
const url = new URL(`https://${domain}`) | ||
url.pathname = `/${user}/${project}.git` | ||
return url.toString() | ||
} catch { | ||
// errors are ignored | ||
} | ||
} | ||
|
||
const getBranches = async (path, branchPatterns) => { | ||
let matchingBranches = new Set() | ||
let matchingPatterns = new Set() | ||
|
||
try { | ||
const res = await tryGit(path, 'ls-remote', '--heads', 'origin').then(r => r.split('\n')) | ||
const remotes = res.map((h) => h.match(/refs\/heads\/(.*)$/)).filter(Boolean).map(h => h[1]) | ||
for (const branch of remotes) { | ||
for (const pattern of branchPatterns) { | ||
if (minimatch(branch, pattern)) { | ||
matchingBranches.add(branch) | ||
matchingPatterns.add(pattern) | ||
} | ||
} | ||
} | ||
} catch { | ||
matchingBranches = new Set(branchPatterns.filter(b => !b.includes('*'))) | ||
matchingPatterns = new Set(branchPatterns) | ||
} | ||
|
||
return { | ||
branches: [...matchingBranches], | ||
patterns: [...matchingPatterns], | ||
} | ||
} | ||
|
||
const defaultBranch = async (path) => { | ||
try { | ||
const remotes = await tryGit(path, 'remote', 'show', 'origin') | ||
const branch = remotes.match(/HEAD branch: (.*)$/m) | ||
return branch[1] | ||
} catch { | ||
return 'main' | ||
} | ||
} | ||
|
||
module.exports = { | ||
getUrl, | ||
getBranches, | ||
defaultBranch, | ||
} |
Oops, something went wrong.