Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Warn for Empty Strings | |
on: | |
pull_request: | |
paths: | |
- "**/*.ts" | |
- "**/*.tsx" | |
permissions: | |
issues: write | |
pull-requests: write | |
jobs: | |
check-empty-strings: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Find empty strings in TypeScript files | |
id: find_empty_strings | |
run: | | |
# Find empty strings and mark them explicitly | |
output=$(grep -Rn --include=\*.ts "''\|\"\"" --exclude-dir={node_modules,dist,out} . || true) | |
if [ -z "$output" ]; then | |
echo "::set-output name=results::No empty strings found." | |
exit 0 | |
else | |
output=$(echo "$output" | sed 's/""/"[EMPTY STRING]"/g' | sed "s/''/'[EMPTY STRING]'/g") | |
echo "::set-output name=results::${output//$'\n'/%0A}" | |
fi | |
- name: findings | |
if: steps.find_empty_strings.outputs.results != 'No empty strings found.' | |
run: | | |
if [ "${{ steps.find_empty_strings.outputs.results }}" == "No empty strings found." ]; then | |
echo "No empty strings found. No action required." | |
else | |
echo "::warning::Empty strings found in the following files:" | |
echo "${{ steps.find_empty_strings.outputs.results }}" | |
fi | |
- name: Find Comment | |
uses: peter-evans/find-comment@v3 | |
id: find_comment | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body-includes: Empty String Usage Detected | |
comment-author: github-actions[bot] | |
- name: Comment on PR | |
if: steps.find_empty_strings.outputs.results != 'No empty strings found.' | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-id: ${{ steps.find_comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
## Empty String Usage Detected | |
The following occurrences of empty strings were detected. Please review them to ensure their usage is necessary: | |
```plaintext | |
${{ steps.find_empty_strings.outputs.results }} | |
``` |