-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6d2b9ea
commit 27c57ef
Showing
2 changed files
with
3 additions
and
70 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
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 |
---|---|---|
|
@@ -6,43 +6,6 @@ rel_path=$1 | |
abs_path=$DIR/$rel_path | ||
action=$2 | ||
owner="${3:-github actions}" | ||
check_mode="${CHECK_MODE:-}" | ||
run_mode="${RUN_MODE:-}" | ||
|
||
while getopts "p:a:o:crh" opt; do | ||
case $opt in | ||
p) abs_path="$DIR/$OPTARG" ;; | ||
a) action="$OPTARG" ;; | ||
o) owner="$OPTARG" ;; | ||
c) check_mode=true ;; | ||
r) run_mode=true ;; | ||
h) | ||
cat <<EOF | ||
Usage: | ||
$0 <path> <action> <owner> | ||
$0 [options] | ||
The options -p, -a, -o are required if using the second form | ||
Options: | ||
-p <path> path to the file to check | ||
-a <action> action to run | ||
-o <owner> owner to commit as | ||
-c check mode | ||
-r run mode | ||
EOF | ||
exit 0 | ||
;; | ||
*) echo "Invalid option: -$OPTARG" >&2 ;; | ||
esac | ||
done | ||
|
||
for opt in "$abs_path" "$action" "$owner"; do | ||
if [[ -z "$opt" ]] || [[ "$opt" = -* ]]; then | ||
echo "A required argument is missing" >&2 | ||
exit 1 | ||
fi | ||
done | ||
|
||
commit_as_github_actions() { | ||
git config user.name 'github-actions[bot]' | ||
|
@@ -54,22 +17,10 @@ commit_as_dirty_bot() { | |
git config user.email '[email protected]' | ||
} | ||
|
||
if [[ "$run_mode" == true ]]; then | ||
# Split action into array safely: | ||
IFS=' ' read -r -a action_array <<<"$action" | ||
if ! yarn "${action_array[@]}"; then | ||
echo "Error: Failed to execute yarn command: ${action_array[*]}" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ "$check_mode" == true ]] && ! git diff --quiet; then | ||
echo "found unstaged files from $action, aborting" | ||
exit 1 | ||
fi | ||
if [[ $(git diff --stat "$abs_path") != '' ]]; then | ||
echo "changes found in $rel_path that will be commited" | ||
git diff "$abs_path" || true | ||
git diff "$abs_path" | ||
git add "$abs_path" | ||
if [ "$owner" == "github actions" ]; then | ||
commit_as_github_actions | ||
elif [ "$owner" == "dirtybot" ]; then | ||
|
@@ -78,7 +29,7 @@ if [[ $(git diff --stat "$abs_path") != '' ]]; then | |
echo "Error: Unknown owner!" | ||
exit 1 | ||
fi | ||
git commit -am "chore: $action update dirty files" | ||
git commit -m "chore: $action update dirty files" | ||
git push | ||
else | ||
echo "found no unstaged files from $action, nothing to commit" | ||
|