# ============================================================ # Build & Deploy — toozhao.com blog # Trigger: push to hexo-source (source/config changes) or manual # Flow: hexo generate -> push static build to master (GitHub Pages auto-deploys) # ============================================================ name: Build & Deploy Blog on: push: branches: [hexo-source] paths: - 'source/**' - '_config*.yml' - 'package.json' - 'package-lock.json' workflow_dispatch: permissions: contents: write jobs: build-and-deploy: runs-on: ubuntu-latest concurrency: group: blog-deploy cancel-in-progress: true steps: - name: Checkout source uses: actions/checkout@v4 with: ref: hexo-source - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 cache: npm cache-dependency-path: package-lock.json - name: Install dependencies run: npm ci - name: Build site run: npx hexo generate - name: Deploy to master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -euo pipefail rm -rf /tmp/deploy git clone --depth 1 -b master "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" /tmp/deploy cd /tmp/deploy # clean old build (keep .git) find . -path ./.git -prune -o -type f -print0 | xargs -0 rm -f find . -path ./.git -prune -o -type d -empty -print0 | xargs -0 rmdir # copy fresh build cp -r "${GITHUB_WORKSPACE}/public/." . git add -A if git diff --cached --quiet; then echo "No changes to deploy." else git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ commit -m "Site updated: $(date -u '+%Y-%m-%d %H:%M:%S') [ci]" git push origin master fi