From 349ca7f6861b03589f5e383c29ca89d9a936cdd0 Mon Sep 17 00:00:00 2001 From: Tianen Pang <32772271+tianenpang@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:18:31 +0800 Subject: [PATCH] chore: update workflow and related configs --- .commitlintrc.cjs => .commitlintrc.mjs | 7 +++-- .github/workflows/ci.yml | 28 ++++++++++++++++---- .github/workflows/commitlint.yml | 36 ++++++++++++-------------- .husky/commit-msg | 5 +--- .husky/pre-commit | 10 +------ .lintstagedrc.cjs => .lintstagedrc.mjs | 9 ++++--- 6 files changed, 53 insertions(+), 42 deletions(-) rename .commitlintrc.cjs => .commitlintrc.mjs (78%) rename .lintstagedrc.cjs => .lintstagedrc.mjs (87%) diff --git a/.commitlintrc.cjs b/.commitlintrc.mjs similarity index 78% rename from .commitlintrc.cjs rename to .commitlintrc.mjs index e5aa284..f6a8ad8 100644 --- a/.commitlintrc.cjs +++ b/.commitlintrc.mjs @@ -1,6 +1,7 @@ -const conventional = require("@commitlint/config-conventional"); +import conventional from "@commitlint/config-conventional"; -module.exports = { + +const commitLintConfig = { extends: ["@commitlint/config-conventional"], plugins: ["commitlint-plugin-function-rules"], helpUrl: @@ -15,3 +16,5 @@ module.exports = { "function-rules/header-max-length": [0], }, }; + +export default commitLintConfig; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d188925..855f3eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,18 +15,36 @@ jobs: script: [lint, test, build] steps: - name: Checkout Codebase - uses: actions/checkout@v3 - - name: Setup Pnpm - uses: pnpm/action-setup@v2 + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 with: run_install: false - - name: Setup Node - uses: actions/setup-node@v3 + + - name: Setup node + uses: actions/setup-node@v4 with: cache: "pnpm" check-latest: true node-version-file: ".nvmrc" + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Setup pnpm cache + uses: actions/cache@v4 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install Dependencies + shell: bash run: pnpm install --frozen-lockfile + - name: Run Script ${{ matrix.script }} run: pnpm ${{ matrix.script }} diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index b7324a3..7e77f5d 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -4,31 +4,29 @@ on: [pull_request] jobs: commitlint: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + environment: Preview + steps: - - name: Checkout Codebase - uses: actions/checkout@v3 + - name: Checkout codebase + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup pnpm - uses: pnpm/action-setup@v2 - with: - run_install: false - - name: Setup Node - uses: actions/setup-node@v3 - with: - cache: "pnpm" - check-latest: true - node-version-file: ".nvmrc" - - name: Install Dependencies - run: pnpm install --frozen-lockfile - - name: Run Commitlint + + - name: Install dependencies + uses: ./.github/actions/install + + - name: Run commitlint id: run_commitlint - uses: wagoid/commitlint-github-action@v5 + uses: wagoid/commitlint-github-action@v6 with: - configFile: .commitlintrc.cjs + configFile: .commitlintrc.mjs env: NODE_PATH: ${{ github.workspace }}/node_modules - - name: Show Outputs + + - name: Show outputs if: ${{ always() }} run: echo ${{ toJSON(steps.run_commitlint.outputs.results) }} diff --git a/.husky/commit-msg b/.husky/commit-msg index a2a78ce..1ad95cc 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -pnpm commitlint --config .commitlintrc.cjs --edit ${1} +pnpm commitlint --config .commitlintrc.mjs --edit ${1} diff --git a/.husky/pre-commit b/.husky/pre-commit index 5ad5bd3..6a6887e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,9 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -# Avoid excessive outputs -if [ -t 2 ]; then - exec >/dev/tty 2>&1 -fi - -pnpm lint-staged +pnpm lint-staged -c .lintstagedrc.mjs diff --git a/.lintstagedrc.cjs b/.lintstagedrc.mjs similarity index 87% rename from .lintstagedrc.cjs rename to .lintstagedrc.mjs index 27d9e8f..6236018 100644 --- a/.lintstagedrc.cjs +++ b/.lintstagedrc.mjs @@ -1,6 +1,6 @@ -const {relative} = require("path"); +import {relative} from "path"; -const {ESLint} = require("eslint"); +import {ESLint} from "eslint"; const removeIgnoredFiles = async (files) => { const cwd = process.cwd(); @@ -12,7 +12,8 @@ const removeIgnoredFiles = async (files) => { return filteredFiles.join(" "); }; -module.exports = { + +const lintStaged = { // *.!(js|ts|jsx|tsx|d.ts) "**/*.{js,cjs,mjs,ts,jsx,tsx,json,md}": async (files) => { const filesToLint = await removeIgnoredFiles(files); @@ -25,3 +26,5 @@ module.exports = { return [`eslint -c .eslintrc.json --max-warnings=0 --fix ${filesToLint}`]; }, }; + +export default lintStaged;