-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·48 lines (34 loc) · 1.23 KB
/
entrypoint.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -euo pipefail
# mark workspace dir as 'safe'
git config --system --add safe.directory '/github/workspace'
# validate
[ -z "$1" ] && echo "ERROR: branch-name is a required input" && exit 1
BRANCH_NAME="$1"
# set up a git user
git config user.name "github-actions[bot]"
git config user.email "[email protected]"
# make sure we've got all branches from the remote
# fetched locally before we call `git show-branch`
# (actions/checkout does not fetch all branches)
git fetch
# check if the branch already exists
if git show-branch "remotes/origin/$BRANCH_NAME"; then
echo "INFO: branch $BRANCH_NAME already exists, exiting..."
exit 0
fi
# if it doesn't exist, create one
echo "INFO: branch $BRANCH_NAME does not exist, creating a new orphan branch..."
# store the currently checked out branch before we start
CURRENT_BRANCH=$(git branch --show-current)
[ -z "$CURRENT_BRANCH" ] && echo "ERROR: I don't know how to cleanup, exiting..." && exit 1
# create the orphan branch and push it
git checkout --orphan "$BRANCH_NAME"
git rm -rf .
rm -f '.gitignore'
echo "# $BRANCH_NAME" > README.md
git add README.md
git commit -m 'init'
git push origin "$BRANCH_NAME"
# cleanup
git checkout --force "$CURRENT_BRANCH"