Skip to content

KyoriPowered/action-regex-match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Action Regex Match

actions-workflow-test release license

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.

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 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 The whole matched text. If the inputs.regex doesn't match inputs.text, this value 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

name: Add Label with Comment

on: [issue_comment]

jobs:
  create_comment:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: KyoriPowered/action-regex-match@v3
        id: regex-match
        with:
          text: ${{ github.event.comment.body }}
          regex: '^/label\s*(.*?)\s*$'

      - uses: actions-ecosystem/action-add-labels@v1
        if: ${{ steps.regex-match.outputs.match != '' }}
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          labels: ${{ steps.regex-match.outputs.group1 }}
name: Create Comment with Regex Match

on: [issue_comment]

jobs:
  create_comment:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: KyoriPowered/action-regex-match@v3
        id: regex-match
        with:
          text: ${{ github.event.comment.body }}
          regex: '```typescript([\s\S]*)```'
          flags: gm

      - uses: actions-ecosystem/action-create-comment@v1
        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 }}

            ---

Contributing

As this is a Javascript action, it is subject to the quirks enforced on GitHub. Development should be done on Node 20 or later. Any text editor works, but we tend to use VS Code.

To set up a development environment:

  1. Clone this repository
  2. Install Node v16 or later
  3. (if the yarn command is not available), run corepack enable
  4. Fetch dependencies by running yarn install
  5. Open the project in VS Code: code . (or your choice of editor). The source to edit is in src/

After making changes, run yarn build to compile the TS source, producing the final dist/index.js file that Actions actually reads. Yes, for some reason GitHub makes us commit this file to the repository. A CI check will ensure that this step has been done when pull requests are published.

Making a release

Simply create a release based on a tag with the format vMAJOR.MINOR.PATCH (all 3 elements are required). An Actions workflow will automatically run to update the alias tags of vMAJOR and vMAJOR.MINOR.

License

Copyright 2022 KyoriPowered https://kyori.net Copyright 2020 The Actions Ecosystem Authors.

Action Regex Match is released under the Apache License 2.0.