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'
|
||||
|
||||
jobs:
|
||||
build-n-test:
|
||||
continuous-delivery:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
@ -17,15 +17,15 @@ jobs:
|
|||
with:
|
||||
ruby-version: '2.6.x'
|
||||
|
||||
- name: install tooling
|
||||
run: |
|
||||
brew install yq
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install yq
|
||||
run: |
|
||||
brew install yq
|
||||
|
||||
- name: Bundle Caching
|
||||
id: bundle-cache
|
||||
uses: actions/cache@v1
|
||||
|
@ -49,58 +49,25 @@ jobs:
|
|||
run: |
|
||||
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
|
||||
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
|
||||
run: |
|
||||
bash tools/test.sh
|
||||
|
||||
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
|
||||
bash tools/test.sh "$SPEC_TEST"
|
||||
|
||||
- name: Deploy
|
||||
run: |
|
||||
|
|
|
@ -16,7 +16,6 @@ CONTAINER="${WORK_DIR}/.container"
|
|||
|
||||
DEST="${WORK_DIR}/_site"
|
||||
|
||||
|
||||
_help() {
|
||||
echo "Usage:"
|
||||
echo
|
||||
|
@ -28,16 +27,15 @@ _help() {
|
|||
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
|
||||
}
|
||||
|
||||
|
||||
_init() {
|
||||
cd "$WORK_DIR"
|
||||
|
||||
if [[ -d "$CONTAINER" ]]; then
|
||||
if [[ -d $CONTAINER ]]; then
|
||||
rm -rf "$CONTAINER"
|
||||
fi
|
||||
|
||||
if [[ -d "_site" ]]; then
|
||||
jekyll clean
|
||||
if [[ -d $DEST ]]; then
|
||||
bundle exec jekyll clean
|
||||
fi
|
||||
|
||||
local _temp="$(mktemp -d)"
|
||||
|
@ -46,7 +44,6 @@ _init() {
|
|||
mv "$_temp" "$CONTAINER"
|
||||
}
|
||||
|
||||
|
||||
_build() {
|
||||
cd "$CONTAINER"
|
||||
echo "$ cd $(pwd)"
|
||||
|
@ -60,7 +57,7 @@ _build() {
|
|||
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
|
||||
|
||||
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" commit -m "[Automation] Update site files." -q
|
||||
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
|
||||
|
@ -70,24 +67,20 @@ _build() {
|
|||
cd .. && rm -rf "$CONTAINER"
|
||||
}
|
||||
|
||||
|
||||
_check_unset() {
|
||||
if [[ -z ${1:+unset} ]]
|
||||
then
|
||||
if [[ -z ${1:+unset} ]]; then
|
||||
_help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
while [[ $# -gt 0 ]]; do
|
||||
opt="$1"
|
||||
case $opt in
|
||||
-b | --baseurl)
|
||||
local _baseurl="$2"
|
||||
if [[ -z "$_baseurl" ]]; then
|
||||
if [[ -z $_baseurl ]]; then
|
||||
_baseurl='""'
|
||||
fi
|
||||
CMD+=" -b $_baseurl"
|
||||
|
@ -97,8 +90,8 @@ main() {
|
|||
-d | --destination)
|
||||
_check_unset "$2"
|
||||
DEST="$(realpath "$2")"
|
||||
shift;
|
||||
shift;
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
_help
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# Requirement: https://github.com/gjtorikian/html-proofer
|
||||
#
|
||||
# Usage: bash /path/to/test.sh
|
||||
# Usage: bash /path/to/test.sh [indicated path]
|
||||
#
|
||||
# v2.0
|
||||
# https://github.com/cotes2020/jekyll-theme-chirpy
|
||||
|
@ -14,6 +14,10 @@
|
|||
DEST=_site
|
||||
URL_IGNORE=cdn.jsdelivr.net
|
||||
|
||||
if [[ -n $1 && -d $1 ]]; then
|
||||
DEST=$1
|
||||
fi
|
||||
|
||||
bundle exec htmlproofer $DEST \
|
||||
--disable-external \
|
||||
--check-html \
|
||||
|
|
Loading…
Reference in a new issue