Skip to content

Merge pull request #53 from fishcpy/main #20

Merge pull request #53 from fishcpy/main

Merge pull request #53 from fishcpy/main #20

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches: [ main, master ]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref || github.ref }}
- name: Set up timezone
run: |
sudo timedatectl set-timezone Asia/Shanghai
- name: Update build time
run: |
# 获取当前日期时间
BUILD_TIME=$(date '+%Y.%-m.%-d %H:%M:%S')
echo "Updating build time to: $BUILD_TIME"
# 更新 buildTime.js 文件
sed -i "s/const BUILD_TIME = '.*';/const BUILD_TIME = '$BUILD_TIME';/" js/buildTime.js
# 验证更新
echo "Updated buildTime.js:"
cat js/buildTime.js | head -1
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Commit build time changes to pages branch
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if ! git diff --quiet js/buildTime.js; then
BUILD_TIME=$(date '+%Y.%-m.%-d %H:%M:%S')
# 创建或切换到pages分支
git checkout -B pages
# 删除README和LICENSE文件以及.github文件夹
rm -f README.md README_EN.md LICENSE.txt
rm -rf .github
echo "Removed README.md, README_EN.md, LICENSE.txt, and .github folder from pages branch"
# 添加并提交更改
git add -A
git commit -m "🤖 Auto update build time to $BUILD_TIME and remove docs"
# 推送到pages分支
git push origin pages --force
echo "Build time updated and pushed to pages branch: $BUILD_TIME"
else
echo "No changes to build time"
fi