forked from nickmackenzie/dont-get-zohod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
name: Verify Naming Convention | ||
name: Validate File and Folder Names | ||
|
||
on: | ||
pull_request: | ||
push: | ||
paths: | ||
- "**/*" # Trigger the workflow on any file or folder change | ||
branches: | ||
- main | ||
|
||
jobs: | ||
verifyNaming: | ||
validate: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Verify names | ||
run: | | ||
# Get a list of all files and folders in the pages directory | ||
pages_items=$(git ls-files pages/**/* && git ls-tree -d --name-only -r HEAD pages) | ||
# Initialize an array to store incorrect items | ||
incorrect_items=() | ||
- name: Install Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "14" | ||
|
||
# Iterate through the files and folders and check their names | ||
for item in $pages_items; do | ||
# Check if the item is a file or a folder and does not start with an underscore | ||
if [[ (-f $item || -d $item) && $item != pages/**/_* ]]; then | ||
# Get the base name of the file or folder (without extension) | ||
base_name=$(basename "$item") | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
# Check if the base name is in camel case | ||
if ! [[ $base_name =~ ^[a-z]+([A-Z][a-z0-9]+)*$ ]]; then | ||
incorrect_items+=("$item") | ||
fi | ||
- name: Validate file and folder names | ||
run: | | ||
#!/bin/bash | ||
set -e | ||
for file in $(find ./pages -type f); do | ||
if [[ "$(basename "$file")" =~ [A-Z] ]]; then | ||
echo "File name $file is not in camelCase" | ||
exit 1 | ||
fi | ||
done | ||
for dir in $(find ./pages -type d); do | ||
if [[ "$(basename "$dir")" =~ [A-Z] ]]; then | ||
echo "Folder name $dir is not in camelCase" | ||
exit 1 | ||
fi | ||
done | ||
# Check if there are any incorrect items | ||
if [[ ${#incorrect_items[@]} -gt 0 ]]; then | ||
# Output the list of incorrect items | ||
echo "The following items have invalid names (camel case required):" | ||
for item in "${incorrect_items[@]}"; do | ||
echo "- $item" | ||
done | ||
exit 1 | ||
else | ||
echo "All items in the pages directory have valid names." | ||
fi |