-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout
More file actions
executable file
·58 lines (38 loc) · 1.16 KB
/
checkout
File metadata and controls
executable file
·58 lines (38 loc) · 1.16 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
usageHelp() {
echo "Usage: $0 <repository> [target-branch]"
echo " repository: The GitHub repository in the format 'user/repo'."
echo " example: ./ci/checkout \${{ github.repository }}"
}
# Check if the repository argument is provided
if [ -z "$1" ]; then
usageHelp
exit 1
fi
echo "Usage help"
usageHelp
REPOSITORY=$1
CURRENT_BRANCH=$(git branch --show-current)
echo "[TAG-GENERATOR] initializing..."
echo " REPOSITORY=$REPOSITORY"
checkoutInfo() {
LAST_COMMIT_HASH=$(git rev-parse --short HEAD)
LAST_COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Last commit message from hash $CURRENT_BRANCH-$LAST_COMMIT_HASH:
$LAST_COMMIT_MSG
"
}
checkoutInfo
rm -rf .git
# Extract the project name from the REPOSITORY variable
PROJECT_NAME=$(echo "$REPOSITORY" | cut -d'/' -f2)
git clone "git@github.com:${REPOSITORY}.git"
# cd project with validation. If failed, exit.
cd "$PROJECT_NAME" || exit 1
git fetch --tags
git checkout tags/"$CURRENT_BRANCH-$LAST_COMMIT_HASH"
echo "After checkout"
checkoutInfo
echo "Current branch: in ($(pwd)) - $(git branch --show-current)"