-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve the lock copy.sh script
* separate the script into a template file so it's easier to shellcheck and syntax highlight in editors. * shellcheck the script and remove all SC2086 warnings ("Double quote to prevent globbing and word splitting") * improve the buildozer help messages in the copy.sh script: * reduce duplication of buildozer command * add a more clear autofix bazel run command that can be easily copy-pasted * change some of the variable names in the copy.sh template for longer, easier to understand names (repo_name >> name, lock_label >> label) * move repo_name and workspace_relative_path into variables to reduce line length and improve readability
- Loading branch information
Showing
3 changed files
with
63 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o pipefail -o errexit -o nounset | ||
|
||
lock=$(realpath "$1") | ||
autofix=${{2:-}} | ||
|
||
cd "$BUILD_WORKING_DIRECTORY" | ||
|
||
echo | ||
echo "Writing lockfile to {workspace_relative_path}" | ||
cp "$lock" "{workspace_relative_path}" | ||
|
||
# Detect which file we wish the user to edit | ||
if [ -e "$BUILD_WORKSPACE_DIRECTORY/WORKSPACE" ]; then | ||
wksp_file="WORKSPACE" | ||
elif [ -e "$BUILD_WORKSPACE_DIRECTORY/WORKSPACE.bazel" ]; then | ||
wksp_file="WORKSPACE.bazel" | ||
elif [ -e "$BUILD_WORKSPACE_DIRECTORY/MODULE.bazel" ]; then | ||
wksp_file="MODULE.bazel" | ||
else | ||
echo>&2 "Error: no MODULE.bazel or WORKSPACE file was found" | ||
exit 1 | ||
fi | ||
|
||
# Detect a vendored buildozer binary in canonical location (tools/buildozer) | ||
if [ -e "$BUILD_WORKSPACE_DIRECTORY/tools/buildozer" ]; then | ||
buildozer="tools/buildozer" | ||
else | ||
# Assume it's on the $PATH | ||
buildozer="buildozer" | ||
fi | ||
|
||
echo | ||
|
||
cmd="$buildozer 'set lock \"{lock_label}\"' $wksp_file:{repo_name}" | ||
|
||
if [[ "$autofix" == "--autofix" ]]; then | ||
eval "$cmd" | ||
else | ||
cat <<EOF | ||
Run the following command to add the 'lock' attribute | ||
to the "{repo_name}" repo in $wksp_file: | ||
$cmd | ||
or run the following command to do it automatically: | ||
bazel run @{repo_name}//:lock -- --autofix | ||
EOF | ||
fi |
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