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:
push:
branches-ignore:
- 'production'
- 'docs'
- "production"
- "docs"
paths-ignore:
- '.github/**'
- '!.github/workflows/ci.yml'
- '.gitignore'
- 'README.md'
- 'LICENSE'
- ".github/**"
- "!.github/workflows/ci.yml"
- ".gitignore"
- "README.md"
- "LICENSE"
pull_request:
paths:
- '**'
- "**"
jobs:
build:
@ -34,5 +34,11 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@v3
- name: Build Assets
run: npm i && npm run build
- name: Test Site
run: bash tools/test

View file

@ -4,9 +4,15 @@
set -eu
# CLI Dependencies
CLI=("git" "npm")
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() {
echo "Usage:"
@ -18,14 +24,32 @@ help() {
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
echo "Error: Commit unstaged files first, and then run this tool again."
exit 1
fi
}
check_init() {
_check_init() {
local _has_inited=false
if [[ ! -d .github ]]; then # using option `--no-gh`
@ -47,9 +71,10 @@ check_init() {
fi
}
checkout_latest_tag() {
tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
git reset --hard "$tag"
check_env() {
_check_cli
_check_status
_check_init
}
init_files() {
@ -63,25 +88,30 @@ init_files() {
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
## Cleanup image settings in site config
sed -i.$TEMP_SUFFIX "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
rm -f _config.yml.$TEMP_SUFFIX
_sedi "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
fi
# remove the other fies
rm -rf _posts/*
# save changes
git add -A
git commit -m "chore: initialize the environment" -q
# build assest
npm i && npm run build
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
_no_gh=false
main() {
check_env
init_files
commit
}
while (($#)); do
opt="$1"
@ -102,6 +132,4 @@ while (($#)); do
esac
done
checkout_latest_tag
init_files
main

View file

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