diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..22f777a --- /dev/null +++ b/.github/workflows/build.yml @@ -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: bot@baoshuo.dev