Skip to content

Commit 462f977

Browse files
committed
Updated README and added missing required param
1 parent 22e267b commit 462f977

File tree

2 files changed

+62
-170
lines changed

2 files changed

+62
-170
lines changed

README.md

Lines changed: 58 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -1,214 +1,102 @@
1-
# Create a GitHub Action Using TypeScript
1+
# Regex Match Commenter Action
22

3-
[![GitHub Super-Linter](https://github.com/actions/typescript-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
4-
![CI](https://github.com/actions/typescript-action/actions/workflows/ci.yml/badge.svg)
5-
[![Check dist/](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml)
6-
[![CodeQL](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml)
3+
[![GitHub Super-Linter](https://github.com/zumba/regex-match-commenter-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
4+
![CI](https://github.com/zumba/regex-match-commenter-action/actions/workflows/ci.yml/badge.svg)
5+
[![Check dist/](https://github.com/zumba/regex-match-commenter-action/actions/workflows/check-dist.yml/badge.svg)](https://github.com/zumba/regex-match-commenter-action/actions/workflows/check-dist.yml)
6+
[![CodeQL](https://github.com/zumba/regex-match-commenter-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/zumba/regex-match-commenter-action/actions/workflows/codeql-analysis.yml)
77
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)
88

9-
Use this template to bootstrap the creation of a TypeScript action. :rocket:
9+
This GitHub Action searches for specified regular expression patterns in the changes of a pull request. If matches are found, it can optionally mark the pull request for changes and add inline comments. If no matches are found, a comment is added to the pull request.
1010

11-
This template includes compilation support, tests, a validation workflow,
12-
publishing, and versioning guidance.
11+
Some use cases are for detecting PII changes on the code. For example, you can monitor if the words `email`, `phone`, `street`, `password`, etc. are part of the changes.
12+
The match uses regex, so you can also look for variables such as `\w+@\w+.\w+` to look for an actual e-mail address.
1313

14-
If you are new, there's also a simpler introduction in the
15-
[Hello world JavaScript action repository](https://github.com/actions/hello-world-javascript-action).
14+
## Inputs
1615

17-
## Create Your Own Action
16+
### `github_token`
1817

19-
To create your own action, you can use this repository as a template! Just
20-
follow the below instructions:
18+
**Required** GitHub token for authentication. Typically, this is the GitHub Actions token.
2119

22-
1. Click the **Use this template** button at the top of the repository
23-
1. Select **Create a new repository**
24-
1. Select an owner and name for your new repository
25-
1. Click **Create repository**
26-
1. Clone your new repository
20+
### `regex_patterns`
2721

28-
> [!IMPORTANT]
29-
>
30-
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
31-
> details on how to use this file, see
32-
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).
22+
**Required** A comma-separated list of regular expression patterns to search for in the pull request diff.
3323

34-
## Initial Setup
24+
### `diff_scope`
3525

36-
After you've cloned the repository to your local machine or codespace, you'll
37-
need to perform some initial setup steps before you can develop your action.
26+
The scope of the diff to search. Can be `added`, `removed`, or `both`. Default is `both`.
3827

39-
> [!NOTE]
40-
>
41-
> You'll need to have a reasonably modern version of
42-
> [Node.js](https://nodejs.org) handy (20.x or later should work!). If you are
43-
> using a version manager like [`nodenv`](https://github.com/nodenv/nodenv) or
44-
> [`nvm`](https://github.com/nvm-sh/nvm), this template has a `.node-version`
45-
> file at the root of the repository that will be used to automatically switch
46-
> to the correct version when you `cd` into the repository. Additionally, this
47-
> `.node-version` file is used by GitHub Actions in any `actions/setup-node`
48-
> actions.
49-
50-
1. :hammer_and_wrench: Install the dependencies
51-
52-
```bash
53-
npm install
54-
```
55-
56-
1. :building_construction: Package the TypeScript for distribution
57-
58-
```bash
59-
npm run bundle
60-
```
28+
### `mark_changes_requested`
6129

62-
1. :white_check_mark: Run the tests
30+
Boolean indicating whether the pull request should be marked as "request changes" if regex matches are found. Default is `false`.
6331

64-
```bash
65-
$ npm test
32+
### `match_found_message`
6633

67-
PASS ./index.test.js
68-
✓ throws invalid number (3ms)
69-
wait 500 ms (504ms)
70-
test runs (95ms)
34+
Custom message for a regex match. This message is used for inline comments on the pull request. Default is `Regex match found.`.
7135

72-
...
73-
```
36+
### `no_match_found_message`
7437

75-
## Update the Action Metadata
38+
Custom message to comment on the pull request when no regex matches are found. Default is `No regex matches found in the diff.`
7639

77-
The [`action.yml`](action.yml) file defines metadata about your action, such as
78-
input(s) and output(s). For details about this file, see
79-
[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
40+
### `changes_requested_message`
8041

81-
When you copy this repository, update `action.yml` with the name, description,
82-
inputs, and outputs for your action.
42+
Custom message for marking the pull request as changes requested. Used only if `mark_changes_requested` is `true`. Default is `Changes are requested due to regex match.`
8343

84-
## Update the Action Code
44+
## Usage
8545

86-
The [`src/`](./src/) directory is the heart of your action! This contains the
87-
source code that will be run when your action is invoked. You can replace the
88-
contents of this directory with your own code.
46+
To use this action, create a workflow file (e.g., `.github/workflows/regex-match.yml`) in your repository:
8947

90-
There are a few things to keep in mind when writing your action code:
48+
```yaml
49+
name: Regex Match
50+
51+
on: [pull_request]
52+
53+
jobs:
54+
regex-match:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v2
58+
- name: Regex Match Action
59+
uses: zumba/regex-match-commenter-action@v1
60+
with:
61+
github_token: ${{ secrets.GITHUB_TOKEN }}
62+
regex_patterns: 'email'
63+
diff_scope: 'both'
64+
mark_changes_requested: false
65+
match_found_message: 'Attention needed.'
66+
no_match_found_message: 'No issues detected in the diff.'
67+
changes_requested_message: 'Please address the commented issues.'
68+
```
9169
92-
- Most GitHub Actions toolkit and CI/CD operations are processed asynchronously.
93-
In `main.ts`, you will see that the action is run in an `async` function.
70+
## Contributing
9471
95-
```javascript
96-
import * as core from '@actions/core'
97-
//...
72+
Contributions to this action are welcome! Please follow the standard GitHub pull request workflow to submit your changes.
9873
99-
async function run() {
100-
try {
101-
//...
102-
} catch (error) {
103-
core.setFailed(error.message)
104-
}
105-
}
106-
```
10774
108-
For more information about the GitHub Actions toolkit, see the
109-
[documentation](https://github.com/actions/toolkit/blob/master/README.md).
75+
## Development Setup
11076
111-
So, what are you waiting for? Go ahead and start customizing your action!
77+
After you've cloned the repository to your local machine or codespace, you'll
78+
need to perform some initial setup steps before you can develop your action.
11279
113-
1. Create a new branch
80+
1. :hammer_and_wrench: Install the dependencies
11481
11582
```bash
116-
git checkout -b releases/v1
83+
npm install
11784
```
11885

119-
1. Replace the contents of `src/` with your action code
120-
1. Add tests to `__tests__/` for your source code
121-
1. Format, test, and build the action
86+
1. :building_construction: Package the TypeScript for distribution
12287

12388
```bash
124-
npm run all
89+
npm run bundle
12590
```
12691

127-
> [!WARNING]
128-
>
129-
> This step is important! It will run [`ncc`](https://github.com/vercel/ncc)
130-
> to build the final JavaScript action code with all dependencies included.
131-
> If you do not run this step, your action will not work correctly when it is
132-
> used in a workflow. This step also includes the `--license` option for
133-
> `ncc`, which will create a license file for all of the production node
134-
> modules used in your project.
135-
136-
1. Commit your changes
92+
1. :white_check_mark: Run the tests
13793

13894
```bash
139-
git add .
140-
git commit -m "My first action is ready!"
141-
```
142-
143-
1. Push them to your repository
95+
$ npm test
14496

145-
```bash
146-
git push -u origin releases/v1
97+
PASS ./index.test.js
14798
```
14899

149-
1. Create a pull request and get feedback on your action
150-
1. Merge the pull request into the `main` branch
151-
152-
Your action is now published! :rocket:
153-
154-
For information about versioning your action, see
155-
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
156-
in the GitHub Actions toolkit.
157-
158-
## Validate the Action
159-
160-
You can now validate the action by referencing it in a workflow file. For
161-
example, [`ci.yml`](./.github/workflows/ci.yml) demonstrates how to reference an
162-
action in the same repository.
163-
164-
```yaml
165-
steps:
166-
- name: Checkout
167-
id: checkout
168-
uses: actions/checkout@v4
169-
170-
- name: Test Local Action
171-
id: test-action
172-
uses: ./
173-
with:
174-
milliseconds: 1000
175-
176-
- name: Print Output
177-
id: output
178-
run: echo "${{ steps.test-action.outputs.time }}"
179-
```
180-
181-
For example workflow runs, check out the
182-
[Actions tab](https://github.com/actions/typescript-action/actions)! :rocket:
183-
184-
## Usage
185-
186-
After testing, you can create version tag(s) that developers can use to
187-
reference different stable versions of your action. For more information, see
188-
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
189-
in the GitHub Actions toolkit.
190-
191-
To include the action in a workflow in another repository, you can use the
192-
`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit
193-
hash.
194-
195-
```yaml
196-
steps:
197-
- name: Checkout
198-
id: checkout
199-
uses: actions/checkout@v4
200-
201-
- name: Test Local Action
202-
id: test-action
203-
uses: actions/typescript-action@v1 # Commit with the `v1` tag
204-
with:
205-
milliseconds: 1000
206-
207-
- name: Print Output
208-
id: output
209-
run: echo "${{ steps.test-action.outputs.time }}"
210-
```
211-
212100
## Publishing a New Release
213101

214102
This project includes a helper script, [`script/release`](./script/release)

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ branding:
77
color: 'red'
88

99
inputs:
10+
github_token:
11+
description: 'GitHub token'
12+
required: true
13+
1014
regex_patterns:
1115
description: 'List of regex patterns to search for'
1216
required: true

0 commit comments

Comments
 (0)