-
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.
Implemented custom Prettier hook and updated GitHub Actions workflow.
**Added:** - Created a new custom pre-commit hook script `prettier.sh` to format JSON, YAML, and YML files using Prettier. **Changed:** - Updated GitHub Actions pre-commit workflow to use `mage runPreCommit` command instead of `pre-commit run --all-files`, enhancing the CI process. - Modified `.pre-commit-config.yaml` to use the custom Prettier hook script for formatting instead of the standard Prettier mirror repository hook. **Removed:** - Removed the Prettier mirror repository hook from `.pre-commit-config.yaml`, replacing it with the custom implementation for better control over formatting. These changes enhance code formatting consistency and improve the automation in CI/CD pipeline through custom scripting and workflow adjustments.
- Loading branch information
Showing
3 changed files
with
46 additions
and
8 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 |
---|---|---|
|
@@ -53,4 +53,4 @@ jobs: | |
run: mage installDeps | ||
|
||
- name: Run pre-commit | ||
run: pre-commit run --all-files | ||
run: mage runPreCommit |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
set -exo pipefail | ||
|
||
# Check if npm is installed | ||
if ! [ -x "$(command -v npm)" ]; then | ||
echo 'Error: npm is not installed.' >&2 | ||
exit 1 | ||
else | ||
# Check if Prettier is installed | ||
if ! [ -x "$(command -v prettier)" ]; then | ||
echo 'Error: Prettier is not installed.' >&2 | ||
echo 'Installing Prettier...' | ||
npm install -g prettier | ||
fi | ||
fi | ||
|
||
# Check if Prettier is installed | ||
if ! [ -x "$(command -v prettier)" ]; then | ||
echo 'Error: Prettier is not installed.' >&2 | ||
exit 1 | ||
fi | ||
|
||
# Run Prettier on staged .json, .yaml, and .yml files | ||
echo "Running Prettier on staged files..." | ||
|
||
# List all staged files, filter for the desired extensions, and run Prettier | ||
git diff --cached --name-only --diff-filter=d \ | ||
| grep -E '\.(json|ya?ml)$' \ | ||
| xargs -I {} prettier --write {} | ||
|
||
# Add the files back to staging area as Prettier may have modified them | ||
git diff --name-only --diff-filter=d \ | ||
| grep -E '\.(json|ya?ml)$' \ | ||
| xargs git add | ||
|
||
echo "Prettier formatting completed." | ||
|
||
exit 0 |
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