Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 2b9ddff

Browse files
authored
ci: do not fetch tags on steps that do not require it (#61156)
* use deepend so that we do not fetch all history * only fetch tags on certain steps * add comment on why we do not use deepen * add links
1 parent ee5eb32 commit 2b9ddff

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

.buildkite/hooks/post-checkout

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@
33
# shellcheck disable=SC1090,SC1091
44
source "$HOME/.profile"
55

6-
# due to how the repostiory is cloned with --depth=100 (see aspect terraform docs), we need to fetch the tags manually
7-
# we don't want to fetch all the tags, so here:
8-
# 1. Get a list of tags from the remote
9-
# 2. Sort them
10-
# 3. Get the last $COUNT tags
11-
# 4. Parse them so that we only get the tag
12-
# 5. Then loop through every tag and fetch it
13-
COUNT=10
14-
echo "~~~ :git: Fetching last $COUNT tags"
15-
git ls-remote --tags origin | sort -t '/' -k 3 -V | tail -n $COUNT | awk -F'/' '{gsub(/\^\{\}$/, "", $3); print $3}' | uniq | while read -r tag; do
16-
git fetch -v origin tag "$tag"
6+
function fetch_tags() {
7+
# ref relevant terraform: https://github.com/sourcegraph/infra-aspect-dev/blob/main/aspect/workflows.tf#L71
8+
# ref docs about above terraform: https://pro.aspect.build/workflows/terraform/workflows#input_bk_runner_groups
9+
# due to how the repostiory is cloned with --depth=100 (see aspect terraform docs), we need to fetch the tags manually
10+
# we don't want to fetch all the tags, so here:
11+
# 1. Get a list of tags from the remote
12+
# 2. Sort them
13+
# 3. Get the last $COUNT tags
14+
# 4. Parse them so that we only get the tag
15+
# 5. Then loop through every tag and fetch it
16+
COUNT=10
17+
echo "~~~ :git: Fetching last $COUNT tags"
18+
git ls-remote --tags origin | sort -t '/' -k 3 -V | tail -n $COUNT | awk -F'/' '{gsub(/\^\{\}$/, "", $3); print $3}' | uniq | while read -r tag; do
19+
# we don't use deepen here since during testing it caused more history to be fetched than just the history for the tag which incured a ~40s cost over 5s with just fetch tag
20+
git fetch -v origin tag "$tag"
21+
done
22+
}
23+
24+
steps_with_tags=(":pipeline: Generate pipeline" ":bazel: Test" ":bazel: Integration/E2E (Test)")
25+
for step in "${steps_with_tags[@]}"; do
26+
if [[ "$BUILDKITE_LABEL" == "$step" ]]; then
27+
fetch_tags
28+
fi
1729
done
1830

1931
# Link command wrapper scripts so we can have more readable steps in the buildkite UI

0 commit comments

Comments
 (0)