diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 000000000..9e6019277 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,103 @@ +name: deploy +on: + push: + branches: + - master + schedule: + - cron: "0 12 * * *" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + name: 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: Restore cache.db + uses: actions/cache/restore@v4 + id: cache-db-restore + with: + 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 + - uses: actions/upload-artifact@v4 + with: + name: build-artifact-${{ github. ref_name }} + path: public + if-no-files-found: error + retention-days: 1 + compression-level: 4 + include-hidden-files: false + - name: Cache cache.db + if: always() + uses: actions/cache/save@v4 + with: + 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 }} + deploy_to_cloudflare_pages: + needs: + - build + name: Deploy to Cloudflare Pages + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: build-artifact-${{ github. ref_name }} + path: public + - 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