main.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. name: Build
  2. on:
  3. push:
  4. branches:
  5. - master
  6. schedule:
  7. - cron: '0 12 * * *'
  8. jobs:
  9. build:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - name: Checkout
  13. uses: actions/checkout@v4
  14. with:
  15. persist-credentials: false
  16. - uses: pnpm/action-setup@v4
  17. name: Install pnpm
  18. with:
  19. run_install: false
  20. - name: Use Node.js
  21. uses: actions/setup-node@v4
  22. with:
  23. node-version-file: '.node-version'
  24. cache: 'pnpm'
  25. - name: Get current date
  26. id: date
  27. run: |
  28. echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
  29. echo "year=$(date +'%Y')" >> $GITHUB_OUTPUT
  30. echo "month=$(date +'%m')" >> $GITHUB_OUTPUT
  31. echo "day=$(date +'%d')" >> $GITHUB_OUTPUT
  32. echo "hour=$(date +'%H')" >> $GITHUB_OUTPUT
  33. echo "minute=$(date +'%M')" >> $GITHUB_OUTPUT
  34. echo "second=$(date +'%S')" >> $GITHUB_OUTPUT
  35. - name: Cache cache.db
  36. uses: actions/cache@v4
  37. with:
  38. save-always: true
  39. path: |
  40. .cache
  41. 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 }}
  42. # If source files changed but packages didn't, rebuild from a prior cache.
  43. restore-keys: |
  44. ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:
  45. ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:
  46. ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }}
  47. ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-
  48. ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-
  49. ${{ runner.os }}-v3-
  50. - name: Install dependencies
  51. run: pnpm install
  52. - run: pnpm run build
  53. - name: Pre-deploy check
  54. # If the public directory doesn't exist, the build should fail.
  55. # If the public directory is empty, the build should fail.
  56. run: |
  57. if [ ! -d public ]; then
  58. echo "public directory not found"
  59. exit 1
  60. fi
  61. if [ ! "$(ls -A public)" ]; then
  62. echo "public directory is empty"
  63. exit 1
  64. fi
  65. - name: Deploy
  66. uses: peaceiris/actions-gh-pages@v4
  67. with:
  68. personal_token: ${{ secrets.GIT_TOKEN }}
  69. user_name: ${{ secrets.GIT_USER }}
  70. user_email: ${{ secrets.GIT_EMAIL }}
  71. external_repository: SukkaLab/ruleset.skk.moe
  72. publish_branch: master
  73. publish_dir: public
  74. cname: ruleset.skk.moe