From 0a7764fc7876fdb6fa2a7de9c2ccaf121c68a192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E9=9B=81=20Cryolitia?= Date: Sat, 6 Apr 2024 08:56:11 +0800 Subject: [PATCH] ci: fix build --- .github/CODEOWNERS | 1 + .github/workflows/build.yaml | 21 +++---------- .github/workflows/publish.yaml | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/publish.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..f1c58023 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +/.github @Cryolitia diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 52922c92..54d579c6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,12 +1,13 @@ -name: Build and publish +name: Build releases on: workflow_dispatch: + pull_request: push: branches: - "main" paths: - - ".github/**" + - ".github/workflows/build.yaml" - ".vitepress/**" - "src/**" - "theme/**" @@ -33,12 +34,6 @@ jobs: with: fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: current - cache: pnpm - - name: Setup pnpm uses: pnpm/action-setup@v3 with: @@ -103,16 +98,8 @@ jobs: sed -e "s/BUILD_TIME/$(TZ=Asia/Shanghai date -Isecond)/" -e "s/COMMIT_SHA/${{ github.sha }}/" -i src/about.md pnpm run build - - name: Publish to Cloudflare Pages - uses: cloudflare/pages-action@v1 - with: - apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }} - projectName: proskynova-github-io - directory: .vitepress/dist/ - wranglerVersion: 3 - - name: Release eBook + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' env: GITHUB_TOKEN: ${{ github.token }} run: pnpm exec semantic-release diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..7e78dafa --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,57 @@ +name: Publish to Cloudflare + +on: + workflow_dispatch: + pull_request: + push: + branches: + - "main" + paths: + - ".github/workflows/publish.yaml" + - ".vitepress/**" + - "src/**" + - "theme/**" + - "package-lock.json" + - "package.json" + +permissions: + contents: write + issues: write + pull-requests: write + +concurrency: + group: "publish" + cancel-in-progress: true + +jobs: + build: + name: Build and publish + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: latest + run_install: true + + - name: Build + env: + NODE_OPTIONS: --max_old_space_size=4096 + run: | + sed -e "s/BUILD_TIME/$(TZ=Asia/Shanghai date -Isecond)/" -e "s/COMMIT_SHA/${{ github.sha }}/" -i src/about.md + pnpm run web:build + + - name: Publish to Cloudflare Pages + uses: cloudflare/pages-action@v1 + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + with: + apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }} + projectName: transky-book + directory: .vitepress/dist/ + wranglerVersion: 3