-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): support for rules & ignore sections in config
config file now supports separate sections for ignore directives and auto-merge rules BREAKING CHANGE: - config file is now required - action inputs no longer accept target & command - config file format has changed
- Loading branch information
Ahmad Nassri
committed
Dec 15, 2020
1 parent
67a38ec
commit a3557c6
Showing
19 changed files
with
311 additions
and
310 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
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,28 +1,46 @@ | ||
// internals | ||
import fs from 'fs' | ||
import path from 'path' | ||
import Ajv from 'ajv' | ||
|
||
// packages | ||
import core from '@actions/core' | ||
import yaml from 'js-yaml' | ||
|
||
// require for json loading | ||
import { createRequire } from 'module' | ||
|
||
const require = createRequire(import.meta.url) | ||
const schema = require('./config.schema.json') | ||
|
||
const ajv = new Ajv() | ||
const validate = ajv.compile(schema) | ||
|
||
// default value is passed from workflow | ||
export default function ({ workspace, inputs }) { | ||
const configPath = path.join(workspace || '', inputs.config || '.github/auto-merge.yml') | ||
export default function ({ workspace = '', filename = '.github/auto-merge.yml' }) { | ||
const configPath = path.join(workspace, filename) | ||
|
||
// read auto-merge.yml to determine what should be merged | ||
if (fs.existsSync(configPath)) { | ||
// parse .github/auto-merge.yml | ||
const configYaml = fs.readFileSync(configPath, 'utf8') | ||
const config = yaml.safeLoad(configYaml) | ||
|
||
core.info('loaded merge config: \n' + configYaml) | ||
|
||
// validate config schema | ||
const valid = validate(config) | ||
|
||
if (!valid) { | ||
core.error('invalid config file format') | ||
return process.exit(1) | ||
} | ||
|
||
return config | ||
} | ||
|
||
// or convert the input "target" to the equivalent config | ||
const config = [{ match: { dependency_type: 'all', update_type: `semver:${inputs.target}` } }] | ||
core.info('using workflow\'s "target": \n' + yaml.safeDump(config)) | ||
// create default config structure | ||
|
||
return config | ||
core.error('missing config file') | ||
return process.exit(1) | ||
} |
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,62 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
|
||
"definitions": { | ||
"update_type": { | ||
"type": "string", | ||
"enum": ["security:patch", "semver:patch", "semver:minor", "all"], | ||
"default": "semver:patch" | ||
}, | ||
|
||
"dependency_type": { | ||
"type": "string", | ||
"enum": ["development", "production", "all"], | ||
"default": "all" | ||
}, | ||
|
||
"dependency_name": { | ||
"type": "string" | ||
}, | ||
|
||
"match": { | ||
"type": "object", | ||
"properties": { | ||
"dependency_name": { "$ref": "#/definitions/dependency_name" }, | ||
"dependency_type": { "$ref": "#/definitions/dependency_type" }, | ||
"update_type": { "$ref": "#/definitions/update_type" } | ||
} | ||
} | ||
}, | ||
|
||
"type": "object", | ||
"properties": { | ||
"command": { | ||
"description": "The command to pass to Dependabot as a comment", | ||
"type": "string", | ||
"enum": ["merge", "squash and merge"], | ||
"default": "merge" | ||
}, | ||
|
||
"approve": { | ||
"description": "Auto-approve pull-requests", | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
|
||
"rules": { | ||
"type": "array", | ||
"default": [], | ||
"items": { "$ref": "#/definitions/match" } | ||
}, | ||
"ignore": { | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"dependency_name": { "$ref": "#/definitions/dependency_name" } | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.