Skip to content

Commit

Permalink
bazel: Add workspace status for RBE.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivucica committed May 3, 2024
1 parent 9321006 commit 01448d2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ bazel-genfiles
bazel-glict
bazel-out
bazel-testlogs

.bazelrc.buildbuddysecrets
9 changes: 9 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ build:remote --remote_cache=grpcs://remote.buildbuddy.io
build:remote --remote_timeout=3600
build:remote --remote_executor=grpcs://remote.buildbuddy.io

# build:remote --build_metadata=REPO_URL=https://github.com/ivucica/glict
# build:remote --build_metadata=VISIBILITY=PUBLIC # default for unauthenticated, could be put into buildbuddysecrets if authenticated
build:remote --workspace_status_command=$(pwd)/workspace_status.sh

# readonly:
#build:remote --noremote_upload_local_results # Uploads logs & artifacts without writing to cache
# toplevel:
Expand All @@ -37,6 +41,11 @@ build:remotecache --remote_cache=grpcs://remote.buildbuddy.io
build:remotecache --remote_timeout=3600
build:remotecache --remote_executor=grpcs://remote.buildbuddy.io

# build:remotecache --build_metadata=REPO_URL=https://github.com/ivucica/glict
# build:remotecache --build_metadata=VISIBILITY=PUBLIC # default for unauthenticated, could be put into buildbuddysecrets if authenticated
build:remotecache --workspace_status_command=$(pwd)/workspace_status.sh


# readonly:
#build:remotecache --noremote_upload_local_results # Uploads logs & artifacts without writing to cache
# toplevel:
Expand Down
9 changes: 9 additions & 0 deletions tools/latest_version_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e

# Prints the latest BuildBuddy version tag, like "v2.12.8"
git tag -l 'v*' --sort=creatordate |
perl -nle 'if (/^v\d+\.\d+\.\d+$/) { print $_ }' |
tail -n1

# https://raw.githubusercontent.com/buildbuddy-io/buildbuddy/0e1c95e47bb668edfbfe62f7eb6fc7795f1f4576/tools/latest_version_tag.sh
49 changes: 49 additions & 0 deletions workspace_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# This script will be run bazel when building process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with non-zero code, it's considered as a failure
# and the output will be discarded.

set -eo pipefail # exit immediately if any command fails.

function remove_url_credentials() {
which perl >/dev/null && perl -pe 's#//.*?:.*?@#//#' || cat
}

repo_url=$(git config --get remote.origin.url | remove_url_credentials)
echo "REPO_URL $repo_url"

commit_sha=$(git rev-parse HEAD)
echo "COMMIT_SHA $commit_sha"

git_branch=$(git rev-parse --abbrev-ref HEAD)
echo "GIT_BRANCH $git_branch"

git_tree_status=$(git diff-index --quiet HEAD -- && echo 'Clean' || echo 'Modified')
echo "GIT_TREE_STATUS $git_tree_status"

# Note: the "STABLE_" suffix causes these to be part of the "stable" workspace
# status, which may trigger rebuilds of certain targets if these values change
# and you're building with the "--stamp" flag.
latest_version_tag=$(./tools/latest_version_tag.sh)
echo "STABLE_VERSION_TAG $latest_version_tag"
echo "STABLE_COMMIT_SHA $commit_sha"

# https://raw.githubusercontent.com/buildbuddy-io/buildbuddy/0e1c95e47bb668edfbfe62f7eb6fc7795f1f4576/workspace_status.sh
# other additions:
echo 'TAGS rbe'
echo 'ALLOW_ENV RBE_ALLOWED_ENV_*'
echo "BUILDBUDDY_LINKS [GitHub]($repo_url)"

# some other items:
# PATTERN: override the build command pattern
# USER: override USER/GITHUB_ACTOR/GITLAB_USER_NAME/BUILDKITE_BUILD_CREATOR/CIRCLE_USERNAME
# ROLE: if set to CI, treat as a CI build
# TEST_GROUPS: group test prefixes together, e.g. //foo/bar,//foo/baz
# BRANCH_NAME: pulled from GITHUB_REF, GITHUB_HEAD_REF, GIT_BRANCH, CI_COMMIT_BRANCH etc

0 comments on commit 01448d2

Please sign in to comment.