This repository was archived by the owner on Jan 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Adding script to check git status of Radix DLT Java repos #6
Open
Sajjon
wants to merge
1
commit into
rc/1.0-beta.11
Choose a base branch
from
infra/bash_script_git_status_of_radix_repos
base: rc/1.0-beta.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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,94 @@ | ||
| #!/bin/bash | ||
|
|
||
| ERROR_MSG_NO_SUCH_FOLDER="___folder_does_not_exist___" | ||
|
|
||
| RADIXDLT_JAVA_CLIENT_LIBRARY_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY='radixdlt-java' | ||
| RADIXDLT_CORE_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY='radixdlt-core' | ||
| RADIXDLT_ENGINE_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY='radix-engine-library' | ||
| RADIXDLT_REGRESSION_TESTS_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY='RadixRegressionTests' | ||
|
|
||
| # Arguments: | ||
| # $1 = git_repo_absolute_path: String | ||
| # $2 = git_command: String | ||
| function git_command() { | ||
| local git_repo_absolute_path="$1" | ||
| local git_command="$2" | ||
| echo $(git --git-dir="$git_repo_absolute_path" $git_command) | ||
| } | ||
|
|
||
| # Arguments: | ||
| # $1 = git_repo_absolute_path: String | ||
| # $1 = git_rev_parse_argument: String | ||
| function git_rev_parse_head() { | ||
| local git_repo_absolute_path="$1" | ||
| local git_rev_parse_argument="$2" | ||
| echo $(git_command "$git_repo_absolute_path" "rev-parse $git_rev_parse_argument HEAD") | ||
| } | ||
|
|
||
| # Arguments: | ||
| # $1 = git_repo_absolute_path: String | ||
| function git_branch_name() { | ||
| local git_repo_absolute_path="$1" | ||
| echo $(git_rev_parse_head "$git_repo_absolute_path" --abbrev-ref) | ||
| } | ||
|
|
||
| # Arguments: | ||
| # $1 = git_repo_absolute_path: String | ||
| function git_last_commit_hash() { | ||
| local git_repo_absolute_path="$1" | ||
| echo $(git_rev_parse_head "$git_repo_absolute_path" --short) | ||
| } | ||
|
|
||
| # Arguments: | ||
| # $1 = git_repo_absolute_path: String | ||
| function git_summary_of_repo() { | ||
| local git_repo_absolute_path="$1" | ||
| if test -d "$git_repo_absolute_path"; then | ||
| local branch_name=$(git_branch_name "$git_repo_absolute_path") | ||
| local commit_hash=$(git_last_commit_hash "$git_repo_absolute_path") | ||
| echo "#: $commit_hash, ᛋ: '$branch_name'" | ||
| else | ||
| echo "$ERROR_MSG_NO_SUCH_FOLDER" | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| echo "⚠️ This script assumes that all your Radix Java repos are placed" | tr -d '\n' | ||
| echo " in a shared root folder two directories up from this script," | tr -d '\n' | ||
| echo " with folders matching name of repos." | ||
|
|
||
|
|
||
| # assumes this scripts is in `<PATH-WITH-ALL-RADIX-GIT-REPOS>radixdlt-java-common/<SCRIPTS-DIR>/this_script.sh | ||
| script_dir=$(dirname "$0") | ||
| RADIXDLT_JAVA_COMMON_PATH="$script_dir/../" | ||
|
|
||
| RADIXDLT_JAVA_REPOS_PATH="$RADIXDLT_JAVA_COMMON_PATH/../" | ||
|
|
||
| RADIXDLT_JAVA_CLIENT_LIBRARY_PATH="$RADIXDLT_JAVA_REPOS_PATH/$RADIXDLT_JAVA_CLIENT_LIBRARY_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY" | ||
| RADIXDLT_ENGINE_PATH="$RADIXDLT_JAVA_REPOS_PATH/$RADIXDLT_ENGINE_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY" | ||
| RADIXDLT_CORE_PATH="$RADIXDLT_JAVA_REPOS_PATH/$RADIXDLT_CORE_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY" | ||
| RADIXDLT_REGRESSION_TESTS_PATH="$RADIXDLT_JAVA_REPOS_PATH/$RADIXDLT_REGRESSION_TESTS_NAME_OF_REPO_AND_ASSUMED_NAME_OF_DIRECTORY" | ||
|
|
||
| radix_java_repos=( $RADIXDLT_JAVA_COMMON_PATH $RADIXDLT_JAVA_CLIENT_LIBRARY_PATH $RADIXDLT_ENGINE_PATH $RADIXDLT_CORE_PATH $RADIXDLT_REGRESSION_TESTS_PATH ) | ||
|
|
||
| git_report='' | ||
|
|
||
| for radix_java_repo_path in "${radix_java_repos[@]}" | ||
| do | ||
| git_repo_name=$(basename $radix_java_repo_path) | ||
| if [[ "$git_repo_name" == ".." ]]; then | ||
|
Contributor
Author
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. @clstrfsck do you have a solution for this? the dir |
||
| # ugly fix for when using `basename` on the parent directory of this script | ||
| # results in ".." as folder name. | ||
| git_repo_name="radixdlt-java-common" | ||
| fi | ||
| git_repo_name_padded=$(printf "%-.25s %s\n" "${git_repo_name} ") | ||
| git_info=$(git_summary_of_repo "$radix_java_repo_path/.git") | ||
| if [[ "$git_info" == "$ERROR_MSG_NO_SUCH_FOLDER" ]]; then | ||
| echo "$git_repo_name not found" | ||
| else | ||
| git_report="${git_report}$git_repo_name_padded $git_info\n" | ||
| fi | ||
| done | ||
|
|
||
|
|
||
| echo "\n🔮Git status of Radix DLT Java repos:\n$git_report\n" | ||
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.
Would be good if this script worked, even if it was not run with the current directory the same as the the script directory, eg
./scripts/radix_git_status.shYou could use
scriptdir=$(dirname "$0")to work out where the script directory was relative to the working directory it was run from.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.
nice! fixed! would be nice to get it working even when using symlinks, but
readlink -fdoes not work on macOS 🤷♂️