Skip to content

Homework 02.Git

Homework 02.Git #7

name: Tests. PR validation
on:
pull_request:
paths:
- '**'
jobs:
check-whitespace:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for Whitespace
id: whitespace-check
run: |
git diff --name-only origin/master...HEAD
whitespace_files=$(git diff --name-only origin/master...HEAD | grep ' ' || true)
if [ -n "$whitespace_files" ]; then
echo "has_whitespace=true" >> $GITHUB_ENV
echo "files=$whitespace_files" >> $GITHUB_ENV
else
echo "has_whitespace=false" >> $GITHUB_ENV
fi
- name: Post Comment if Whitespace Found
if: env.has_whitespace == 'true'
uses: actions/github-script@v6
with:
script: |
const files = process.env.files.split('\n').map(file => `- ${file}`).join('\n');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `⚠️ **Whitespace detected in file or folder names:**\n\n${files}`
});
core.setFailed("Whitespace detected in file or folder names");