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

Add check for tabs vs spaces to GitHub Actions for Pull Requests #2011

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/pull_request_qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,43 @@ jobs:
echo "No changes detected in the release notes."
exit 1
fi

check_tabs_vs_spaces:
runs-on: ubuntu-latest

steps:
- name: Checkout pull request branch
uses: actions/checkout@v4

- name: Add official Aspen Discovery repo as another remote
run: git remote add official https://github.com/Aspen-Discovery/aspen-discovery.git && git fetch official

- name: Get default branch
id: get_default_branch
run: |
default_branch=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/Aspen-Discovery/aspen-discovery | jq -r .default_branch)
echo "Default branch is $default_branch"
echo "DEFAULT_BRANCH=$default_branch" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check for spaces instead of tabs
run: |
# Find files that are modified in the pull request
MODIFIED_FILES=$(git diff --name-only official/$DEFAULT_BRANCH HEAD)

# Loop through each file and check for spaces used instead of tabs
EXIT_CODE=0
for file in $MODIFIED_FILES; do
echo "Found modified file: $file";
if [[ $file == *.php || $file == *.js || $file == *.java ]]; then
#echo "Checking $file for whitespace issues"
DIFF=$(git diff official/$DEFAULT_BRANCH HEAD -- $file)
#echo "DIFF: $DIFF"
if [[ $DIFF =~ " " ]]; then
echo "Detected spaces instead of tabs in $file"
EXIT_CODE=1
fi
fi
done
exit $EXIT_CODE
1 change: 1 addition & 0 deletions code/web/release_notes/24.09.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@

### GitHub Actions
- Add GitHub Actions to check pull requests for release notes (*KMH*)
- Add GitHub Actions to check pull requests for spaces vs tabs (*KMH*)
- Prevent GitHub Actions from attempting to push Docker images unless the push is to the official rep (*KMH*)

// Liz Rea
Expand Down