-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·138 lines (109 loc) · 2.97 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
set -e
set -o pipefail
if [[ -n "$TOKEN" ]]; then
GITHUB_TOKEN=$TOKEN
fi
if [[ -z "$PAGES_BRANCH" ]]; then
PAGES_BRANCH="build"
fi
if [[ -z "$BUILD_DIR" ]]; then
BUILD_DIR="."
fi
if [[ -n "$REPOSITORY" ]]; then
TARGET_REPOSITORY=$REPOSITORY
else
if [[ -z "$GITHUB_REPOSITORY" ]]; then
echo "Set the GITHUB_REPOSITORY env variable."
exit 1
fi
TARGET_REPOSITORY=${GITHUB_REPOSITORY}
fi
if [[ -z "$BUILD_ONLY" ]]; then
BUILD_ONLY=false
fi
if [[ -z "$BUILD_THEMES" ]]; then
BUILD_THEMES=false
fi
if [[ -z "$OUTPUT_DIR" ]]; then
OUTPUT_DIR="out"
fi
if [[ -z "$GITHUB_TOKEN" ]] && [[ "$BUILD_ONLY" == false ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
if [[ -z "$GITHUB_HOSTNAME" ]]; then
GITHUB_HOSTNAME="github.com"
fi
minifyhtml() {
COMMAND="htmlmin"
find "$(pwd)" -iname "*.html" | sort -u | while read -r i; do
$COMMAND -o "$i.new" "$i"
rm "$i"
mv "$i.new" "$i"
done
}
minifyjs() {
COMMAND="uglifyjs"
find "$(pwd)" -iname "*.js" | sort -u | while read -r i; do
$COMMAND -o "$i.new" "$i"
rm "$i"
mv "$i.new" "$i"
done
}
minifypng() {
COMMAND="pngcrush"
find "$(pwd)" -iname "*.png" | sort -u | while read -r i; do
$COMMAND -ow "$i"
done
}
minifyjpeg() {
COMMAND="jpegoptim"
find "$(pwd)" -iname "*.jpg" -o -iname "*.jpeg" | sort -u | while read -r i; do
$COMMAND "$i"
done
}
minifyimages() {
minifypng
minifyjpeg
}
main() {
echo "Starting deploy..."
git config --global url."https://".insteadOf git://
## $GITHUB_SERVER_URL is set as a default environment variable in all workflows, default is https://github.com
git config --global url."$GITHUB_SERVER_URL/".insteadOf "git@${GITHUB_HOSTNAME}":
version=$(yarn --version)
remote_repo="https://${GITHUB_TOKEN}@${GITHUB_HOSTNAME}/${TARGET_REPOSITORY}.git"
remote_branch=$PAGES_BRANCH
echo "Using yarn $version"
echo "Building in $BUILD_DIR directory"
cd $BUILD_DIR
echo "Install yarn dependencies"
yarn install --frozen-lockfile --silent
echo "Building and Exporting next project"
yarn build
current_dir="$PWD"
public_dir="$current_dir/$OUTPUT_DIR"
cd "$public_dir"
echo "Minifying HTML and JS Files"
minifyhtml
minifyjs
echo "Minifying Images"
minifyimages
cd "$current_dir"
if ${BUILD_ONLY}; then
echo "Build complete. Deployment skipped by request"
exit 0
else
echo "Pushing artifacts to ${TARGET_REPOSITORY}:$remote_branch"
cd $OUTPUT_DIR
git init
git config user.name "GitHub Actions"
git config user.email "[email protected].${GITHUB_HOSTNAME}"
git add .
git commit -m "Deploy ${TARGET_REPOSITORY} to ${TARGET_REPOSITORY}:$remote_branch"
git push --force "${remote_repo}" master:${remote_branch}
echo "Deploy complete"
fi
}
main "$@"