forked from sounddrill31/actions_generate_local_manifests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.sh
executable file
·32 lines (25 loc) · 1.06 KB
/
add.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#
# Copyright (C) 2024 Souhrud Reddy
#
# SPDX-License-Identifier: Apache-2.0
#
#!/bin/bash
LINE=$1
# Extract the repository URL, local path, and branch from the line
read -r _ REPO_URL LOCAL_PATH BRANCH <<< $(echo "$LINE" | tr '"' ' ')
# Extract the repository name and owner from the URL
REPO_NAME=$(basename "$REPO_URL" .git)
REPO_OWNER=$(basename "$(dirname "$REPO_URL")")
# Extract the domain name from the URL
DOMAIN_NAME=$(echo "$REPO_URL" | sed -E 's/https?:\/\/([^\/]+).*/\1/')
# Add remote to the REMOTES array if not already present
if [[ ! " ${!REMOTES[@]} " =~ " ${REPO_OWNER} " ]]; then
REMOTES[$REPO_OWNER]=" <remote name=\"$REPO_OWNER\" fetch=\"https://$DOMAIN_NAME/$REPO_OWNER\" clone-depth=\"1\" />"
fi
# Add project to the PROJECTS array
PROJECT_KEY="${LOCAL_PATH}|${REPO_NAME}"
if [ -z "$BRANCH" ]; then
PROJECTS[$PROJECT_KEY]=" <project path=\"$LOCAL_PATH\" name=\"$REPO_NAME\" remote=\"$REPO_OWNER\" />"
else
PROJECTS[$PROJECT_KEY]=" <project path=\"$LOCAL_PATH\" name=\"$REPO_NAME\" remote=\"$REPO_OWNER\" revision=\"$BRANCH\" />"
fi