| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- name: Build
- on:
- push:
- branches:
- - master
- schedule:
- - cron: '0 12 * * *'
- jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - name: Checkout
- uses: actions/checkout@v4
- with:
- persist-credentials: false
- - uses: pnpm/action-setup@v4
- name: Install pnpm
- with:
- run_install: false
- - name: Use Node.js
- uses: actions/setup-node@v4
- with:
- node-version-file: '.node-version'
- cache: 'pnpm'
- - name: Get current date
- id: date
- run: |
- echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
- echo "year=$(date +'%Y')" >> $GITHUB_OUTPUT
- echo "month=$(date +'%m')" >> $GITHUB_OUTPUT
- echo "day=$(date +'%d')" >> $GITHUB_OUTPUT
- echo "hour=$(date +'%H')" >> $GITHUB_OUTPUT
- echo "minute=$(date +'%M')" >> $GITHUB_OUTPUT
- echo "second=$(date +'%S')" >> $GITHUB_OUTPUT
- - name: Cache cache.db
- uses: actions/cache@v4
- with:
- save-always: true
- path: |
- .cache
- key: ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:${{ steps.date.outputs.second }}
- # If source files changed but packages didn't, rebuild from a prior cache.
- restore-keys: |
- ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:
- ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:
- ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }}
- ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-
- ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-
- ${{ runner.os }}-v3-
- - name: Install dependencies
- run: pnpm install
- - run: pnpm run build
- - name: Pre-deploy check
- # If the public directory doesn't exist, the build should fail.
- # If the public directory is empty, the build should fail.
- run: |
- if [ ! -d public ]; then
- echo "public directory not found"
- exit 1
- fi
- if [ ! "$(ls -A public)" ]; then
- echo "public directory is empty"
- exit 1
- fi
- - name: Deploy to Cloudflare Pages
- uses: cloudflare/wrangler-action@v3
- with:
- apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- command: pages deploy public --project-name=sukkaw-ruleset --commit-dirty=true --branch=main
- - name: Upload Dist to GitLab
- run: |
- git clone --filter=blob:none https://${GITLAB_TOKEN_NAME}:${GITLAB_TOKEN}@gitlab.com/SukkaW/ruleset.skk.moe.git ./deploy-git
- cd ./deploy-git
- git config --global push.default matching
- git config --global user.email "${GITLAB_EMAIL}"
- git config --global user.name "${GITLAB_USER}"
- rm -rf ./*
- cp -rf ../public/* ./
- git add --all .
- git commit -m "deploy: https://github.com/SukkaW/Surge/commit/${GITHUB_SHA}"
- git push --quiet --force origin HEAD:master
- cd ..
- rm -rf ./deploy-git
- env:
- GITLAB_EMAIL: ${{ secrets.GITLAB_EMAIL }}
- GITLAB_USER: ${{ secrets.GITLAB_USER }}
- GITLAB_TOKEN_NAME: ${{ secrets.GITLAB_TOKEN_NAME }}
- GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
- - name: Upload Dist to GitHub
- uses: peaceiris/actions-gh-pages@v4
- continue-on-error: true
- with:
- personal_token: ${{ secrets.GIT_TOKEN }}
- user_name: ${{ secrets.GIT_USER }}
- user_email: ${{ secrets.GIT_EMAIL }}
- external_repository: SukkaLab/ruleset.skk.moe
- publish_branch: master
- publish_dir: public
- cname: ruleset.skk.moe
|