Skip to content
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

group1 empty on perfect regex match #158

Closed
Tchekda opened this issue Apr 27, 2021 · 3 comments
Closed

group1 empty on perfect regex match #158

Tchekda opened this issue Apr 27, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@Tchekda
Copy link

Tchekda commented Apr 27, 2021

What happened

When running this action :

      - name: Extract version number
        id: version
        uses: actions-ecosystem/action-regex-match@v2
        with:
          text: ${{ github.event.head_commit.message }}
          regex: '.*(v\d+\.\d+\.\d+).*'
      - name: Create Release
        if: ${{ steps.version.outputs.match != '' }}
        uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          prerelease: false
          automatic_release_tag: ${{ steps.version.outputs.group1 }}
          title: Version ${{ steps.version.outputs.group1 }}

With the commit message v0.0.8, the second step is triggered so steps.version.outputs.match isn't empty but steps.version.outputs.group1 is empty that creates an error on the following step. But when the commit message is v0.0.8 - 2nd try it's working fine and the steps.version.outputs.group1 contains correctly the version number.

Regex101 proof

What you expected to happen

I expected the regex to match the whole message as expected and put it in steps.version.outputs.group1

How to reproduce it

Use these steps on an action triggered by push and create a commit matching perfectly the regex

Environment

These action are set with runs-on: ubuntu-latest

@Tchekda Tchekda added the bug Something isn't working label Apr 27, 2021
@kaisugi
Copy link
Contributor

kaisugi commented May 11, 2021

Actually, you cannot use \d+ because this workflow exploits JavaScript's constructor Regex internally.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#literal_notation_and_constructor

> const re1 = new RegExp("\d+", "");   # constructor
undefined
> re1.exec("34");
null
> const re2 = new RegExp(/\d+/, "");   # literal notation
undefined
> re2.exec("34");
[ '34', index: 0, input: '34', groups: undefined ]

@kaisugi
Copy link
Contributor

kaisugi commented May 11, 2021

In your case, .*(v.+?\..+?\..+?).* would work perfectly fine

> const re = new RegExp(".*(v.+?\..+?\..+?).*", "");
undefined
> re.exec("v0.0.8")
[ 'v0.0.8', 'v0.0.8', index: 0, input: 'v0.0.8', groups: undefined ]
> re.exec("v0.0.8 - 2nd try")
[
  'v0.0.8 - 2nd try',
  'v0.0.8',
  index: 0,
  input: 'v0.0.8 - 2nd try',
  groups: undefined
]

@Tchekda
Copy link
Author

Tchekda commented Jun 8, 2021

Understood. I was more looking for something that would match only numbers but that is good too.

Thank you for your answer, sorry for bothering...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants