Merge pull request #49 from fishcpy/main #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Build Time | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| workflow_dispatch: | |
| jobs: | |
| update-build-time: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: write | |
| 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 and commit to pages branch | |
| 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 | |
| # 配置git | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| # 检查是否有更改并提交到pages分支 | |
| if ! git diff --quiet js/buildTime.js; then | |
| # 创建或切换到pages分支 | |
| git checkout -B pages | |
| # 删除README和LICENSE文件 | |
| rm -f README.md README_EN.md LICENSE.txt | |
| echo "Removed README.md, README_EN.md, and LICENSE.txt 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 |