Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/approved-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: pull_request_review
name: Add milestone when approved
jobs:
milestoneWhenApproved:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
automations: assign-milestone
10 changes: 0 additions & 10 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Import the default config file and expose it in the project root.
// Useful for editor integrations.
module.exports = require( '@wordpress/prettier-config' );
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ This is a [GitHub Action](https://help.github.com/en/categories/automating-your-

## Available Automations

| Automation | Description |
| ---- | --------------|
| [todos](./lib/automations/todos/README.md) | This automation parses for `@todo` or `@TODO` comments in code and adds formatted pull request comments for each todo found. When a pull request is merged to the main branch, issues will be created for each `@todo` in the diff if there is not already an issue for that todo. |
| [release](./lib/automations/release/README.md) | This automation handles automating various parts of a somewhat opinionated release process.
| Automation | Description |
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [todos](./lib/automations/todos/README.md) | This automation parses for `@todo` or `@TODO` comments in code and adds formatted pull request comments for each todo found. When a pull request is merged to the main branch, issues will be created for each `@todo` in the diff if there is not already an issue for that todo. |
| [release](./lib/automations/release/README.md) | This automation handles automating various parts of a somewhat opinionated release process. |
| [assign-milestone](./lib/automations/assign-milestone/README.md) | This automation will assign the next milestone to a pull request once it has been approved. |

## Installation and Usage

Expand All @@ -16,22 +17,22 @@ To use the action, include it in your workflow configuration file:
```yaml
on: pull_request
jobs:
pull-request-automation:
runs-on: ubuntu-latest
steps:
- uses: woocommerce/automations@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# This can be a comma delimited list of automations to run, in this case we're just executing todos
automations: todos
pull-request-automation:
runs-on: ubuntu-latest
steps:
- uses: woocommerce/automations@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# This can be a comma delimited list of automations to run, in this case we're just executing todos
automations: todos
```

## API

### Inputs

- `github_token`: Required. GitHub API token to use for making API requests. This should be stored as a secret in the GitHub repository.
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.
- `github_token`: Required. GitHub API token to use for making API requests. This should be stored as a secret in the GitHub repository.
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.

### Outputs

Expand All @@ -43,41 +44,41 @@ This will be expanded, but for reference:

### Developing

- Clone the repo and then `npm install`.
- Clone the repo and then `npm install`.

### Builds and releases

- All pushes to trunk will automatically build the `dist/index.js` file for the action (then commit and push to trunk). So no need to worry about builds.
- For releases, make sure you update the examples in the `README.md` if releasing a major version, otherwise just create a release manually (in the future this may get automated for releases).
- All pushes to trunk will automatically build the `dist/index.js` file for the action (then commit and push to trunk). So no need to worry about builds.
- For releases, make sure you update the examples in the `README.md` if releasing a major version, otherwise just create a release manually (in the future this may get automated for releases).

### Adding a new automation.

The design of this repository is setup so that automations can be their own discrete thing (eg. "todos") but still take advantage of various scaffolding and boilerplate when creating a new automation. The following is a rough list of steps to take to create and add a new automation:

- Create a new directory in `lib/automations` that is the name of your automation.
- Your `lib/automations` directory must at a minimum export the following from the `index.js` file in the directory:
- Create a new directory in `lib/automations` that is the name of your automation.
- Your `lib/automations` directory must at a minimum export the following from the `index.js` file in the directory:

```js
module.exports = {
// the name of your automation
name: 'my-automation',
// what github action workflow events your automation reacts to.
events: [ 'pull_request' ],
// what github action workflow event actions your automation reacts to.
actions: [ 'opened' ],
// the runner for your automation.
runner
}
// the name of your automation
name: 'my-automation',
// what github action workflow events your automation reacts to.
events: ['pull_request'],
// what github action workflow event actions your automation reacts to.
actions: ['opened'],
// the runner for your automation.
runner,
};
```
- As noted above, this export must include a `runner` for your automation. The runner is an async function that will receive two arguments: `context` (which is the GitHub action context value) and `octokit` (which is the GitHub api helper). See more about these two arguments [here](https://github.com/actions/toolkit/tree/trunk/packages/github) (they are essentially what gets exposed by the `@actions/github` package). You can use the [`todos` runner as an example](https://github.com/woocommerce/automations/blob/trunk/lib/automations/todos/runner.js).
- Finally, in [`lib/automations.js`](https://github.com/woocommerce/automations/automations/blob/trunk/lib/automations.js), makes sure you import your automation configuration into this file and add it to the `moduleNames` array. So for example, if your automation was setup in `lib/automations/my-automation`, you would have something like this in the file after your changes:

```js
- As noted above, this export must include a `runner` for your automation. The runner is an async function that will receive two arguments: `context` (which is the GitHub action context value) and `octokit` (which is the GitHub api helper). See more about these two arguments [here](https://github.com/actions/toolkit/tree/trunk/packages/github) (they are essentially what gets exposed by the `@actions/github` package). You can use the [`todos` runner as an example](https://github.com/woocommerce/automations/blob/trunk/lib/automations/todos/runner.js).
- Finally, in [`lib/automations.js`](https://github.com/woocommerce/automations/automations/blob/trunk/lib/automations.js), makes sure you import your automation configuration into this file and add it to the `moduleNames` array. So for example, if your automation was setup in `lib/automations/my-automation`, you would have something like this in the file after your changes:

const todos = require( './automations/todos' );
const myAutomation = require( './automations/my-automation' );
```js
const todos = require('./automations/todos');
const myAutomation = require('./automations/my-automation');

const moduleNames = [ todos, myAutomation ];
const moduleNames = [todos, myAutomation];

/**
* @typedef {import('./typedefs').AutomationTask} AutomationTask
Expand All @@ -86,19 +87,18 @@ const moduleNames = [ todos, myAutomation ];
/**
* @type {AutomationTask[]}
*/
const automations = moduleNames.map( ( module ) => module );
const automations = moduleNames.map((module) => module);

module.exports = automations;
```

- make sure you list your automation name and a brief description of what it does in the **Available Automations** section of this readme file.
- make sure you list your automation name and a brief description of what it does in the **Available Automations** section of this readme file.

That's it!

Don't forget to add tests for your automation. There are various helpers available for mocking the `context` and `octokit` values (you can view the various todos automation tests for examples).


## Credits

- Thanks to the work of the [Gutenberg team](https://github.com/wordpress/gutenberg) (particularly [@aduth](https://github.com/aduth)) in providing some inspiration for this approach to bundling various automations together.
- The `todos` automation was inspired by this [todo probot app](https://github.com/JasonEtco/todo). Initial iterations of this action borrowed heavily from the ideas in this app.
- Thanks to the work of the [Gutenberg team](https://github.com/wordpress/gutenberg) (particularly [@aduth](https://github.com/aduth)) in providing some inspiration for this approach to bundling various automations together.
- The `todos` automation was inspired by this [todo probot app](https://github.com/JasonEtco/todo). Initial iterations of this action borrowed heavily from the ideas in this app.
163 changes: 161 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/automations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
module.exports = [
require( './automations/todos' ),
require( './automations/release' ),
require( './automations/assign-milestone' ),
];
37 changes: 37 additions & 0 deletions lib/automations/assign-milestone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Assign Milestone Automation

When a pull request is approved and is not already assigned a milestone, this automation will assign the next milestone to it
automatically.

## Usage

To implement this action, include it in your workflow configuration file:

```yaml
on:
pull_request:
types: [opened, synchronize, closed]
push:
issues:
types: [edited]
jobs:
pull-request-automation:
runs-on: ubuntu-latest
steps:
- uses: woocommerce/automations@v1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should release a @v2 as a result of implementing the new automation (that way if there are unintended issues with existing automations folks can rollback)?

This can be done in a followup if we end up doing that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I'm fine with that. This shouldn't affect existing workflows because you'd need to call assign-milestone by name in your workflow file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh true, I guess there's not any changes to existing tasks (or shared code across tasks) so it's safe to release under the existing version. We could probably reserve version bumps for when there's potentially task breaking changes.

Are you okay with doing a release or want me to take care of it? If you take care of it, this repo uses the release PR automation (similar to process we follow for blocks repo) except the checklist is much smaller. It's currently mostly manual as it's mostly just creating the correct tags etc. The release PR checklist should have all the steps needed.

with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# This can be a comma delimited list of automations to run, in this case we're just executing assign-milestone
automations: assign-milestone
```

## API

### Inputs

- `github_token`: Required. GitHub API token to use for making API requests. You can use the default `secrets.GITHUB_TOKEN` used by GitHub actions or store a different one in the secrets configuration of your GitHub repository.
- `automations`: Optional. You can include a comma-delimited list of specific automations you want to run if you don't want to use them all in a given workflow.

### Outputs

_None._
8 changes: 8 additions & 0 deletions lib/automations/assign-milestone/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const runner = require( './runner' );

module.exports = {
name: 'assign-milestone',
events: [ 'pull_request_review' ],
actions: [ 'submitted', 'edited' ],
runner,
};
Loading