Skip to content

Commit

Permalink
Add the possibility to clone to a specific branch (#62)
Browse files Browse the repository at this point in the history
* Add value to clone to branch

* Fix

* Fix test step

* Add debug

* Update command to clone

* Add a wrong test to validate it actually works

* Restore the good tests
  • Loading branch information
marboledacci authored Nov 26, 2024
1 parent f460e43 commit 1291e52
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ jobs:
- run:
command: |-
[ -f ./test2/README.md ]
- run: mkdir test3
- github-cli/clone:
repo: https://github.com/CircleCI-Public/Orb-Project-Template.git
branch: gmemstr-patch-1
dir: ./test3
- run: |
cd test3
[ "$(git rev-parse --abbrev-ref HEAD)" = "gmemstr-patch-1" ]
workflows:
test-deploy:
jobs:
Expand Down
5 changes: 5 additions & 0 deletions src/commands/clone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ parameters:
type: string
default: "."
description: Select the path to clone into. By default the current path will be selected, which is dictated by the job's "working_directory".
branch:
type: string
default: ""
description: Branch to checkout. Value defaults to empty, which will clone the default branch.
when:
type: string
default: "on_success"
Expand All @@ -26,5 +30,6 @@ steps:
PARAM_GH_REPO: <<parameters.repo>>
PARAM_GH_DIR: <<parameters.dir>>
PARAM_GH_HOSTNAME: <<parameters.hostname>>
PARAM_BRANCH: <<parameters.branch>>
command: <<include(scripts/clone.sh)>>
when: <<parameters.when>>
2 changes: 1 addition & 1 deletion src/examples/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
gh: circleci/github-cli@2.0
gh: circleci/github-cli@2.6
node: circleci/[email protected]
workflows:
test-and-deploy:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
gh: circleci/github-cli@2.0
gh: circleci/github-cli@2.6
jobs:
create-a-deployment:
docker:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/pr-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
gh: circleci/github-cli@2.2.0
gh: circleci/github-cli@2.6.0
workflows:
build_and_test:
jobs:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
gh: circleci/github-cli@2.0
gh: circleci/github-cli@2.6
jobs:
create-a-pr:
docker:
Expand Down
8 changes: 7 additions & 1 deletion src/scripts/clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ mkdir -p ~/.ssh
ssh-keyscan -t rsa "$PARAM_GH_HOSTNAME" >> ~/.ssh/known_hosts

PARAM_GITHUB_REPO_EXPANDED="$(eval echo "$PARAM_GH_REPO")"
gh repo clone "$PARAM_GITHUB_REPO_EXPANDED" "$PARAM_GH_DIR"

if [ -n "$PARAM_BRANCH" ]; then
gh repo clone "$PARAM_GITHUB_REPO_EXPANDED" "$PARAM_GH_DIR" -- "--branch=$PARAM_BRANCH"
else
gh repo clone "$PARAM_GITHUB_REPO_EXPANDED" "$PARAM_GH_DIR"
fi

0 comments on commit 1291e52

Please sign in to comment.