Skip to content

Commit

Permalink
fix: Shell escaping issue
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Gasch <15986659+embano1@users.noreply.github.com>
  • Loading branch information
embano1 committed Apr 23, 2023
1 parent e83c03c commit c25450f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/check-wip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check WIP in PR Title
uses: embano1/wip@v1
uses: embano1/wip@v2
env:
TITLE: ${{ github.event.pull_request.title }}
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ work-in-progress ("WIP") patterns using regular expressions in `BASH`.

## Simple with Defaults

Uses `^[[:space:]]*(WIP)+(:)*` regex pattern to match against the PR title.

```yaml
name: Check "WIP" in PR Title

Expand All @@ -19,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check WIP in PR Title
uses: embano1/wip@v1
uses: embano1/wip@v2
```

## Custom Options
Expand All @@ -36,22 +38,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check WIP in PR Title
uses: embano1/wip@v1
uses: embano1/wip@v2
with:
# this is also the default value
title: "${{ github.event.pull_request.title }}"

# only matches PRs where title is "WIP" only
# only matches PRs where title is exactly "WIP"
regex: "^WIP$"

```

## Configuration Options

| Input | Type | Required | Default | Description |
|---------|----------|----------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `title` | `string` | yes | `${{ github.event.pull_request.title }}` | The title to perform regular expression pattern matching against. Typically a field from the Github [`context`](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) is used. |
| `regex` | `string` | yes | `^[[:space:]]*(WIP)+(:)*` | The regular expression to perform. The default value matches the word `WIP` (optionally followed by `:`) and ignores any whitespace character(s) at the beginning of the text |
| Input | Type | Required | Default | Description |
|---------|----------|----------|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `title` | `string` | yes | `${{ github.event.pull_request.title }}` | The title to perform regular expression pattern matching against. Typically a field from the Github [`context`](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) is used. |
| `regex` | `string` | yes | `^[[:space:]]*(WIP)+(:)*` | The regular expression to perform. The default value matches the word `WIP` (optionally followed by `:`) and ignores any whitespace character(s) at the beginning of the text. |

⚠️ Currently regular expression pattern matching is **case-insensitive**, i.e.
`wip` would also match.
> **Note**
> Currently regular expression pattern matching is **case-insensitive**, i.e., `wip` would also match.
38 changes: 33 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,51 @@ inputs:
required: true
# starts with zero or more leading whitespace chars, WIP and zero or more colons
default: "^[[:space:]]*(WIP)+(:)*"
debug:
description: "Enable verbose logging"
required: false
default: "false"
runs:
using: "composite"
steps:
- shell: bash
env:
TITLE: ${{ inputs.title }}
REGEX: ${{ inputs.regex }}
DEBUG: ${{ inputs.debug }}
run: |
set -ex
set -e
if [[ ${DEBUG} == "true" ]]; then
echo "Enabling debug output"
set -x
fi
# TODO (@mgasch): make configurable
# case-insensitive
shopt -s nocasematch
if [[ '${{ inputs.title }}' =~ ${{ inputs.regex }} ]]; then
if [[ -z ${TITLE} ]]; then
echo "::error::title input must be set";
exit 1
fi
if [[ -z ${REGEX} ]]; then
echo "::error::regex input must be set";
exit 1
fi
if [[ ${TITLE} =~ ${REGEX} ]]; then
echo "::error::Title marked as work in progress"
exit 1
else
echo "::debug::Title not marked as work in progress"
echo "Title not marked as work in progress"
fi
# unset nocasematch option
shopt -u nocasematch
if [[ ${DEBUG} == "true" ]]; then
echo "Disabling debug output"
set +x
fi

0 comments on commit c25450f

Please sign in to comment.