From 6eaef41447647c754fd9f379dd06088ecd1eb3f6 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Mon, 8 Dec 2025 19:11:44 +0800 Subject: [PATCH] Add CI workflow and update deployment triggers Introduces a new CI workflow for linting, type checking, and testing. Updates sync and workers deployment workflows to trigger on successful completion of the CI workflow instead of direct pushes, improving reliability and sequencing of deployments. --- .github/workflows/ci.yml | 80 +++++++++++++++++++++++++++++++++++ .github/workflows/sync.yml | 18 +++----- .github/workflows/workers.yml | 17 +++----- 3 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d4b4236 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - "**.md" + - "LICENSE" + - ".gitignore" + - ".editorconfig" + - ".vscode/**" + - "docs/**" + - ".github/ISSUE_TEMPLATE/**" + - ".github/PULL_REQUEST_TEMPLATE/**" + pull_request: + branches: + - main + paths-ignore: + - "**.md" + - "LICENSE" + - ".gitignore" + - ".editorconfig" + - ".vscode/**" + - "docs/**" + - ".github/ISSUE_TEMPLATE/**" + - ".github/PULL_REQUEST_TEMPLATE/**" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "22" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Check formatting + run: npm run format:check + + - name: Run ESLint + run: npm run lint + + - name: Type check + run: npm run type-check + + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "22" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm run test:run + + - name: Run tests with coverage + run: npm run test:coverage diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index f5733b6..826239a 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -1,20 +1,12 @@ name: Sync to Pages and Functions on: - push: + workflow_run: + workflows: ["CI"] + types: + - completed branches: - main - paths-ignore: - - "**.md" - - "LICENSE" - - ".gitignore" - - ".editorconfig" - - ".vscode/**" - - "docs/**" - - ".prettierrc*" - - ".eslintrc*" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE/**" workflow_dispatch: concurrency: @@ -27,6 +19,7 @@ jobs: timeout-minutes: 15 permissions: contents: write + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} steps: - name: Checkout main branch @@ -186,6 +179,7 @@ jobs: timeout-minutes: 15 permissions: contents: write + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} steps: - name: Checkout main branch diff --git a/.github/workflows/workers.yml b/.github/workflows/workers.yml index 81c74e5..6e62c7d 100644 --- a/.github/workflows/workers.yml +++ b/.github/workflows/workers.yml @@ -1,20 +1,12 @@ name: Deploy to Cloudflare Workers on: - push: + workflow_run: + workflows: ["CI"] + types: + - completed branches: - main - paths-ignore: - - "**.md" - - "LICENSE" - - ".gitignore" - - ".editorconfig" - - ".vscode/**" - - "docs/**" - - ".prettierrc*" - - ".eslintrc*" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE/**" workflow_dispatch: concurrency: @@ -28,6 +20,7 @@ jobs: permissions: contents: read deployments: write + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} steps: - name: Checkout main branch uses: actions/checkout@v6