main.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 to Cloudflare Pages
  66. uses: cloudflare/wrangler-action@v3
  67. with:
  68. apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
  69. accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
  70. command: pages deploy public --project-name=sukkaw-ruleset --commit-dirty=true --branch=main
  71. - name: Upload Dist to GitLab
  72. run: |
  73. mkdir ./deploy-git
  74. cd ./deploy-git
  75. git config --global init.defaultBranch master
  76. git init
  77. git config --global push.default matching
  78. git config --global user.email "${GITLAB_EMAIL}"
  79. git config --global user.name "${GITLAB_USER}"
  80. git remote add origin https://${GITLAB_TOKEN_NAME}:${GITLAB_TOKEN}@gitlab.com/SukkaW/ruleset.skk.moe.git
  81. git pull origin master
  82. rm -rf ./*
  83. cp -rf ../public/* ./
  84. git add --all .
  85. git commit -m "deploy: https://github.com/SukkaW/Surge/commit/${GITHUB_SHA}"
  86. git push --quiet --force origin HEAD:master
  87. cd ..
  88. rm -rf ./deploy-git
  89. env:
  90. GITLAB_EMAIL: ${{ secrets.GITLAB_EMAIL }}
  91. GITLAB_USER: ${{ secrets.GITLAB_USER }}
  92. GITLAB_TOKEN_NAME: ${{ secrets.GITLAB_TOKEN_NAME }}
  93. GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
  94. - name: Upload Dist to GitHub
  95. uses: peaceiris/actions-gh-pages@v4
  96. continue-on-error: true
  97. with:
  98. personal_token: ${{ secrets.GIT_TOKEN }}
  99. user_name: ${{ secrets.GIT_USER }}
  100. user_email: ${{ secrets.GIT_EMAIL }}
  101. external_repository: SukkaLab/ruleset.skk.moe
  102. publish_branch: master
  103. publish_dir: public
  104. cname: ruleset.skk.moe