Improve the CD workflow and enhance the related tools.
This commit is contained in:
parent
643c8177be
commit
d0d1e02763
3 changed files with 39 additions and 75 deletions
71
.github/workflows/pages-deploy.yml.hook
vendored
71
.github/workflows/pages-deploy.yml.hook
vendored
|
@ -9,7 +9,7 @@ on:
|
||||||
- 'LICENSE'
|
- 'LICENSE'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-n-test:
|
continuous-delivery:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -17,15 +17,15 @@ jobs:
|
||||||
with:
|
with:
|
||||||
ruby-version: '2.6.x'
|
ruby-version: '2.6.x'
|
||||||
|
|
||||||
- name: install tooling
|
|
||||||
run: |
|
|
||||||
brew install yq
|
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install yq
|
||||||
|
run: |
|
||||||
|
brew install yq
|
||||||
|
|
||||||
- name: Bundle Caching
|
- name: Bundle Caching
|
||||||
id: bundle-cache
|
id: bundle-cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
|
@ -49,58 +49,25 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
bundle install --local
|
bundle install --local
|
||||||
|
|
||||||
|
- name: Check baseurl
|
||||||
|
run: |
|
||||||
|
baseurl="$(grep '^baseurl:' _config.yml | yq r - baseurl)"
|
||||||
|
if [[ -n $baseurl ]]; then
|
||||||
|
echo "::set-env name=SPEC_TEST::_site_no_baseurl"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Build Site
|
- name: Build Site
|
||||||
run: |
|
run: |
|
||||||
bash tools/build.sh -b ""
|
bash tools/build.sh
|
||||||
|
|
||||||
|
if [[ -n $SPEC_TEST ]]; then
|
||||||
|
# Bypass the defects of htmlproofer
|
||||||
|
bash tools/build.sh -b "" -d "$SPEC_TEST"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Test Site
|
- name: Test Site
|
||||||
run: |
|
run: |
|
||||||
bash tools/test.sh
|
bash tools/test.sh "$SPEC_TEST"
|
||||||
|
|
||||||
deploy:
|
|
||||||
needs: build-n-test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-ruby@v1
|
|
||||||
with:
|
|
||||||
ruby-version: '2.6.x'
|
|
||||||
|
|
||||||
- name: install tooling
|
|
||||||
run: |
|
|
||||||
brew install yq
|
|
||||||
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Bundle Caching
|
|
||||||
id: bundle-cache
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: vendor/bundle
|
|
||||||
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-gems-
|
|
||||||
|
|
||||||
- name: Bundle config
|
|
||||||
run: |
|
|
||||||
bundle config path vendor/bundle
|
|
||||||
|
|
||||||
- name: Bundle Install
|
|
||||||
if: steps.bundle-cache.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
|
||||||
bundle install
|
|
||||||
|
|
||||||
- name: Bundle Install locally
|
|
||||||
if: steps.bundle-cache.outputs.cache-hit == 'true'
|
|
||||||
run: |
|
|
||||||
bundle install --local
|
|
||||||
|
|
||||||
- name: Build site
|
|
||||||
run: |
|
|
||||||
bash tools/build.sh
|
|
||||||
|
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -16,28 +16,26 @@ CONTAINER="${WORK_DIR}/.container"
|
||||||
|
|
||||||
DEST="${WORK_DIR}/_site"
|
DEST="${WORK_DIR}/_site"
|
||||||
|
|
||||||
|
|
||||||
_help() {
|
_help() {
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo
|
echo
|
||||||
echo " bash build.sh [options]"
|
echo " bash build.sh [options]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
|
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
|
||||||
echo " -h, --help Print the help information"
|
echo " -h, --help Print the help information"
|
||||||
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
|
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
cd "$WORK_DIR"
|
cd "$WORK_DIR"
|
||||||
|
|
||||||
if [[ -d "$CONTAINER" ]]; then
|
if [[ -d $CONTAINER ]]; then
|
||||||
rm -rf "$CONTAINER"
|
rm -rf "$CONTAINER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -d "_site" ]]; then
|
if [[ -d $DEST ]]; then
|
||||||
jekyll clean
|
bundle exec jekyll clean
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local _temp="$(mktemp -d)"
|
local _temp="$(mktemp -d)"
|
||||||
|
@ -46,7 +44,6 @@ _init() {
|
||||||
mv "$_temp" "$CONTAINER"
|
mv "$_temp" "$CONTAINER"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_build() {
|
_build() {
|
||||||
cd "$CONTAINER"
|
cd "$CONTAINER"
|
||||||
echo "$ cd $(pwd)"
|
echo "$ cd $(pwd)"
|
||||||
|
@ -60,7 +57,7 @@ _build() {
|
||||||
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
|
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
|
||||||
|
|
||||||
if [[ -d "${DEST}/.git" ]]; then
|
if [[ -d "${DEST}/.git" ]]; then
|
||||||
if [[ ! -z $(git -C "$DEST" status -s) ]]; then
|
if [[ -n $(git -C "$DEST" status -s) ]]; then
|
||||||
git -C "$DEST" add .
|
git -C "$DEST" add .
|
||||||
git -C "$DEST" commit -m "[Automation] Update site files." -q
|
git -C "$DEST" commit -m "[Automation] Update site files." -q
|
||||||
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
|
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
|
||||||
|
@ -70,37 +67,33 @@ _build() {
|
||||||
cd .. && rm -rf "$CONTAINER"
|
cd .. && rm -rf "$CONTAINER"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_check_unset() {
|
_check_unset() {
|
||||||
if [[ -z ${1:+unset} ]]
|
if [[ -z ${1:+unset} ]]; then
|
||||||
then
|
|
||||||
_help
|
_help
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while [[ $# -gt 0 ]]
|
while [[ $# -gt 0 ]]; do
|
||||||
do
|
|
||||||
opt="$1"
|
opt="$1"
|
||||||
case $opt in
|
case $opt in
|
||||||
-b|--baseurl)
|
-b | --baseurl)
|
||||||
local _baseurl="$2"
|
local _baseurl="$2"
|
||||||
if [[ -z "$_baseurl" ]]; then
|
if [[ -z $_baseurl ]]; then
|
||||||
_baseurl='""'
|
_baseurl='""'
|
||||||
fi
|
fi
|
||||||
CMD+=" -b $_baseurl"
|
CMD+=" -b $_baseurl"
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-d|--destination)
|
-d | --destination)
|
||||||
_check_unset "$2"
|
_check_unset "$2"
|
||||||
DEST="$(realpath "$2")"
|
DEST="$(realpath "$2")"
|
||||||
shift;
|
shift
|
||||||
shift;
|
shift
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
-h | --help)
|
||||||
_help
|
_help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# Requirement: https://github.com/gjtorikian/html-proofer
|
# Requirement: https://github.com/gjtorikian/html-proofer
|
||||||
#
|
#
|
||||||
# Usage: bash /path/to/test.sh
|
# Usage: bash /path/to/test.sh [indicated path]
|
||||||
#
|
#
|
||||||
# v2.0
|
# v2.0
|
||||||
# https://github.com/cotes2020/jekyll-theme-chirpy
|
# https://github.com/cotes2020/jekyll-theme-chirpy
|
||||||
|
@ -14,6 +14,10 @@
|
||||||
DEST=_site
|
DEST=_site
|
||||||
URL_IGNORE=cdn.jsdelivr.net
|
URL_IGNORE=cdn.jsdelivr.net
|
||||||
|
|
||||||
|
if [[ -n $1 && -d $1 ]]; then
|
||||||
|
DEST=$1
|
||||||
|
fi
|
||||||
|
|
||||||
bundle exec htmlproofer $DEST \
|
bundle exec htmlproofer $DEST \
|
||||||
--disable-external \
|
--disable-external \
|
||||||
--check-html \
|
--check-html \
|
||||||
|
|
Loading…
Reference in a new issue