-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add packcheck-remote to work with remote repositories directly #36
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,208 @@ | ||
#!/usr/bin/env bash | ||
|
||
PACKCHECK_DIR=$(dirname "$0") | ||
PACKCHECK_EXE="$PACKCHECK_DIR/packcheck.sh" | ||
PWD="$(pwd)" | ||
DEFAULT_DIRECTORY_NAME="packcheck-remote-work" | ||
DEFAULT_DIRECTORY="$PWD/$DEFAULT_DIRECTORY_NAME" | ||
|
||
# $1: msg | ||
show_step() { | ||
echo | ||
echo "--------------------------------------------------" | ||
echo "$1" | ||
echo "--------------------------------------------------" | ||
} | ||
|
||
which_cmd() { | ||
hash -r && type -P "$1" || true | ||
} | ||
|
||
# $1: executable (eg. git) | ||
require_cmd () { | ||
local cmd_path | ||
cmd_path=$(which_cmd "$1") | ||
if test -z "$cmd_path" | ||
then | ||
echo "Required command [$1] not found in PATH [$PATH]." | ||
exit 1 | ||
else | ||
echo "Using [$1] at [$cmd_path]" | ||
fi | ||
} | ||
|
||
# $1: command | ||
function run_verbose() { | ||
echo "$1" | ||
bash -c "$1" | ||
} | ||
|
||
# $1: Remote repository | ||
# $2: Revision to checkout | ||
# $3: Revision to merge into $2 | ||
# $4: Directory to clone into | ||
# $5: Force mode | ||
# $6: Packcheck cli options | ||
try_git_clone_and_merge() { | ||
|
||
# Check for prerequisites | ||
require_cmd git | ||
|
||
local remote="$1" | ||
local rev="$2" | ||
local merge="$3" | ||
local dir="$4" | ||
local force_mode="$5" | ||
local packcheck_cli_opts="$6" | ||
|
||
if test -z "$dir" | ||
then | ||
dir="$DEFAULT_DIRECTORY" | ||
echo "No directory specified to clone to." | ||
echo "Using $dir" | ||
fi | ||
|
||
if test -z "$remote" | ||
then | ||
echo "No remote repository provided." | ||
echo "Skipping cloning." | ||
return | ||
fi | ||
|
||
if test -z "$rev" | ||
then | ||
echo "No revision given." | ||
echo "Defaulting to 'origin/master'." | ||
rev="origin/master" | ||
fi | ||
|
||
if test -d "$dir" | ||
then | ||
echo "$dir already exists" | ||
|
||
if [ "$force_mode" == "true" ]; | ||
then | ||
echo "Forcing the deletion of the directory." | ||
echo "Removing $dir" | ||
rm -rf "$dir" || exit 1 | ||
else | ||
echo "Set the script to force mode to force the deletion." | ||
return | ||
fi | ||
fi | ||
|
||
mkdir -p "$dir" || exit 1 | ||
|
||
run_verbose "git clone $remote $dir" || exit 1 | ||
|
||
cd "$dir" || exit 1 | ||
run_verbose "git branch $rev" || exit 1 | ||
|
||
if test -n "$merge" | ||
then | ||
# This will fail if there are any merge conflicts | ||
run_verbose "git merge -X theirs $merge --no-edit --commit" || exit 1 | ||
fi | ||
|
||
show_step "Running packcheck" | ||
# Run packcheck here | ||
run_verbose "$PACKCHECK_EXE $packcheck_cli_opts" | ||
} | ||
|
||
# Arguments for the command line | ||
FORCE="false" | ||
REMOTE="" | ||
CHECKOUT="" | ||
MERGE="" | ||
DIRECTORY="" | ||
PACKCHECK_CLI_OPTS_ARR=() | ||
PACKCHECK_CLI_OPTS="" | ||
|
||
function run_help() { | ||
local script | ||
script=$(basename "$0") | ||
|
||
echo | ||
echo "USAGE: --option[=value]" | ||
echo | ||
echo "-f (or) --force: Puts the script in force mode. This is ideal for CIs." | ||
echo "-h (or) --help: Print help." | ||
echo "--remote: Repository to clone." | ||
echo "--checkout: Revision to checkout. Defaults to 'origin/master'." | ||
echo "--merge: Revision to merge in the checked out branch." | ||
echo "--directory: Directory to clone the repository into." | ||
echo " Defaults to '$DEFAULT_DIRECTORY_NAME' under the present working directory." | ||
echo | ||
echo "All the arguments after '--' are passed to packcheck" | ||
echo | ||
|
||
echo | ||
echo "EXAMPLE:" | ||
echo | ||
echo "$script --force \\" | ||
echo " --remote=https://github.com/user/repo \\" | ||
echo " --checkout=origin/master \\" | ||
echo " --merge=origin/branch \\" | ||
echo " --directory=./repo.packcheck \\" | ||
echo " -- cabal-v2 GHCVER=8.8.3" | ||
echo | ||
} | ||
|
||
# Program entry point | ||
for i in "$@" | ||
do | ||
case $i in | ||
-f|--force) | ||
FORCE="true" | ||
shift | ||
;; | ||
-h|--help) | ||
run_help | ||
exit 0 | ||
;; | ||
--remote=*) | ||
REMOTE="${i#*=}" | ||
shift | ||
;; | ||
--checkout=*) | ||
CHECKOUT="${i#*=}" | ||
shift | ||
;; | ||
--merge=*) | ||
MERGE="${i#*=}" | ||
shift | ||
;; | ||
--directory=*) | ||
DIRECTORY="${i#*=}" | ||
shift | ||
;; | ||
--) | ||
shift | ||
PACKCHECK_CLI_OPTS_ARR=("$@") | ||
break | ||
;; | ||
*) | ||
echo "Unknown argument to packcheck-remote" | ||
run_help | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
for i in "${PACKCHECK_CLI_OPTS_ARR[@]}" | ||
do | ||
case $i in | ||
*=*) | ||
key=${1%%=*} | ||
val=${1#*=} | ||
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $key=\"$val\"" | ||
shift | ||
;; | ||
*) | ||
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $i" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
try_git_clone_and_merge "$REMOTE" "$CHECKOUT" "$MERGE" "$DIRECTORY" "$FORCE" "$PACKCHECK_CLI_OPTS" | ||
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,9 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
PACKCHECK_DIR=$(dirname $0) | ||
PACKCHECK_DIR=$(dirname "$0") | ||
echo "Running ${PACKCHECK_DIR}/packcheck.sh with clean environment and CHECK_ENV on..." | ||
echo "No environment variables are honored, you have to specifiy ALL the" | ||
echo "parameters explicitly on the command line, including PATH." | ||
echo | ||
|
||
/usr/bin/env -i CHECK_ENV=y $(dirname $0)/packcheck.sh $* | ||
PACKCHECK_CLI_OPTS_ARR=("$@") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just quoting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not work. |
||
PACKCHECK_CLI_OPTS="" | ||
|
||
for i in "${PACKCHECK_CLI_OPTS_ARR[@]}" | ||
do | ||
case $i in | ||
*=*) | ||
key=${1%%=*} | ||
val=${1#*=} | ||
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $key=\"$val\"" | ||
shift | ||
;; | ||
*) | ||
PACKCHECK_CLI_OPTS="$PACKCHECK_CLI_OPTS $i" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
eval "/usr/bin/env -i CHECK_ENV=y $PACKCHECK_DIR/packcheck.sh $PACKCHECK_CLI_OPTS" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just pass
"$*"
instead of processing$@
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work.
a="b c d"
would becomea=b c d
.