chore(ci,tools): adapt to changes in JS builds

This commit is contained in:
Cotes Chung 2023-03-14 01:25:42 +08:00
parent b69d3d7edd
commit 60229ae334
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
3 changed files with 83 additions and 50 deletions

View file

@ -1,18 +1,18 @@
name: 'CI' name: "CI"
on: on:
push: push:
branches-ignore: branches-ignore:
- 'production' - "production"
- 'docs' - "docs"
paths-ignore: paths-ignore:
- '.github/**' - ".github/**"
- '!.github/workflows/ci.yml' - "!.github/workflows/ci.yml"
- '.gitignore' - ".gitignore"
- 'README.md' - "README.md"
- 'LICENSE' - "LICENSE"
pull_request: pull_request:
paths: paths:
- '**' - "**"
jobs: jobs:
build: build:
@ -26,7 +26,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0 # for posts's lastmod fetch-depth: 0 # for posts's lastmod
- name: Setup Ruby - name: Setup Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
@ -34,5 +34,11 @@ jobs:
ruby-version: ${{ matrix.ruby }} ruby-version: ${{ matrix.ruby }}
bundler-cache: true bundler-cache: true
- name: Setup Node
uses: actions/setup-node@v3
- name: Build Assets
run: npm i && npm run build
- name: Test Site - name: Test Site
run: bash tools/test run: bash tools/test

View file

@ -4,9 +4,15 @@
set -eu set -eu
# CLI Dependencies
CLI=("git" "npm")
ACTIONS_WORKFLOW=pages-deploy.yml ACTIONS_WORKFLOW=pages-deploy.yml
TEMP_SUFFIX="to-delete" # temporary file suffixes that make `sed -i` compatible with BSD and Linux # temporary file suffixes that make `sed -i` compatible with BSD and Linux
TEMP_SUFFIX="to-delete"
_no_gh=false
help() { help() {
echo "Usage:" echo "Usage:"
@ -18,14 +24,32 @@ help() {
echo " -h, --help Print this help information." echo " -h, --help Print this help information."
} }
check_status() { # BSD and GNU compatible sed
_sedi() {
regex=$1
file=$2
sed -i.$TEMP_SUFFIX "$regex" "$file"
rm -f "$file".$TEMP_SUFFIX
}
_check_cli() {
for i in "${!CLI[@]}"; do
cli="${CLI[$i]}"
if ! command -v "$cli" &>/dev/null; then
echo "Command '$cli' not found! Hint: you should install it."
exit 1
fi
done
}
_check_status() {
if [[ -n $(git status . -s) ]]; then if [[ -n $(git status . -s) ]]; then
echo "Error: Commit unstaged files first, and then run this tool again." echo "Error: Commit unstaged files first, and then run this tool again."
exit 1 exit 1
fi fi
} }
check_init() { _check_init() {
local _has_inited=false local _has_inited=false
if [[ ! -d .github ]]; then # using option `--no-gh` if [[ ! -d .github ]]; then # using option `--no-gh`
@ -47,9 +71,10 @@ check_init() {
fi fi
} }
checkout_latest_tag() { check_env() {
tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") _check_cli
git reset --hard "$tag" _check_status
_check_init
} }
init_files() { init_files() {
@ -63,25 +88,30 @@ init_files() {
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW} mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
## Cleanup image settings in site config ## Cleanup image settings in site config
sed -i.$TEMP_SUFFIX "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml _sedi "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
rm -f _config.yml.$TEMP_SUFFIX
fi fi
# remove the other fies # remove the other fies
rm -rf _posts/* rm -rf _posts/*
# save changes # build assest
git add -A npm i && npm run build
git commit -m "chore: initialize the environment" -q
echo "[INFO] Initialization successful!" # track the js output
_sedi "/^assets.*\/dist/d" .gitignore
} }
check_status commit() {
git add -A
git commit -m "chore: initialize the environment" -q
echo -e "\n[INFO] Initialization successful!\n"
}
check_init main() {
check_env
_no_gh=false init_files
commit
}
while (($#)); do while (($#)); do
opt="$1" opt="$1"
@ -102,6 +132,4 @@ while (($#)); do
esac esac
done done
checkout_latest_tag main
init_files

View file

@ -29,7 +29,6 @@ NODE_CONFIG="package.json"
FILES=( FILES=(
"_sass/jekyll-theme-chirpy.scss" "_sass/jekyll-theme-chirpy.scss"
"_javascript/copyright"
"$GEM_SPEC" "$GEM_SPEC"
"$NODE_CONFIG" "$NODE_CONFIG"
) )
@ -69,17 +68,24 @@ _check_git() {
} }
_check_src() { _check_src() {
if [[ ! -f $1 && ! -d $1 ]]; then for i in "${!FILES[@]}"; do
echo -e "Error: Missing file \"$1\"!\n" _src="${FILES[$i]}"
exit 1 if [[ ! -f $_src && ! -d $_src ]]; then
fi echo -e "Error: Missing file \"$_src\"!\n"
exit 1
fi
done
} }
_check_command() { _check_command() {
if ! command -v "$1" &>/dev/null; then for i in "${!TOOLS[@]}"; do
echo "Command '$1' not found" cli="${TOOLS[$i]}"
exit 1 if ! command -v "$cli" &>/dev/null; then
fi echo "Command '$cli' not found!"
exit 1
fi
done
} }
_check_node_packages() { _check_node_packages() {
@ -89,20 +95,13 @@ _check_node_packages() {
} }
check() { check() {
_check_command
_check_git _check_git
_check_src
for i in "${!FILES[@]}"; do
_check_src "${FILES[$i]}"
done
for i in "${!TOOLS[@]}"; do
_check_command "${TOOLS[$i]}"
done
_check_node_packages _check_node_packages
} }
_bump_file() { _bump_files() {
for i in "${!FILES[@]}"; do for i in "${!FILES[@]}"; do
if [[ ${FILES[$i]} == "$NODE_CONFIG" ]]; then if [[ ${FILES[$i]} == "$NODE_CONFIG" ]]; then
continue continue
@ -111,7 +110,7 @@ _bump_file() {
sed -i "s/v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/v$1/" "${FILES[$i]}" sed -i "s/v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/v$1/" "${FILES[$i]}"
done done
npx gulp npm run build
} }
_bump_gemspec() { _bump_gemspec() {
@ -127,7 +126,7 @@ _bump_gemspec() {
# #
# 2. Create a commit to save the changes. # 2. Create a commit to save the changes.
bump() { bump() {
_bump_file "$1" _bump_files "$1"
_bump_gemspec "$1" _bump_gemspec "$1"
if [[ $opt_pre = false && -n $(git status . -s) ]]; then if [[ $opt_pre = false && -n $(git status . -s) ]]; then