Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/actions/scripts/common_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@

set -euo pipefail

# shellcheck disable=SC2034
start_time=$SECONDS
trap 'echo "::notice title=common_setup.sh::total elapsed: $((SECONDS - start_time))s"' EXIT

# Checkout relevant git branches and tags
# Note that we need to checkout main and the current branch also because the todo checker uses
# `git log main..$BRANCH` so both main and the branch have to be local refs

current_commit=$(git rev-parse HEAD)

git config --global --add safe.directory "$(pwd)"
echo "FETCHING ORIGIN"
echo "FETCHING ORIGIN MAIN"
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF:-}"
refspecs=('refs/heads/main:refs/remotes/origin/main')
if [ -n "${GITHUB_HEAD_REF:-}" ] && [ "$GITHUB_HEAD_REF" != "main" ]; then
refspecs+=("refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/${GITHUB_HEAD_REF}")
fi
for attempt in {1..3}; do
if git fetch --tags --force origin; then
# On PRs from forks, GITHUB_HEAD_REF is the name of the branch in the forked repo, so we cannot actually fetch that branch directly.
if git fetch --no-tags --force origin "${refspecs[@]}" || git fetch --no-tags --force origin 'refs/heads/main:refs/remotes/origin/main'; then
break
else
echo "Fetch attempt $attempt failed. Retrying..."
Expand All @@ -27,18 +37,18 @@ for attempt in {1..3}; do
done
echo "CHECKING OUT MAIN"
git checkout main
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF:-}"
if [ -n "${GITHUB_HEAD_REF:-}" ] && [ "$GITHUB_HEAD_REF" != "main" ]; then
echo "Checking out $GITHUB_HEAD_REF"
# On PRs from forks, GITHUB_HEAD_REF is the name of the branch in the forked repo, so we cannot actually checkout that branch directly.
git checkout "$GITHUB_HEAD_REF" || true
fi
echo "FETCHING RELEASE LINES"
echo "FETCHING LATEST RELEASE LINE"
latest_release=$(cat LATEST_RELEASE)
for attempt in {1..3}; do
if git fetch origin 'refs/heads/release-line*:refs/heads/origin/release-line*' --force; then
if git fetch origin "refs/heads/release-line-${latest_release}:refs/heads/origin/release-line-${latest_release}" --force; then
break
else
echo "Fetch attempt $attempt for release lines failed. Retrying..."
echo "Fetch attempt $attempt for release line ${latest_release} failed. Retrying..."
if [ "$attempt" -eq 3 ]; then
echo "This was the last attempt. Exiting."
exit 1
Expand Down
Loading