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

chore: only run build in changed dirs #124

Merged
merged 1 commit into from
Jan 10, 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
2 changes: 1 addition & 1 deletion .github/workflows/update-generated-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
git checkout -b $BRANCH_NAME
git commit -m "chore: sync generated files"
git push origin $BRANCH_NAME
gh pr create --base main --head $BRANCH_NAME --title "chore: sync generated files" --body ""
gh pr create --base main --head $BRANCH_NAME --title "chore: sync generated files" --body "This PR was opened by a robot :robot: :tada:."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
26 changes: 25 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run build -ws
# 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))
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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 .
npx lint-staged
Loading