Skip to content

Commit 6036638

Browse files
authored
Merge pull request #7 from DNXLabs/add-script-clone-repo
🚀 Add script clone-repo
2 parents 7c14baa + 0e2889c commit 6036638

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# clone-repositories
2+
3+
This script clones a list of GIT repositories.
4+
5+
## Use case:
6+
7+
Used extensively to clone private repositories locally using local or CICD pipeline credentials, eliminating the need to export or store GIT credentials.
8+
9+
_Examples:_
10+
11+
- Terraform modules stored in private repositories
12+
- Applications that uses private repositories as dependencies.
13+
14+
## Prerequisites
15+
16+
- Bash
17+
- GIT
18+
19+
20+
## How to run
21+
22+
- Export the required environment variables:
23+
- `ORG_NAME` = Organization name, this variable is used to compose the repository URL e.g.: `export ORG_NAME=DNXLabs`
24+
- `VCS_URL` = Version control system, this variable is used to compose the repository URL e.g.: `export VCS_URL=github.com`
25+
- From the command line run: `bash clone-repositories.sh "repo-1@1.0.1" repo-2@1.2.1" "repo-3@2.0.3"`
26+
27+
## Versioning
28+
29+
1.0.0
30+
31+
32+
## Author
33+
34+
* **Woltter Xavier** - *Initial work* - [wvxavier](https://github.com/wvxavier)
35+
36+
## License
37+
38+
Apache 2 Licensed. See [LICENSE](https://github.com/DNXLabs/tools-box/blob/master/LICENSE) for full details.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#/bin/bash
2+
3+
#Checking if necessary environment variables are set
4+
if [[ -z "${ORG_NAME}" ]] ; then
5+
echo "ORG_NAME environment variable is not set, this variable is used to compose the repository URL"
6+
exit
7+
fi
8+
9+
if [[ -z "${VCS_URL}" ]] ; then
10+
echo "VCS_URL environment variable is not set, this variable is used to compose the repository URL"
11+
exit
12+
fi
13+
14+
#List of private repositories and tags from arguments
15+
declare -a repos=("$@")
16+
17+
# Disabe GIT advice
18+
git config --global advice.detachedHead false
19+
20+
for PACKAGE in "${repos[@]}"; do
21+
repoName="$(cut -d'@' -f1 <<< $PACKAGE)"
22+
repoVersion="$(cut -d'@' -f2 <<< $PACKAGE)"
23+
if [ -d "./local-repositories/$repoName" ]
24+
then
25+
echo "Repository $repoName already exists locally."
26+
else
27+
echo "Cloning git@$VCS_URL:$ORG_NAME/$repoName.git..."
28+
git clone -b $repoVersion git@$VCS_URL:$ORG_NAME/$repoName.git ./local-repositories/$repoName
29+
fi
30+
done
31+
32+

0 commit comments

Comments
 (0)