之前在 通过 GitHub Actions 自动部署 Hexo,通过创建两个不同的分支,raw
分支存储原始的 Hexo 项目,master
分支存储 hexo generate
编译出来的静态页面,通过 hexo deploy
来部署。由于使用了 hexo deploy
需要设置部署用的 SSH 密钥。
下面的办法更简单,不需要做额外的设置,Hexo 项目在 main
分支,不需要再添加其他分支。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| name: Hexo deploy
on: push: branches: - raw - main
jobs: build: runs-on: ubuntu-latest
steps: - uses: actions/checkout@v4 - name: Use Node.js (.tool-versions) uses: actions/setup-node@v4 with: node-version-file: ".tool-versions" - uses: pnpm/action-setup@v3 name: Install pnpm with: version: 8 run_install: false - name: Get pnpm store directory shell: bash run: | echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - uses: actions/cache@v4 name: Setup pnpm cache with: path: ${{ env.STORE_PATH }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - name: Install Dependencies run: pnpm install - name: Build run: pnpm run build - name: Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: ./public 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
|
---EOF---