55 branches :
66 - master
77 - website_Static
8- paths :
9- - ' Solutions/**' # (#814)
8+ - website_testMaster
109
1110env :
1211 GIT_USER : LetMeFly666
13- GIT_EMAIL : 814114971 @qq.com
12+ GIT_EMAIL : Tisfy @qq.com
1413
1514jobs :
1615 build :
@@ -36,33 +35,73 @@ jobs:
3635 - name : Checkout this repo
3736 uses : actions/checkout@v3
3837 with :
38+ persist-credentials : true
3939 fetch-depth : 1
4040
41- - name : Check for .nodeploy
41+ - name : Whether Skip Deploy( .nodeploy|filePath)
4242 id : deploy-check
4343 run : |
4444 if [ -f .nodeploy ]; then
45+ echo "Found .nodeploy, skip deploy"
4546 echo "SKIP_DEPLOY=true" >> $GITHUB_ENV
47+ exit 0
48+ fi
49+
50+ set -e
51+ echo "GITHUB_REF=$GITHUB_REF"
52+ echo "GITHUB_SHA=$GITHUB_SHA"
53+ echo "GITHUB_EVENT_BEFORE=${{ github.event.before }}"
54+ BRANCH="${GITHUB_REF#refs/heads/}"
55+ echo "Current branch: $BRANCH"
56+
57+ if [ "$BRANCH" = "website_Static" ]; then
58+ echo "website_Static branch, deploy"
59+ elif [ "$BRANCH" = "master" ] || [ "$BRANCH" = "website_testMaster" ]; then # (#814)、(#1318)
60+ echo "master branch, checking Solutions changes"
61+ git fetch --depth=2 origin "$BRANCH"
62+ CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} $GITHUB_SHA || true)
63+ echo "Changed files:"
64+ echo "$CHANGED_FILES"
65+ if echo "$CHANGED_FILES" | grep -q '^Solutions/'; then
66+ echo "Solutions changed, deploy"
67+ else
68+ echo "No Solutions changes, skip deploy"
69+ echo "SKIP_DEPLOY=true" >> $GITHUB_ENV
70+ exit 0
71+ fi
4672 else
47- echo "SKIP_DEPLOY=false" >> $GITHUB_ENV
73+ echo "Other branch ($BRANCH), skip deploy"
74+ echo "SKIP_DEPLOY=true" >> $GITHUB_ENV
75+ exit 0
4876 fi
4977
5078 - name : Fetch and checkout each branch (shallow)
5179 if : env.SKIP_DEPLOY != 'true'
5280 run : |
5381 # git clone git@github.com:LetMeFly666/LeetCode.git --depth=1
5482 # cd LeetCode
83+ # git rev-list --count HEAD
5584 git fetch --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
5685 for branch in $(git branch -r | grep -v '\->'); do
5786 local_branch="${branch#origin/}"
87+ if [[ "$local_branch" =~ ^[0-9] ]] || [[ "$local_branch" == "From_GitCode_CSDN" ]]; then
88+ echo "Skipping branch $local_branch"
89+ continue
90+ fi
5891 if ! git show-ref --quiet "refs/heads/$local_branch"; then
5992 echo "Setting branch $local_branch"
6093 git switch -c $local_branch origin/$local_branch
6194 else
6295 echo "Branch $local_branch already exists, skipping..."
6396 fi
6497 done
65- git switch master
98+
99+ if [ "${GITHUB_REF}" = "refs/heads/website_testMaster" ]; then
100+ git switch website_testMaster
101+ else
102+ git switch master
103+ fi
104+ # git rev-list --count HEAD
66105
67106 - name : Use Node.js ${{ matrix.node_version }}
68107 if : env.SKIP_DEPLOY != 'true'
@@ -98,16 +137,7 @@ jobs:
98137 ssh-keyscan github.com >> ~/.ssh/known_hosts
99138 git config --global user.name $GIT_USER
100139 git config --global user.email $GIT_EMAIL
101-
102- - name : Install hexo and init
103- if : env.SKIP_DEPLOY != 'true'
104- run : |
105- npm install -g hexo-cli --save
106- hexo init ../hexoWorkspace
107- rm -f ../hexoWorkspace/source/_posts/hello-world.md # 不再显示Hello World这篇文章(每次都显示在首页)
108- sed -i 's/"<em>" + text + "<\/em>"/"_" + text + "_"/g' ../hexoWorkspace/node_modules/marked/lib/*
109- # cat ../hexoWorkspace/node_modules/marked/lib/*
110-
140+
111141 # 上次commit记录
112142 MESSAGE=$(git log -1 --format="%s")
113143 HASH=$(git log -1 --format="%H")
@@ -118,11 +148,104 @@ jobs:
118148 echo "$HASH"
119149 echo "MESSAGE=$MESSAGE" >> $GITHUB_ENV
120150 echo "HASH=$HASH" >> $GITHUB_ENV
151+
152+ - name : Checkout LastModifiedTime.json
153+ if : env.SKIP_DEPLOY != 'true'
154+ run : |
155+ git switch website_modifyTime
156+ cd ..
157+ cp -r LeetCode website_modifyTime
158+ cd LeetCode
159+
160+ if [ "${GITHUB_REF}" = "refs/heads/website_testMaster" ]; then
161+ git switch website_testMaster
162+ else
163+ git switch master
164+ fi
165+
166+ - name : Update LastModifiedTime.json
167+ if : (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/website_testMaster' ) && env.SKIP_DEPLOY != 'true'
168+ continue-on-error : false
169+ run : |
170+ set -e
171+
172+ json_file="../website_modifyTime/LastModifiedTime.json"
173+
174+ # 获取本次 push 里 master 分支变动的文件列表
175+ # TODO: Let's处理删除removed
176+ # TODO: Let's solve this
177+ echo '${{ toJSON(github.event) }}' | jq .
178+ changed_files=$(jq -r '
179+ [
180+ .commits[].added[]?,
181+ .commits[].modified[]?
182+ ]
183+ | unique
184+ | .[]
185+ ' "$GITHUB_EVENT_PATH")
186+ echo "Changed files:"
187+ echo "$changed_files"
188+
189+ # 保存原 json 内容顺序
190+ tmp_json=$(mktemp)
191+ cp "$json_file" "$tmp_json"
192+
193+ # 遍历每个文件,看是否是 Solutions 下的 md 文件
194+ updated=false
195+ commit_time=$(git show -s --format=%cI ${{ github.sha }}) # ISO 8601 commit 时间
196+
197+ while IFS= read -r file; do
198+ # 只处理 Solutions/*.md 文件
199+ if [[ "$file" == Solutions/*.md ]]; then
200+ filename=$(basename "$file")
201+ # 使用 jq 更新 JSON 值
202+ # 保持原有顺序,用临时文件写回
203+ jq --arg key "$filename" --arg value "$commit_time" '(.[$key] = $value) | .' "$tmp_json" > "$tmp_json.tmp" && mv "$tmp_json.tmp" "$tmp_json"
204+ updated=true
205+ fi
206+ done <<< "$changed_files"
207+
208+ if [ "$updated" != true ]; then
209+ echo "No Solutions/*.md file changed, skip JSON update."
210+ exit 0
211+ fi
212+
213+ # 提交修改
214+ cp "$tmp_json" "$json_file"
215+ cd ../website_modifyTime
216+ git add "$json_file"
217+ TOCOMMIT=$(printf "%s\n\n%s" "$MESSAGE" "$HASH")
218+ git commit --allow-empty -m "$TOCOMMIT"
219+ git push
220+ cd ../LeetCode
221+
222+ - name : Update Solutions/*.md file mtime
223+ if : env.SKIP_DEPLOY != 'true'
224+ run : |
225+ set -e
226+
227+ json_file="../website_modifyTime/LastModifiedTime.json"
228+
229+ while IFS= read -r line; do
230+ file_name=$(echo "$line" | jq -r 'keys[0]')
231+ file_time=$(echo "$line" | jq -r '.[keys[0]]')
232+ touch -d "$file_time" "Solutions/$file_name"
233+ echo "set Solutions/$file_name -> $file_time"
234+ done < <(jq -c 'to_entries | map({(.key): .value}) | .[]' "$json_file")
235+
236+ - name : Install hexo and init
237+ if : env.SKIP_DEPLOY != 'true'
238+ run : |
239+ npm install -g hexo-cli --save
240+ hexo init ../hexoWorkspace
241+ rm -f ../hexoWorkspace/source/_posts/hello-world.md # 不再显示Hello World这篇文章(每次都显示在首页)
242+ sed -i 's/"<em>" + text + "<\/em>"/"_" + text + "_"/g' ../hexoWorkspace/node_modules/marked/lib/*
243+ # cat ../hexoWorkspace/node_modules/marked/lib/*
121244
122245 - name : Copy config files from branch website_Static
123246 if : env.SKIP_DEPLOY != 'true'
124247 run : |
125- cp -r Solutions ../Articles
248+ cp -a Solutions ../Articles
126249
127250 echo --- > ../Articles/README.md
128251 echo title: README >> ../Articles/README.md
@@ -141,7 +264,9 @@ jobs:
141264 # echo tree ../hexoWorkspace/source/_posts
142265
143266 # sub theme: 明日方舟arknights
144- cp -r ../hexoWorkspace ../hexoWorkspace_arknights
267+ cp -a ../hexoWorkspace ../hexoWorkspace_arknights
268+ ls -l ../hexoWorkspace/source/_posts
269+ ls -l ../hexoWorkspace_arknights/source/_posts
145270
146271 - name : Install dependencies
147272 if : env.SKIP_DEPLOY != 'true'
@@ -188,6 +313,8 @@ jobs:
188313 - name : Modify sitemap
189314 if : env.SKIP_DEPLOY != 'true'
190315 run : |
316+ # TODO: Let's change this
317+ # TODO: Let's change tag orders
191318 echo "" > ../hexoWorkspace/public/sitemap.txt # 主站优先
192319 sed 's/theme\/arknights\///g' ../hexoWorkspace/public/theme/arknights/sitemap.txt >> ../hexoWorkspace/public/sitemap.txt
193320 cat ../hexoWorkspace/public/theme/arknights/sitemap.txt >> ../hexoWorkspace/public/sitemap.txt
@@ -253,6 +380,6 @@ jobs:
253380 # uses: EndBug/add-and-commit@v9
254381 # with:
255382 # author_name: LetMeFly
256- # author_email: 814114971 @qq.com
383+ # author_email: Tisfy @qq.com
257384 # message: "backup .deploy_git"
258385 # add: "."
0 commit comments