Skip to content
Open
Show file tree
Hide file tree
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
48 changes: 48 additions & 0 deletions orb/src/commands/checkout-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
description: >
Checkout the current CircleCI SHA over HTTPS with retries.
parameters:
checkout-method:
type: enum
enum:
- blobless
- full
default: full
steps:
- run:
name: Checkout code
command: |
set -euo pipefail

repo="${CIRCLE_REPOSITORY_URL:-https://github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git}"
case "$repo" in
git@github.com:*) repo="https://github.com/${repo#git@github.com:}" ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SSH-to-HTTPS rewrite changes the auth behavior compared to circleci's built-in checkout. For private repos where CIRCLE_REPOSITORY_URL is SSH, this can turn an authenticated checkout into an anonymous HTTPS fetch. Since circleci's built-in checkout is a special step with integration-specific credential handling, a custom git fetch may not be a drop-in replacement for private repos, especially GitHub App HTTPS pipelines.

circlci checkout docs: https://circleci.com/docs/reference/configuration-reference/#checkout

ssh://git@github.com/*) repo="https://github.com/${repo#ssh://git@github.com/}" ;;
esac

fetch_filter=""
if [ "<< parameters.checkout-method >>" = "blobless" ]; then
fetch_filter="--filter=blob:none"
fi

git init .
git remote add origin "$repo"

fetched=false
for attempt in 1 2 3; do
if git fetch --no-tags $fetch_filter origin "$CIRCLE_SHA1"; then
fetched=true
break
fi

delay=$((attempt * 5))
echo "git fetch failed on attempt ${attempt}; retrying in ${delay}s..."
sleep "$delay"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight improvement: could avoid the sleep here if all 3 attempts failed

done

if [ "$fetched" != "true" ]; then
echo "git fetch failed after 3 attempts."
exit 1
fi

git checkout --detach "$CIRCLE_SHA1"
test "$(git rev-parse HEAD)" = "$CIRCLE_SHA1"
4 changes: 2 additions & 2 deletions orb/src/commands/checkout-with-mise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ parameters:
type: string
default: '{{ checksum "mise.toml" }}'
steps:
- checkout:
method: << parameters.checkout-method >>
- checkout-code:
checkout-method: << parameters.checkout-method >>
- install-mise:
enable_mise_cache: << parameters.enable-mise-cache >>
mise_cache_key_prefix: << parameters.mise-cache-key-prefix >>
Expand Down
2 changes: 1 addition & 1 deletion orb/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
FILE_PATH=$(dirname $0)
cd $FILE_PATH/src

circleci orb validate @orb.yml
circleci orb validate @orb.yml