Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Clean up shells and stop obscure API...
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Apr 20, 2020
1 parent f378294 commit e37755a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
40 changes: 20 additions & 20 deletions ci/dependabot-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ set -ex
cd "$(dirname "$0")/.."

if ! echo "$BUILDKITE_BRANCH" | grep -E '^pull/[0-9]+/head$'; then
echo "not pull request!?"
echo "not pull request!?" >&2
exit 1
fi

source ci/rust-version.sh stable

ci/docker-run.sh $rust_nightly_docker_image ci/dependabot-updater.sh

if [[ $(git status --short :**/Cargo.lock | wc -l) -gt 0 ]]; then
(
echo --- "(FAILING) Backpropagating dependabot-triggered Cargo.lock updates"

git add :**/Cargo.lock
NAME="dependabot-buildkite"
GIT_AUTHOR_NAME="$NAME" \
GIT_COMMITTER_NAME="$NAME" \
EMAIL="dependabot-buildkite@noreply.solana.com" \
git commit -m "[auto-commit] Update all Cargo lock files"
api_base="https://api.github.com/repos/solana-labs/solana/pulls"
pr_num=$(echo "$BUILDKITE_BRANCH" | grep -Eo '[0-9]+')
branch=$(curl -s "$api_base/$pr_num" | python -c 'import json,sys;print json.load(sys.stdin)["head"]["ref"]')
git push origin "HEAD:$branch"

echo "Source branch is updated; failing this build for the next"
exit 1
)
if [[ $(git status --short :**/Cargo.lock | wc -l) -eq 0 ]]; then
echo --- ok
exit 0
fi

echo --- ok
echo --- "(FAILING) Backpropagating dependabot-triggered Cargo.lock updates"

name="dependabot-buildkite"
api_base="https://api.github.com/repos/solana-labs/solana/pulls"
pr_num=$(echo "$BUILDKITE_BRANCH" | grep -Eo '[0-9]+')
branch=$(curl -s "$api_base/$pr_num" | python -c 'import json,sys;print json.load(sys.stdin)["head"]["ref"]')

git add :**/Cargo.lock
EMAIL="dependabot-buildkite@noreply.solana.com" \
GIT_AUTHOR_NAME="$name" \
GIT_COMMITTER_NAME="$name" \
git commit -m "[auto-commit] Update all Cargo lock files"
git push origin "HEAD:$branch"

echo "Source branch is updated; failing this build for the next"
exit 1
5 changes: 3 additions & 2 deletions ci/dependabot-updater.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ parsed_update_args="$(
package=$(echo "$parsed_update_args" | awk '{print $2}')
if [[ -n $parsed_update_args ]]; then
# shellcheck disable=SC2086
_TARGET_LOCK_FILES=$(git grep --files-with-matches "$package" :**/Cargo.lock) \
_ scripts/cargo-for-all-lock-files.sh update $parsed_update_args
_ scripts/cargo-for-all-lock-files.sh \
"$(git grep --files-with-matches "$package" :**/Cargo.lock)" -- \
update $parsed_update_args
fi

echo --- ok
30 changes: 25 additions & 5 deletions scripts/cargo-for-all-lock-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,37 @@

set -e

if [[ -n $_TARGET_LOCK_FILES ]]; then
files="$_TARGET_LOCK_FILES"
shifted_args=()
while [[ -n $1 ]]; do
if [[ $1 = -- ]]; then
escape_marker=found
shift
break
else
shifted_args+=("$1")
shift
fi
done

# When "--" appear at the first and shifted_args is empty, consume it here
# to unambiguously pass and use any other "--" for cargo
if [[ -n $escape_marker && ${#shifted_args[@]} -gt 0 ]]; then
files="${shifted_args[*]}"
for file in $files; do
if [[ $file = "${file%Cargo.lock}" ]]; then
echo "$0: unrecognizable as Cargo.lock path (prepend \"--\"?): $file" >&2
exit 1
fi
done
shifted_args=()
else
files="$(git ls-files :**/Cargo.lock)"
fi

for lock_file in $files
do
for lock_file in $files; do
(
set -x
cd "$(dirname "$lock_file")"
cargo "$@"
cargo "${shifted_args[@]}" "$@"
)
done

0 comments on commit e37755a

Please # to comment.