Skip to content

Commit

Permalink
Add a workflow test and improve errors (#13)
Browse files Browse the repository at this point in the history
* Add a workflow test and improve errors

* Semicolon
  • Loading branch information
maor-rozenfeld authored Mar 25, 2024
1 parent 2ad6bb5 commit b855661
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Tests
on:
push:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: ./tests.sh || { echo "::error title=Tests failed::tests.sh returned an error." && exit 1; }
6 changes: 2 additions & 4 deletions lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
# Match regex title with the title
if grep -qP -- "$TITLE_REGEX" <<< "$TITLE"; then
echo "Title matches regex: $TITLE_REGEX"
echo "verdict=Pass" >> $GITHUB_OUTPUT
else
echo "Error: Title does not match regex: $TITLE_REGEX" >&2
echo "$ERROR_MESSAGE" >&2
echo "verdict=$(echo $ERROR_MESSAGE)" >> $GITHUB_OUTPUT
echo "Title does not match regex: $TITLE_REGEX" >&2
echo "::error title=PR Title is invalid::$ERROR_MESSAGE"
exit 1
fi
15 changes: 7 additions & 8 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

set -e

if TITLE="Add something" \
TITLE_REGEX="^Add" \
if TITLE="Starts with Starts" \
TITLE_REGEX="^Starts" \
ERROR_MESSAGE="N/A" \
./lint.sh; then echo "Pass"; else echo "Failed" && exit 1; fi

if ! TITLE="Add something" \
if ! TITLE="Capitalized title" \
TITLE_REGEX="^[a-z]" \
ERROR_MESSAGE="Must be lower case" \
ERROR_MESSAGE="Title must not be capitalized" \
./lint.sh; then echo "Pass"; else echo "Failed" && exit 1; fi

if TITLE="Fix a thing" \
TITLE_REGEX="^(?!\\S+ing\\s)(?!\\S+ed\\s)" \
ERROR_MESSAGE="Must be lower case" \
ERROR_MESSAGE="Must use imperative mood" \
./lint.sh; then echo "Pass"; else echo "Failed" && exit 1; fi

if TITLE="Fix a thing" \
if ! TITLE="Fixing a thing" \
TITLE_REGEX="^(?!\\S+ing\\s)(?!\\S+ed\\s)" \
ERROR_MESSAGE="Must be lower case" \
ERROR_MESSAGE="Must use imperative mood" \
./lint.sh; then echo "Pass"; else echo "Failed" && exit 1; fi


echo All tests passed

0 comments on commit b855661

Please sign in to comment.