-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix husky precommit hook not running code in bash (#125)
* new approach * push main
- Loading branch information
Showing
2 changed files
with
31 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# only run the npm build script for each workspace directory that has changed files | ||
function run_build { | ||
# convert multiline string into array | ||
# @see https://stackoverflow.com/questions/24628076/convert-multiline-string-to-array | ||
local IFS=$'\n' | ||
local lines=($1) | ||
local i | ||
|
||
# get only the unique values from an array | ||
# `lines[$i]%%/*` gets the substring up to the first '/'. so `semantic-pr-footer-v1/src/run.ts` becomes `semantic-pr-footer-v1` | ||
# @see https://www.baeldung.com/linux/bash-unique-values-arrays | ||
unique_dirs=($(for (( i=0; i<${#lines[@]}; i++ )) ; do echo "${lines[$i]%%/*}"; done | sort -u)) | ||
|
||
for dir in "${unique_dirs[@]}"; do | ||
npm run build -w "$dir" | ||
done | ||
} | ||
|
||
cd "$(dirname -- "$0")/../.github/actions" | ||
files=$(git diff HEAD~1 --name-only --relative) | ||
if [ "$files" != "" ]; then | ||
run_build "$files" | ||
fi | ||
|
||
git add . |
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,30 +1,8 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
# only run the npm build script for each workspace directory that has changed files | ||
function run_build { | ||
# convert multiline string into array | ||
# @see https://stackoverflow.com/questions/24628076/convert-multiline-string-to-array | ||
local IFS=$'\n' | ||
local lines=($1) | ||
local i | ||
|
||
# get only the unique values from an array | ||
# `lines[$i]%%/*` gets the substring up to the first '/'. so `semantic-pr-footer-v1/src/run.ts` becomes `semantic-pr-footer-v1` | ||
# @see https://www.baeldung.com/linux/bash-unique-values-arrays | ||
unique_dirs=($(for (( i=0; i<${#lines[@]}; i++ )) ; do echo "${lines[$i]%%/*}"; done | sort -u)) | ||
|
||
for dir in "${unique_dirs[@]}"; do | ||
npm run build -w "$dir" | ||
done | ||
} | ||
|
||
cd ./.github/actions | ||
files=$(git diff HEAD~1 --name-only --relative) | ||
if [ "$files" != "" ]; then | ||
run_build "$files" | ||
fi | ||
|
||
cd ../../ | ||
git add . | ||
# this file requires bash to run in github actions (github | ||
# actions use dash as default `sh` command) | ||
# @see https://github.com/typicode/husky/issues/1326 | ||
bash "$(dirname -- "$0")/build-changed-files.sh" | ||
npx lint-staged |