summaryrefslogtreecommitdiffhomepage
path: root/tools/go_branch.sh
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2021-02-01 16:59:01 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-01 17:00:58 -0800
commit5d8054e75a9ce2a4ee3feeb0a6d284967ff3ba46 (patch)
tree644340ed66abffae1298540668d0cb5037e78bdf /tools/go_branch.sh
parent5230c8e13c5db572615403b4f0bc576c2ec08087 (diff)
Remove Go cache on failure.
It's unclear why permissions wind up corrupted, but these can be cleared on any failure, similar to the bazel cache itself: https://buildkite.com/gvisor/pipeline/builds/2304#_ PiperOrigin-RevId: 355057421
Diffstat (limited to 'tools/go_branch.sh')
-rwxr-xr-xtools/go_branch.sh20
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/go_branch.sh b/tools/go_branch.sh
index 026733d3c..e89a8b098 100755
--- a/tools/go_branch.sh
+++ b/tools/go_branch.sh
@@ -16,14 +16,25 @@
set -xeou pipefail
+# Remember our current directory.
+declare orig_dir
+orig_dir=$(pwd)
+readonly orig_dir
+
+# Record the current working commit.
+declare head
+head=$(git describe --always)
+readonly head
+
# Create a temporary working directory, and ensure that this directory and all
# subdirectories are cleaned up upon exit.
declare tmp_dir
tmp_dir=$(mktemp -d)
readonly tmp_dir
finish() {
- cd / # Leave tmp_dir.
- rm -rf "${tmp_dir}"
+ cd "${orig_dir}" # Leave tmp_dir.
+ rm -rf "${tmp_dir}" # Remove all contents.
+ git checkout -f "${head}" # Restore commit.
}
trap finish EXIT
@@ -70,11 +81,6 @@ declare -r go_merged="${tmp_dir}/merged"
rsync --recursive "${go_amd64}/" "${go_merged}"
rsync --recursive "${go_arm64}/" "${go_merged}"
-# Record the current working commit.
-declare head
-head=$(git describe --always)
-readonly head
-
# We expect to have an existing go branch that we will use as the basis for this
# commit. That branch may be empty, but it must exist. We search for this branch
# using the local branch, the "origin" branch, and other remotes, in order.