Skip to content

Merge pull request #11 from channinghsu/dependabot/npm_and_yarn/walin… #181

Merge pull request #11 from channinghsu/dependabot/npm_and_yarn/walin…

Merge pull request #11 from channinghsu/dependabot/npm_and_yarn/walin… #181

Workflow file for this run

name: Build and Deploy Pages
on:
push:
branches: [ main ] # 假设您的主分支是 main
repository_dispatch:
types: [trigger-deploy]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MY_TOKEN }}
submodules: recursive
- name: Clone latest posts
env:
GH_PAT: ${{ secrets.MY_TOKEN }}
run: |
rm -rf source/_posts
git clone https://[email protected]/channinghsu/Blog-Post.git source/_posts
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # 使用 Node.js 20 LTS 版本
- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
continue-on-error: true
- name: Check build output
run: |
if [ ! -d "public" ]; then
echo "Build failed: public directory not found"
exit 1
fi
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Checkout deploy repo
uses: actions/checkout@v4
with:
repository: channinghsu/blog_deploy
ref: gh-pages
token: ${{ secrets.MY_TOKEN }}
path: blog_deploy
- name: Copy build output to deploy repo
run: |
cp -r ./public/* blog_deploy/
- name: Commit and push changes to deploy repo
run: |
cd blog_deploy
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Deploy new static files - $(date +'%Y-%m-%d %H:%M:%S')"
git push origin gh-pages
deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
cleanup:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Cleanup workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.MY_TOKEN }}
repository: ${{ github.repository }}
retain_days: 30
keep_minimum_runs: 6