-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): support for rules & ignore sections in config #43
Open
ahmadnassri
wants to merge
1
commit into
master
Choose a base branch
from
feat/ignore
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,74 +25,20 @@ jobs: | |
- uses: actions/checkout@v2 | ||
- uses: ahmadnassri/action-dependabot-auto-merge@v2 | ||
with: | ||
target: minor | ||
config: .github/auto-merge.yml | ||
github-token: ${{ secrets.mytoken }} | ||
``` | ||
|
||
The action will only merge PRs whose checks (CI/CD) pass. | ||
|
||
### Examples | ||
|
||
Minimal setup: | ||
|
||
``` yaml | ||
steps: | ||
- uses: ahmadnassri/action-dependabot-auto-merge@v2 | ||
with: | ||
github-token: ${{ secrets.mytoken }} | ||
``` | ||
|
||
Only merge if the changed dependency version is a `patch` *(default behavior)*: | ||
|
||
``` yaml | ||
steps: | ||
- uses: ahmadnassri/action-dependabot-auto-merge@v2 | ||
with: | ||
target: patch | ||
github-token: ${{ secrets.mytoken }} | ||
``` | ||
|
||
Only merge if the changed dependency version is a `minor`: | ||
|
||
``` yaml | ||
steps: | ||
- uses: ahmadnassri/action-dependabot-auto-merge@v2 | ||
with: | ||
target: minor | ||
github-token: ${{ secrets.mytoken }} | ||
``` | ||
|
||
Using a configuration file: | ||
|
||
###### `.github/workflows/auto-merge.yml` | ||
|
||
``` yaml | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ahmadnassri/action-dependabot-auto-merge@v2 | ||
with: | ||
github-token: ${{ secrets.mytoken }} | ||
``` | ||
|
||
###### `.github/auto-merge.yml` | ||
|
||
``` yaml | ||
- match: | ||
dependency_type: all | ||
update_type: "semver:minor" # includes patch updates! | ||
``` | ||
> **Note**: The action will only merge PRs whose checks (CI/CD) pass. | ||
|
||
### Inputs | ||
|
||
| input | required | default | description | | ||
|----------------|----------|--------------------------|-----------------------------------------------------| | ||
| `github-token` | ✔ | `github.token` | The GitHub token used to merge the pull-request | | ||
| `config` | ✔ | `.github/auto-merge.yml` | Path to configuration file *(relative to root)* | | ||
| `target` | ❌ | `patch` | The version comparison target (major, minor, patch) | | ||
| `command` | ❌ | `merge` | The command to pass to Dependabot | | ||
| `approve` | ❌ | `true` | Auto-approve pull-requests | | ||
| input | required | default | description | | ||
|----------------|----------|--------------------------|-------------------------------------------------| | ||
| `github-token` | ✔ | `github.token` | The GitHub token used to merge the pull-request | | ||
| `config` | ✔ | `.github/auto-merge.yml` | Path to configuration file *(relative to root)* | | ||
|
||
### Token Scope | ||
#### Token Scope | ||
|
||
The GitHub token is a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) with the following scopes: | ||
|
||
|
@@ -103,34 +49,46 @@ The token MUST be created from a user with **`push`** permission to the reposito | |
|
||
> ℹ *see reference for [user owned repos](https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/permission-levels-for-a-user-account-repository) and for [org owned repos](https://docs.github.com/en/github/setting-up-and-managing-organizations-and-teams/repository-permission-levels-for-an-organization)* | ||
|
||
### Configuration file syntax | ||
### Configuration File | ||
|
||
A configuration file is **REQUIRED** to successfully determine the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete sentence? |
||
|
||
Using the configuration file *(specified with `config` input)*, you have the option to provide a more fine-grained configuration. The following example configuration file merges | ||
The syntax is loosely based on the [legacy dependaBot v1 config format](https://dependabot.com/docs/config-file/), with `ignore` and `rules` resembling [`ignored_updates`](https://dependabot.com/docs/config-file/#ignored_updates) and [`automerged_updates`](https://dependabot.com/docs/config-file/#automerged_updates) respectively. | ||
|
||
- minor updates for `aws-sdk` | ||
- minor development dependency updates | ||
- patch production dependency updates | ||
- minor security-critical production dependency updates | ||
###### Example | ||
|
||
minimal configuration: | ||
|
||
``` yaml | ||
- match: | ||
dependency_name: aws-sdk | ||
rules: | ||
- dependency_type: all | ||
update_type: semver:minor | ||
``` | ||
|
||
- match: | ||
dependency_type: development | ||
update_type: semver:minor # includes patch updates! | ||
advanced configuration: | ||
|
||
``` yaml | ||
# ignore certain dependencies | ||
ignore: | ||
- dependency_name: react-router | ||
- dependency_name: react-* | ||
|
||
# auto merge rules | ||
rules: | ||
# rule for specific dependency | ||
- dependency_name: aws-sdk | ||
update_type: semver:minor | ||
|
||
- match: | ||
dependency_type: production | ||
update_type: security:minor # includes patch updates! | ||
# rule per dependency type | ||
- dependency_type: development | ||
update_type: semver:minor | ||
|
||
- match: | ||
dependency_type: production | ||
update_type: semver:patch | ||
# rule per update type | ||
- dependency_type: production | ||
update_type: security:minor | ||
``` | ||
|
||
#### Match Properties | ||
#### Properties | ||
|
||
| property | required | supported values | | ||
|-------------------|----------|--------------------------------------------| | ||
|
@@ -151,21 +109,6 @@ Using the configuration file *(specified with `config` input)*, you have the opt | |
> | ||
> To allow `prereleases`, the corresponding `prepatch`, `preminor` and `premajor` types are also supported | ||
|
||
###### Defaults | ||
|
||
By default, if no configuration file is present in the repo, the action will assume the following: | ||
|
||
``` yaml | ||
- match: | ||
dependency_type: all | ||
update_type: semver:${TARGET} | ||
``` | ||
|
||
> Where `$TARGET` is the `target` value from the action [Inputs](#inputs) | ||
|
||
The syntax is based on the [legacy dependaBot v1 config format](https://dependabot.com/docs/config-file/#automerged_updates). | ||
However, **`in_range` is not supported yet**. | ||
|
||
## Exceptions and Edge Cases | ||
|
||
1. Parsing of *version ranges* is not currently supported | ||
|
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" } | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these two are missing from the docs now.