Skip to content

Commit 02ab576

Browse files
committed
Improve the CD workflow and enhance the related tools.
1 parent df36e23 commit 02ab576

File tree

3 files changed

+38
-74
lines changed

3 files changed

+38
-74
lines changed

.github/workflows/pages-deploy.yml.hook

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ on:
99
- 'LICENSE'
1010

1111
jobs:
12-
build-n-test:
12+
continuous-delivery:
1313
runs-on: ubuntu-latest
1414

1515
steps:
1616
- uses: actions/setup-ruby@v1
1717
with:
1818
ruby-version: '2.6.x'
1919

20-
- name: install tooling
21-
run: |
22-
brew install yq
23-
2420
- name: Checkout
2521
uses: actions/checkout@v2
2622
with:
2723
fetch-depth: 0
2824

25+
- name: Install yq
26+
run: |
27+
brew install yq
28+
2929
- name: Bundle Caching
3030
id: bundle-cache
3131
uses: actions/cache@v1
@@ -49,58 +49,25 @@ jobs:
4949
run: |
5050
bundle install --local
5151

52-
- name: Build Site
52+
- name: Check baseurl
5353
run: |
54-
bash tools/build.sh -b ""
55-
56-
- name: Test Site
57-
run: |
58-
bash tools/test.sh
59-
60-
deploy:
61-
needs: build-n-test
62-
runs-on: ubuntu-latest
63-
64-
steps:
65-
- uses: actions/setup-ruby@v1
66-
with:
67-
ruby-version: '2.6.x'
68-
69-
- name: install tooling
70-
run: |
71-
brew install yq
72-
73-
- name: Checkout
74-
uses: actions/checkout@v2
75-
with:
76-
fetch-depth: 0
54+
baseurl="$(grep '^baseurl:' _config.yml | yq r - baseurl)"
55+
if [[ -n $baseurl ]]; then
56+
echo "::set-env name=SPEC_TEST::_site_no_baseurl"
57+
fi
7758

78-
- name: Bundle Caching
79-
id: bundle-cache
80-
uses: actions/cache@v1
81-
with:
82-
path: vendor/bundle
83-
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile') }}
84-
restore-keys: |
85-
${{ runner.os }}-gems-
86-
87-
- name: Bundle config
88-
run: |
89-
bundle config path vendor/bundle
90-
91-
- name: Bundle Install
92-
if: steps.bundle-cache.outputs.cache-hit != 'true'
59+
- name: Build Site
9360
run: |
94-
bundle install
61+
bash tools/build.sh
9562

96-
- name: Bundle Install locally
97-
if: steps.bundle-cache.outputs.cache-hit == 'true'
98-
run: |
99-
bundle install --local
63+
if [[ -n $SPEC_TEST ]]; then
64+
# Bypass the defects of htmlproofer
65+
bash tools/build.sh -b "" -d "$SPEC_TEST"
66+
fi
10067

101-
- name: Build site
68+
- name: Test Site
10269
run: |
103-
bash tools/build.sh
70+
bash tools/test.sh "$SPEC_TEST"
10471

10572
- name: Deploy
10673
run: |

tools/build.sh

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,26 @@ CONTAINER="${WORK_DIR}/.container"
1616

1717
DEST="${WORK_DIR}/_site"
1818

19-
2019
_help() {
2120
echo "Usage:"
2221
echo
2322
echo " bash build.sh [options]"
2423
echo
2524
echo "Options:"
26-
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
27-
echo " -h, --help Print the help information"
28-
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
25+
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
26+
echo " -h, --help Print the help information"
27+
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
2928
}
3029

31-
3230
_init() {
3331
cd "$WORK_DIR"
3432

35-
if [[ -d "$CONTAINER" ]]; then
33+
if [[ -d $CONTAINER ]]; then
3634
rm -rf "$CONTAINER"
3735
fi
3836

39-
if [[ -d "_site" ]]; then
40-
jekyll clean
37+
if [[ -d $DEST ]]; then
38+
bundle exec jekyll clean
4139
fi
4240

4341
local _temp="$(mktemp -d)"
@@ -46,7 +44,6 @@ _init() {
4644
mv "$_temp" "$CONTAINER"
4745
}
4846

49-
5047
_build() {
5148
cd "$CONTAINER"
5249
echo "$ cd $(pwd)"
@@ -60,7 +57,7 @@ _build() {
6057
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
6158

6259
if [[ -d "${DEST}/.git" ]]; then
63-
if [[ ! -z $(git -C "$DEST" status -s) ]]; then
60+
if [[ -n $(git -C "$DEST" status -s) ]]; then
6461
git -C "$DEST" add .
6562
git -C "$DEST" commit -m "[Automation] Update site files." -q
6663
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
@@ -70,37 +67,33 @@ _build() {
7067
cd .. && rm -rf "$CONTAINER"
7168
}
7269

73-
7470
_check_unset() {
75-
if [[ -z ${1:+unset} ]]
76-
then
71+
if [[ -z ${1:+unset} ]]; then
7772
_help
7873
exit 1
7974
fi
8075
}
8176

82-
8377
main() {
84-
while [[ $# -gt 0 ]]
85-
do
78+
while [[ $# -gt 0 ]]; do
8679
opt="$1"
8780
case $opt in
88-
-b|--baseurl)
81+
-b | --baseurl)
8982
local _baseurl="$2"
90-
if [[ -z "$_baseurl" ]]; then
83+
if [[ -z $_baseurl ]]; then
9184
_baseurl='""'
9285
fi
9386
CMD+=" -b $_baseurl"
9487
shift
9588
shift
9689
;;
97-
-d|--destination)
90+
-d | --destination)
9891
_check_unset "$2"
9992
DEST="$(realpath "$2")"
100-
shift;
101-
shift;
93+
shift
94+
shift
10295
;;
103-
-h|--help)
96+
-h | --help)
10497
_help
10598
exit 0
10699
;;

tools/test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Requirement: https://github.com/gjtorikian/html-proofer
66
#
7-
# Usage: bash /path/to/test.sh
7+
# Usage: bash /path/to/test.sh [indicated path]
88
#
99
# v2.0
1010
# https://github.com/cotes2020/jekyll-theme-chirpy
@@ -14,6 +14,10 @@
1414
DEST=_site
1515
URL_IGNORE=cdn.jsdelivr.net
1616

17+
if [[ -n $1 && -d $1 ]]; then
18+
DEST=$1
19+
fi
20+
1721
bundle exec htmlproofer $DEST \
1822
--disable-external \
1923
--check-html \

0 commit comments

Comments
 (0)