Skip to content

Commit

Permalink
CST 2024-07-18 14:20:36
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo-Messi committed Jul 18, 2024
1 parent 10aa9b0 commit 59ee553
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 32 deletions.
49 changes: 18 additions & 31 deletions .github/workflows/update_time.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # 获取完整的提交历史
fetch-depth: 0

- name: Set up Git
run: |
Expand All @@ -25,33 +25,22 @@ jobs:
id: current_date
run: echo "DATE=$(TZ='Asia/Shanghai' date +'%Z %Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV

- name: Update files with commit info # 第四步:更新文件中的提交信息
- name: Update files with commit info
run: |
# current_date="${{ env.DATE }}" # 读取环境变量中的当前日期
# 需要更新的文件
files_to_update="Proxy/**/*"
# 遍历每个文件
for file in $files_to_update; do
if [ -f "$file" ]; then
# 前置条件:检查上一次提交中是否有这些文件的变动
if git diff HEAD~1 HEAD -- "$file" | grep -q "$file"; then
# 读取原始文件内容
original_content=$(cat "$file") # 读取原始文件内容
# 替换现有的更新时间信息(如果存在)
original_content=$(cat "$file")
updated_content=$(echo "$original_content" | sed -E 's/^# Updated: .*/# Updated: '"${{ env.DATE }}"'/')
# 将更新后的内容写入临时文件
echo "$updated_content" > "$file.tmp"
# 检查文件是否有改动
if ! cmp -s "$file" "$file.tmp"; then # 使用 cmp -s 比较文件内容
# 如果文件有改动,则替换原文件
mv "$file.tmp" "$file" # 替换原文件
if ! cmp -s "$file" "$file.tmp"; then
mv "$file.tmp" "$file"
else
# 如果文件没有改动,则删除临时文件
rm "$file.tmp" # 删除临时文件
rm "$file.tmp"
fi
else
echo "$file has no changes in the last commit."
Expand All @@ -62,31 +51,29 @@ jobs:
- name: Commit and push changes
run: |
git add Proxy/**/*
git diff --quiet || git commit -m "${{ env.DATE }}"
git reset --soft HEAD^ #重置索引并保留更改
if ! git diff --quiet; then
git commit -m "${{ env.DATE }}"
fi
git reset --soft HEAD^
git commit -m "${{ env.DATE }}"
git push -f origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

## Brak通知流程运行状态

- name: Translate job status to Chinese
id: translate-status
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "translated_status=成功" >> $GITHUB_ENV
elif [ "${{ job.status }}" == "failure" ]; then
echo "translated_status=失败" >> $GITHUB_ENV
elif [ "${{ job.status }}" == "cancelled" ]; then
echo "translated_status=取消" >> $GITHUB_ENV
else
echo "translated_status=未知" >> $GITHUB_ENV
fi
case "${{ job.status }}" in
success) translated_status="成功" ;;
failure) translated_status="失败" ;;
cancelled) translated_status="取消" ;;
*) translated_status="未知" ;;
esac
echo "translated_status=$translated_status" >> $GITHUB_ENV
- name: Notify job status
if: always() # 确保这一步始终运行,不管之前的步骤是否成功
if: always()
run: |
curl -X "POST" "${{ secrets.BARK_KEY }}" \
-H 'Content-Type: application/json; charset=utf-8' \
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
{
"scripts": {
"prettier": "prettier --write .",
"check": "prettier . --check",
"pull": "git fetch origin && git reset --hard origin/main",
"push": "git add . && git commit -m 'update'",
"soft": "git reset --soft HEAD^ && git add . && git commit -m 'update' && git push -f origin main",
"ps": "pnpm run push && pnpm run soft"
},
"dependencies": {
"devDependencies": {
"prettier": "^3.3.3"
},
"dependencies": {
"lint-staged": "^15.2.7",
"simple-git-hooks": "^2.11.1"
},
"prettier": {
"semi": false,
"singleQuote": true,
"printWidth": 300,
"trailingComma": "none"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": [
"prettier --write --ignore-unknown"
]
}
}
Loading

0 comments on commit 59ee553

Please sign in to comment.