diff --git a/.github/actions/cache-restore/action.yml b/.github/actions/cache-restore/action.yml new file mode 100644 index 000000000..88ba0132b --- /dev/null +++ b/.github/actions/cache-restore/action.yml @@ -0,0 +1,30 @@ +name: 'Cache restoration' +description: 'Setup a NodeJS environment and restore cache if any, given a node version' + +inputs: + node-version: + description: 'Node version to use, default to LTS' + required: true + default: 22 +outputs: + cache-hit: + description: 'Forward actions/cache cache-hit output' + value: ${{ steps.node-cache.outputs.cache-hit }} + +runs: + using: 'composite' # Mandatory parameter + steps: + # Setup a Node environment given a node version + - name: Use Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + + - name: Cache Node Modules + id: node-cache + uses: actions/cache@v4 + with: + path: | + **/node_modules + ~/.cache + key: ${{ runner.os }}-${{ inputs.node-version }}-${{ hashFiles('package-lock.json') }} diff --git a/.github/workflows/check-packages.yml b/.github/workflows/check-packages.yml new file mode 100644 index 000000000..9d9ad75a2 --- /dev/null +++ b/.github/workflows/check-packages.yml @@ -0,0 +1,44 @@ +name: Package Code Quality + +on: + pull_request: + branches: [canary] + paths-ignore: + - '**/*.md' + - '**/*.php' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + setup-node: + name: Setup Dependencies + uses: ./.github/workflows/node-setup.yml + strategy: + matrix: + node-version: [22] + with: + node-version: ${{ matrix.node-version }} + check_lint: + name: Validate package linting + runs-on: ubuntu-latest + needs: [setup-node] + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Set up Node.js + uses: ./.github/actions/cache-restore + - name: Check Linting + run: npm run lint + check_format: + name: Validate package formatting + runs-on: ubuntu-latest + needs: [setup-node] + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Set up Node.js + uses: ./.github/actions/cache-restore + - name: Check Formatting + run: npm run test:format diff --git a/.github/workflows/lint-packages.yml b/.github/workflows/lint-packages.yml deleted file mode 100644 index 390c1526d..000000000 --- a/.github/workflows/lint-packages.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Lint Packages - -on: - pull_request: - paths-ignore: - - '**/*.md' - -jobs: - lint_packages: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '18' - - run: npm ci - - run: npm run build - - run: npm run lint - continue-on-error: FALSE diff --git a/.github/workflows/lint-plugin.yml b/.github/workflows/lint-plugin.yml index 78bc0bca3..560aa19a1 100644 --- a/.github/workflows/lint-plugin.yml +++ b/.github/workflows/lint-plugin.yml @@ -5,6 +5,10 @@ on: paths-ignore: - '**/*.md' +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: lint_plugin: runs-on: ubuntu-22.04 diff --git a/.github/workflows/node-setup.yml b/.github/workflows/node-setup.yml new file mode 100644 index 000000000..bab5a0cb3 --- /dev/null +++ b/.github/workflows/node-setup.yml @@ -0,0 +1,29 @@ +name: 'Node Workspace Setup' +description: 'Setup a environment and restore cache if any, given a node version' + +on: + workflow_call: + inputs: + node-version: + description: 'Node version to use, default to LTS' + required: true + type: string + default: '22' + +jobs: + setup: + name: Setup Dependencies + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js ${{ inputs.node-version }} + uses: ./.github/actions/cache-restore + id: cache-node-modules + with: + node-version: ${{ inputs.node-version }} + + - name: Install dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci diff --git a/.github/workflows/notify-discord.yml b/.github/workflows/notify-discord.yml index a2b936b9a..8a2f490fe 100644 --- a/.github/workflows/notify-discord.yml +++ b/.github/workflows/notify-discord.yml @@ -12,7 +12,7 @@ on: jobs: release_plugin: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Discord Notification env: diff --git a/package.json b/package.json index dc4becccc..a6fa95558 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dev:next:getting-started": "rimraf examples/next/faustwp-getting-started/.next && npm run dev ---workspace=examples/next/faustwp-getting-started", "test": "npm run build && npm test --workspace=@faustwp/core --workspace=@faustwp/cli --workspace=@faustwp/blocks --workspace=@faustwp/block-editor-utils", "test:coverage": "npm run build && npm run test:coverage --workspace=@faustwp/block-editor-utils", + "test:format": "npm run test:format --workspace=@faustwp/cli --workspace=@faustwp/core --workspace=@faustwp/block-editor-utils", "wpe-build": "exit 1", "changeset": "changeset", "version": "changeset version && node scripts/versionPlugin.js", diff --git a/packages/block-editor-utils/package.json b/packages/block-editor-utils/package.json index 9324e0b1e..f3b7bc093 100644 --- a/packages/block-editor-utils/package.json +++ b/packages/block-editor-utils/package.json @@ -38,6 +38,7 @@ "clean": "rimraf dist", "package": "node ../../scripts/package.js", "test": "", + "test:format": "prettier . --check", "build": "npm run build-esm && npm run build-cjs", "build-esm": "tsc -p .", "build-cjs": "tsc -p tsconfig.cjs.json", diff --git a/packages/faustwp-cli/package.json b/packages/faustwp-cli/package.json index e861c280f..3582417f3 100644 --- a/packages/faustwp-cli/package.json +++ b/packages/faustwp-cli/package.json @@ -42,6 +42,7 @@ "test": "jest", "test:coverage:ci": "jest --ci --json --coverage --testLocationInResults --passWithNoTests --outputFile=report.json", "test:coverage": "jest --coverage", + "test:format": "prettier . --check", "test:watch": "jest --watch" }, "repository": { diff --git a/packages/faustwp-core/package.json b/packages/faustwp-core/package.json index 409c2f190..278721a8f 100644 --- a/packages/faustwp-core/package.json +++ b/packages/faustwp-core/package.json @@ -62,6 +62,7 @@ "prepublish": "npm run build", "test:coverage:ci": "jest --ci --json --coverage --testLocationInResults --outputFile=report.json", "test:coverage": "jest --coverage", + "test:format": "prettier . --check", "test:watch": "jest --watch", "test": "jest", "build-cjs": "tsc -p tsconfig-cjs.json",