-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdeploy.yml
37 lines (34 loc) · 1.77 KB
/
deploy.yml
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
version: '3'
tasks:
git:
desc: "Pushes a directory to a git remote"
summary: |
Given a directory, pushes it to a git remote whilst maintaining a linear
history with the remote.
usage: task deploy:git directory="/tmp/release" branch=main remote="[email protected]:Lullabot/drainpipe.git" message="Initial commit" push=true"
directory=<directory> A directory containing the files to be pushed
branch=<branch> Name of the branch to push to e.g. "main"
remote=<remote> Git remote to push to
message=<message> Commit message
push=true (optional) Push to the remote repository
cmds:
- if [ ! -d {{ shellQuote (.directory | default "") }} ]; then echo "Please provide a path to a directory to deploy" && exit 1; fi
- if [ "" == {{ shellQuote (.branch | default "") }} ]; then echo "Please provide a branch to deploy to" && exit 1; fi
- if [ "" == {{ shellQuote (.remote | default "") }} ]; then echo "Please provide a remote git repository to push to" && exit 1; fi
- if [ "" == {{ shellQuote (.message | default "") }} ]; then echo "Please provide a commit message" && exit 1; fi
- |
TMP_DIR=$(mktemp -d)
(git clone --depth 1 --branch {{.branch}} {{.remote}} $TMP_DIR && cd $TMP_DIR) || true
if [[ ! -d "$TMP_DIR/.git" ]]; then
git clone --depth 1 {{.remote}} $TMP_DIR
cd $TMP_DIR
git checkout -b {{.branch}}
fi
mv $TMP_DIR/.git {{.directory}}
cd {{.directory}}
git checkout -B {{.branch}}
git add -A
git commit --quiet --message {{shellQuote .message}} --allow-empty
if [ {{shellQuote (.push | default "true") }} == "true" ]; then
git push origin {{.branch}}
fi