Skip to content

Commit

Permalink
feat: auto build site
Browse files Browse the repository at this point in the history
  • Loading branch information
renbaoshuo committed Aug 18, 2024
1 parent 2aa38a2 commit b6ed789
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build Site

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: yarn

- name: node_modules CI Cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}

- name: Next.js CI Cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- name: Install Dependencies
run: yarn install --frozen-lockfile --prefer-offline

- name: Build Site
run: yarn build
env:
CDNJS_BASE_URL: https://cdnjs.baoshuo.ren/ajax/libs

- name: Upload Build Output to Artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: ${{ github.workspace }}/out/
if-no-files-found: error

deploy-gh-pages:
name: Deploy Site to GitHub Pages
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: [build]
timeout-minutes: 15

steps:
- uses: actions/download-artifact@v3
with:
name: dist
path: ${{ github.workspace }}/out/

- run: ls -R ${{ github.workspace }}/out/

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: out
cname: baoshuo.ren
user_name: BaoshuoBot
user_email: [email protected]

0 comments on commit b6ed789

Please sign in to comment.