-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile
executable file
·110 lines (89 loc) · 3.1 KB
/
Taskfile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# =========================================================
# Taskfile gives you a set of quick tasks for your project
# More info: https://enri.se/taskfile
# =========================================================
# =========================================================
## Project
# =========================================================
function task:init { ## Initialise the project for local development
task:build
project:update
task:help
}
function task:update { ## Update all dependencies and files
project:update
}
function project:update {
title "Installing dependencies"
docker:run composer install
}
# =========================================================
## Local development
# =========================================================
function task:build { ## (re)build the project container
title "Building local container"
docker build --target local --tag upload-to-dropbox:local .
title "Building production container"
docker build --target production --tag upload-to-dropbox:production .
}
function task:run { ## Run the CLI
title "Running the production container"
docker run -ti --rm --volume $PWD/src:/opt/dropbox-uploader --user `id -u`:`id -g` --name upload-to-dropbox upload-to-dropbox:production "$@"
}
function task:shell { ## Open the local development shell
title "Running the development shell"
docker:run /bin/sh
}
# =========================================================
# Docker
# =========================================================
function docker:run {
docker run -ti --rm --volume $PWD/src:/opt/dropbox-uploader --user `id -u`:`id -g` upload-to-dropbox:local "$@"
}
# =========================================================
# Automation
# =========================================================
function task:pre-commit {
title "Linting staged files"
lint-staged
title "Committing"
}
# =========================================================
## Taskfile
# =========================================================
PATH=./node_modules/.bin:$PATH
BLUE=$(printf '\033[36m')
YELLOW=$(printf '\033[33m')
RESET=$(printf '\033[0m')
function title {
echo -e "\n${BLUE}=>${RESET} $1\n"
}
function banner {
echo " "
echo "Docker Upload To Dropbox"
}
function task:help { ## Show all available tasks
title "Available tasks"
awk 'BEGIN {FS = " { [#][#][ ]?"} /^([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ \
{printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\
sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\
sed -E "s/function task:*/ /g"
echo -e "\n${BLUE}Usage:${RESET} $0 ${YELLOW}<task>${RESET} <args>"
}
function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile
title "Creating task shorthand"
if [ -f /usr/local/bin/task ]
then
echo "/usr/local/bin/task already exists."
else
echo -e "You are about to create /usr/local/bin/task that requires root permission..."
sudo curl --location --silent --output /usr/local/bin/task https://enri.se/taskfile-bin
sudo chmod +x /usr/local/bin/task
fi
echo -e "${BLUE}You can now use:${RESET} task ${YELLOW}<task>${RESET} <args>"
}
# Execute tasks (defaults to help)
set -eo pipefail
banner
"task:${@:-help}"