Skip to content

Commit

Permalink
Migrate to TypeScript and support capturing groups (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
micnncim authored May 4, 2020
1 parent 925a515 commit 9f58cd9
Show file tree
Hide file tree
Showing 18 changed files with 5,424 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
57 changes: 57 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {
"accessibility": "no-public"
}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-object-literal-type-assertion": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "off"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
17 changes: 0 additions & 17 deletions .github/workflows/lint.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: "12.x"
- run: yarn install
- run: yarn test
- run: yarn format-check
- run: yarn lint
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
lib/
__tests__/runner/*
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "avoid",
"parser": "typescript"
}
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

51 changes: 35 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Action Regex Match

[![actions-workflow-lint][actions-workflow-lint-badge]][actions-workflow-lint]
[![actions-workflow-test][actions-workflow-test-badge]][actions-workflow-test]
[![release][release-badge]][release]
[![license][license-badge]][license]

This is a GitHub Action to do regex matching and report whether the input text match the regex as an output.
This is a GitHub Action to do regex matching and output the matched text and groups captured by the given regex.

GitHub Actions natively supports some helpful functions, like `contains` and `startsWith`, but doesn't regex matching.
This actions provides the missing, useful function.
Expand All @@ -13,16 +13,26 @@ It would be more useful to use this with other GitHub Actions' outputs.

## Inputs

| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
| ------- | ---------------------------------------- | -------- | -------- | ------- |
| `text` | A text as the target for `inputs.regex`. | `string` | `true` | `N/A` |
| `regex` | An extended regex for `inputs.text`. | `string` | `true` | `N/A` |
| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
| ------- | ----------------------------------------------------- | -------- | -------- | ------- |
| `text` | A text as the target for `inputs.regex`. | `string` | `true` | `N/A` |
| `regex` | A regex for `inputs.text`. Supports capturing groups. | `string` | `true` | `N/A` |
| `flags` | Flags for inputs.regex. e.g.) `'g'`, `'gm'` | `string` | `false` | `''` |

## Outputs

| NAME | DESCRIPTION | TYPE |
| ------- | ------------------------------------------------------------------------------------ | ------ |
| `match` | Whether `inputs.regex` matches `inputs.text`. The value is either 'true' or 'false'. | `bool` |
| NAME | DESCRIPTION | TYPE |
|----------|---------------------------------------------------------------------------------------------|----------|
| `match` | The whole matched text. If the input.regex doesn't match input.text, outputs.matched is ''. | `string` |
| `group1` | The 1st captured group. | `string` |
| `group2` | The 2nd captured group. | `string` |
| `group3` | The 3rd captured group. | `string` |
| `group4` | The 4th captured group. | `string` |
| `group5` | The 5th captured group. | `string` |
| `group6` | The 6th captured group. | `string` |
| `group7` | The 7th captured group. | `string` |
| `group8` | The 8th captured group. | `string` |
| `group9` | The 9th captured group. | `string` |

## Example

Expand All @@ -36,17 +46,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-ecosystem/action-regex-match@v1
- uses: ./.github/actions/action-regex-match-ts
id: regex-match
with:
text: ${{ github.event.comment.body }}
regex: '^/[Hh]ello'
- uses: actions-ecosystem/action-regex-match@v1
if: ${{ steps.regex-match.outputs.match == 'true' }}
text: ${{ github.event.comment.body }}
regex: '```typescript([\s\S]*)```'
flags: gm
- uses: ./.github/actions/action-create-comment
if: ${{ steps.regex-match.outputs.match != '' }}
with:
github_token: ${{ secrets.github_token }}
body: |
Hello, @${{ github.actor }}!
The raw TypeScript code is here.
---
${{ steps.regex-match.outputs.group1 }}
---
```
## License
Expand All @@ -57,8 +76,8 @@ Action Regex Match is released under the [Apache License 2.0](./LICENSE).
<!-- badge links -->
[actions-workflow-lint]: https://github.com/actions-ecosystem/action-regex-match/actions?query=workflow%3ALint
[actions-workflow-lint-badge]: https://img.shields.io/github/workflow/status/actions-ecosystem/action-regex-match/Lint?label=Lint&style=for-the-badge&logo=github
[actions-workflow-test]: https://github.com/actions-ecosystem/action-regex-match/actions?query=workflow%3ATest
[actions-workflow-test-badge]: https://img.shields.io/github/workflow/status/actions-ecosystem/action-regex-match/Test?label=Test&style=for-the-badge&logo=github
[release]: https://github.com/actions-ecosystem/action-regex-match/releases
[release-badge]: https://img.shields.io/github/v/release/actions-ecosystem/action-regex-match?style=for-the-badge&logo=github
Expand Down
3 changes: 3 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('TODO - Add a test suite', () => {
it('TODO - Add a test', async () => {});
});
29 changes: 25 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,35 @@ inputs:
description: A text as the target for inputs.regex.
required: true
regex:
description: An extended regex for inputs.text.
description: A regex for inputs.text. Supports capturing groups.
required: true
flags:
description: Flags for inputs.regex. e.g.) 'g', 'gm'
required: false
outputs:
match:
description: Whether inputs.regex matches inputs.text. The value is either 'true' or 'false'.
description: The whole matched text. If the input.regex doesn't match input.text, outputs.matched is ''.
group1:
description: The 1st captured group.
group2:
description: The 2nd captured group.
group3:
description: The 3rd captured group.
group4:
description: The 4th captured group.
group5:
description: The 5th captured group.
group6:
description: The 6th captured group.
group7:
description: The 7th captured group.
group8:
description: The 8th captured group.
group9:
description: The 9th captured group.
runs:
using: docker
image: Dockerfile
using: node12
main: dist/index.js
branding:
icon: search
color: yellow
Loading

0 comments on commit 9f58cd9

Please sign in to comment.