Skip to content

Commit 60229ae

Browse files
committed
chore(ci,tools): adapt to changes in JS builds
1 parent b69d3d7 commit 60229ae

File tree

3 files changed

+83
-50
lines changed

3 files changed

+83
-50
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
name: 'CI'
1+
name: "CI"
22
on:
33
push:
44
branches-ignore:
5-
- 'production'
6-
- 'docs'
5+
- "production"
6+
- "docs"
77
paths-ignore:
8-
- '.github/**'
9-
- '!.github/workflows/ci.yml'
10-
- '.gitignore'
11-
- 'README.md'
12-
- 'LICENSE'
8+
- ".github/**"
9+
- "!.github/workflows/ci.yml"
10+
- ".gitignore"
11+
- "README.md"
12+
- "LICENSE"
1313
pull_request:
1414
paths:
15-
- '**'
15+
- "**"
1616

1717
jobs:
1818
build:
@@ -26,13 +26,19 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v3
2828
with:
29-
fetch-depth: 0 # for posts's lastmod
29+
fetch-depth: 0 # for posts's lastmod
3030

3131
- name: Setup Ruby
3232
uses: ruby/setup-ruby@v1
3333
with:
3434
ruby-version: ${{ matrix.ruby }}
3535
bundler-cache: true
3636

37+
- name: Setup Node
38+
uses: actions/setup-node@v3
39+
40+
- name: Build Assets
41+
run: npm i && npm run build
42+
3743
- name: Test Site
3844
run: bash tools/test

tools/init

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44

55
set -eu
66

7+
# CLI Dependencies
8+
CLI=("git" "npm")
9+
710
ACTIONS_WORKFLOW=pages-deploy.yml
811

9-
TEMP_SUFFIX="to-delete" # temporary file suffixes that make `sed -i` compatible with BSD and Linux
12+
# temporary file suffixes that make `sed -i` compatible with BSD and Linux
13+
TEMP_SUFFIX="to-delete"
14+
15+
_no_gh=false
1016

1117
help() {
1218
echo "Usage:"
@@ -18,14 +24,32 @@ help() {
1824
echo " -h, --help Print this help information."
1925
}
2026

21-
check_status() {
27+
# BSD and GNU compatible sed
28+
_sedi() {
29+
regex=$1
30+
file=$2
31+
sed -i.$TEMP_SUFFIX "$regex" "$file"
32+
rm -f "$file".$TEMP_SUFFIX
33+
}
34+
35+
_check_cli() {
36+
for i in "${!CLI[@]}"; do
37+
cli="${CLI[$i]}"
38+
if ! command -v "$cli" &>/dev/null; then
39+
echo "Command '$cli' not found! Hint: you should install it."
40+
exit 1
41+
fi
42+
done
43+
}
44+
45+
_check_status() {
2246
if [[ -n $(git status . -s) ]]; then
2347
echo "Error: Commit unstaged files first, and then run this tool again."
2448
exit 1
2549
fi
2650
}
2751

28-
check_init() {
52+
_check_init() {
2953
local _has_inited=false
3054

3155
if [[ ! -d .github ]]; then # using option `--no-gh`
@@ -47,9 +71,10 @@ check_init() {
4771
fi
4872
}
4973

50-
checkout_latest_tag() {
51-
tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
52-
git reset --hard "$tag"
74+
check_env() {
75+
_check_cli
76+
_check_status
77+
_check_init
5378
}
5479

5580
init_files() {
@@ -63,25 +88,30 @@ init_files() {
6388
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
6489

6590
## Cleanup image settings in site config
66-
sed -i.$TEMP_SUFFIX "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
67-
rm -f _config.yml.$TEMP_SUFFIX
91+
_sedi "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
6892
fi
6993

7094
# remove the other fies
7195
rm -rf _posts/*
7296

73-
# save changes
74-
git add -A
75-
git commit -m "chore: initialize the environment" -q
97+
# build assest
98+
npm i && npm run build
7699

77-
echo "[INFO] Initialization successful!"
100+
# track the js output
101+
_sedi "/^assets.*\/dist/d" .gitignore
78102
}
79103

80-
check_status
81-
82-
check_init
104+
commit() {
105+
git add -A
106+
git commit -m "chore: initialize the environment" -q
107+
echo -e "\n[INFO] Initialization successful!\n"
108+
}
83109

84-
_no_gh=false
110+
main() {
111+
check_env
112+
init_files
113+
commit
114+
}
85115

86116
while (($#)); do
87117
opt="$1"
@@ -102,6 +132,4 @@ while (($#)); do
102132
esac
103133
done
104134

105-
checkout_latest_tag
106-
107-
init_files
135+
main

tools/release

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ NODE_CONFIG="package.json"
2929

3030
FILES=(
3131
"_sass/jekyll-theme-chirpy.scss"
32-
"_javascript/copyright"
3332
"$GEM_SPEC"
3433
"$NODE_CONFIG"
3534
)
@@ -69,17 +68,24 @@ _check_git() {
6968
}
7069

7170
_check_src() {
72-
if [[ ! -f $1 && ! -d $1 ]]; then
73-
echo -e "Error: Missing file \"$1\"!\n"
74-
exit 1
75-
fi
71+
for i in "${!FILES[@]}"; do
72+
_src="${FILES[$i]}"
73+
if [[ ! -f $_src && ! -d $_src ]]; then
74+
echo -e "Error: Missing file \"$_src\"!\n"
75+
exit 1
76+
fi
77+
done
78+
7679
}
7780

7881
_check_command() {
79-
if ! command -v "$1" &>/dev/null; then
80-
echo "Command '$1' not found"
81-
exit 1
82-
fi
82+
for i in "${!TOOLS[@]}"; do
83+
cli="${TOOLS[$i]}"
84+
if ! command -v "$cli" &>/dev/null; then
85+
echo "Command '$cli' not found!"
86+
exit 1
87+
fi
88+
done
8389
}
8490

8591
_check_node_packages() {
@@ -89,20 +95,13 @@ _check_node_packages() {
8995
}
9096

9197
check() {
98+
_check_command
9299
_check_git
93-
94-
for i in "${!FILES[@]}"; do
95-
_check_src "${FILES[$i]}"
96-
done
97-
98-
for i in "${!TOOLS[@]}"; do
99-
_check_command "${TOOLS[$i]}"
100-
done
101-
100+
_check_src
102101
_check_node_packages
103102
}
104103

105-
_bump_file() {
104+
_bump_files() {
106105
for i in "${!FILES[@]}"; do
107106
if [[ ${FILES[$i]} == "$NODE_CONFIG" ]]; then
108107
continue
@@ -111,7 +110,7 @@ _bump_file() {
111110
sed -i "s/v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/v$1/" "${FILES[$i]}"
112111
done
113112

114-
npx gulp
113+
npm run build
115114
}
116115

117116
_bump_gemspec() {
@@ -127,7 +126,7 @@ _bump_gemspec() {
127126
#
128127
# 2. Create a commit to save the changes.
129128
bump() {
130-
_bump_file "$1"
129+
_bump_files "$1"
131130
_bump_gemspec "$1"
132131

133132
if [[ $opt_pre = false && -n $(git status . -s) ]]; then

0 commit comments

Comments
 (0)