Skip to content

Merge pull request #244 from woocommerce/upgrade/nodejs-v24-release-w… #22

Merge pull request #244 from woocommerce/upgrade/nodejs-v24-release-w…

Merge pull request #244 from woocommerce/upgrade/nodejs-v24-release-w… #22

name: GitHub Actions Self-Test
on:
push:
branches:
- trunk
paths:
- packages/github-actions/**
- .github/workflows/github-actions-self-test.yml
pull_request:
paths:
- packages/github-actions/**
- .github/workflows/github-actions-self-test.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
unit-test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Install dependencies
working-directory: packages/github-actions
run: npm ci --ignore-scripts
- name: Run unit tests
working-directory: packages/github-actions
run: npm test
build-check:
name: Build Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Install dependencies
working-directory: packages/github-actions
run: npm ci --ignore-scripts
- name: Verify build succeeds
working-directory: packages/github-actions
run: npm run build
test-prepare-node:
name: "prepare-node (Node ${{ matrix.node-version }}, deps: ${{ matrix.install-deps }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['24', '22', '20']
install-deps: ['yes', 'no']
ignore-scripts: ['yes']
include:
- node-version: '24'
install-deps: 'yes'
ignore-scripts: 'no'
steps:
- uses: actions/checkout@v6
- uses: ./packages/github-actions/actions/prepare-node
with:
node-version: ${{ matrix.node-version }}
install-deps: ${{ matrix.install-deps }}
ignore-scripts: ${{ matrix.ignore-scripts }}
- name: Verify Node.js major version
env:
EXPECTED_VERSION: ${{ matrix.node-version }}
run: |
ACTUAL=$(node --version | sed 's/^v//' | cut -d. -f1)
if [ "$ACTUAL" != "$EXPECTED_VERSION" ]; then
echo "Expected Node $EXPECTED_VERSION but got $ACTUAL"
exit 1
fi
# prepare-node runs `npm ci` from the workspace root, so the installed
# node_modules lives there. Pin the verification to the same directory.
- name: Verify node_modules exists
if: matrix.install-deps == 'yes'
working-directory: ${{ github.workspace }}
run: test -d node_modules
- name: Verify node_modules does not exist
if: matrix.install-deps == 'no'
working-directory: ${{ github.workspace }}
run: test ! -d node_modules
test-prepare-php:
name: "prepare-php (PHP ${{ matrix.php-version }}, deps: ${{ matrix.install-deps }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.2', '8.4']
install-deps: ['no']
include:
- php-version: '8.2'
install-deps: 'yes'
steps:
- uses: actions/checkout@v6
- name: Create minimal Composer project for install test
if: matrix.install-deps == 'yes'
run: |
# The repo's own project depends on the private woocommerce/woorelease
# repo, which composer cannot fetch here. Replace it with a minimal
# public dependency and drop the lock so the install test is isolated.
rm -f composer.lock
echo '{"require": {"psr/log": "^3.0"}}' > composer.json
- uses: ./packages/github-actions/actions/prepare-php
with:
php-version: ${{ matrix.php-version }}
install-deps: ${{ matrix.install-deps }}
- name: Verify PHP version
env:
EXPECTED_VERSION: ${{ matrix.php-version }}
run: |
ACTUAL=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
if [ "$ACTUAL" != "$EXPECTED_VERSION" ]; then
echo "Expected PHP $EXPECTED_VERSION but got $ACTUAL"
exit 1
fi
- name: Verify Composer is available
run: composer --version
- name: Verify vendor directory exists
if: matrix.install-deps == 'yes'
run: test -d vendor
test-prepare-mysql:
name: prepare-mysql
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./packages/github-actions/actions/prepare-mysql
- name: Verify MySQL connection
run: mysql -u root -proot -e "SELECT 1;"
test-eslint-formatter:
name: "eslint-annotation (eslint v${{ matrix.eslint-version }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
eslint-version: ['8', '9']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Build the formatter
working-directory: packages/github-actions
run: |
npm ci --ignore-scripts
npm run build
- name: Set up test environment
run: |
mkdir /tmp/formatter-test
cd /tmp/formatter-test
npm init -y
npm install eslint@${{ matrix.eslint-version }}
# Prepend eslint-disable to suppress linting on the formatter itself
echo '/* eslint-disable */' > eslintFormatter.cjs
cat "$GITHUB_WORKSPACE/packages/github-actions/actions/eslint-annotation/eslintFormatter.cjs" >> eslintFormatter.cjs
# Create a file with a known lint error
echo 'var unused = 1;' > sample.js
- name: Verify formatter produces annotation commands
working-directory: /tmp/formatter-test
run: |
MAJOR=$(./node_modules/.bin/eslint --version | cut -d. -f1 | tr -d 'v')
if [ "$MAJOR" -ge 9 ]; then
CONFIG_FLAG="--no-config-lookup"
else
CONFIG_FLAG="--no-eslintrc"
fi
OUTPUT=$(./node_modules/.bin/eslint sample.js $CONFIG_FLAG --rule 'no-unused-vars: error' --format ./eslintFormatter.cjs 2>&1 || true)
echo "$OUTPUT"
echo "$OUTPUT" | grep -qE '^::(error|warning) '
test-stylelint-formatter:
name: "stylelint-annotation (stylelint v${{ matrix.stylelint-version }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
stylelint-version: ['15', '16']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
- name: Build the formatter
working-directory: packages/github-actions
run: |
npm ci --ignore-scripts
npm run build
- name: Set up test environment
run: |
mkdir /tmp/formatter-test
cd /tmp/formatter-test
npm init -y
npm install stylelint@${{ matrix.stylelint-version }}
# Prepend eslint-disable to suppress linting on the stylelint formatter
echo '/* eslint-disable */' > stylelintFormatter.cjs
cat "$GITHUB_WORKSPACE/packages/github-actions/actions/stylelint-annotation/stylelintFormatter.cjs" >> stylelintFormatter.cjs
# Create a CSS file with a known lint error (duplicate property)
echo 'a { color: red; color: blue; }' > sample.css
echo '{"rules": {"declaration-block-no-duplicate-properties": true}}' > .stylelintrc.json
- name: Verify formatter produces annotation commands
working-directory: /tmp/formatter-test
run: |
OUTPUT=$(./node_modules/.bin/stylelint sample.css --custom-formatter ./stylelintFormatter.cjs 2>&1 || true)
echo "$OUTPUT"
echo "$OUTPUT" | grep -qE '^::(error|warning) '