Files
hugo-extended/.github/workflows/test.yml
T
2026-06-21 16:51:33 -04:00

232 lines
6.3 KiB
YAML

name: Tests
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
jobs:
unit:
name: Unit Tests (Node ${{ matrix.node }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: ${{ matrix.node }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Type check
run: npm run check-types
- name: Build
run: npm run build
- name: Run unit tests
run: npm run test:unit
integration:
name: Integration (${{ matrix.os }}, Node ${{ matrix.node }})
needs: unit
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [22, 24, 26]
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: ${{ matrix.node }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Generate current platform binary package
run: npm run generate-packages -- --set-github-env
- name: Build
run: npm run build
- name: Run integration tests
run: npm run test:integration
e2e:
name: E2E Binary Package (${{ matrix.os }})
needs: unit
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Generate current platform binary package
run: npm run generate-packages -- --set-github-env
- name: Build
run: npm run build
- name: Run E2E tests
run: npm run test:e2e
package-resolution:
name: Package Resolution (${{ matrix.os }})
needs: unit
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Generate current platform binary package
run: npm run generate-packages
- name: Install generated binary package
shell: bash
run: |
case "${RUNNER_OS}-${RUNNER_ARCH}" in
Linux-X64)
package_dir="./dist-platforms/hugo-extended-linux-amd64"
;;
Linux-ARM64)
package_dir="./dist-platforms/hugo-extended-linux-arm64"
;;
macOS-X64|macOS-ARM64)
package_dir="./dist-platforms/hugo-extended-darwin-universal"
;;
Windows-X64)
package_dir="./dist-platforms/hugo-extended-windows-amd64"
;;
Windows-ARM64)
package_dir="./dist-platforms/hugo-windows-arm64"
;;
*)
echo "::error::No binary package mapping for ${RUNNER_OS}/${RUNNER_ARCH}"
exit 1
;;
esac
if [[ ! -d "$package_dir" ]]; then
echo "::error::Expected generated binary package at $package_dir"
find dist-platforms -mindepth 1 -maxdepth 1 -type d -print
exit 1
fi
npm install --no-save --package-lock=false "$package_dir"
- name: Build
run: npm run build
- name: Verify package-resolved Hugo
run: |
node -e "
Promise.all([import('./dist/hugo.mjs'), import('node:fs')]).then(async ([m, fs]) => {
const expected = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
const bin = await m.default();
console.log(bin);
const { stdout } = await m.execWithOutput('version');
const versionOutput = stdout.trim();
console.log(versionOutput);
const match = versionOutput.match(/\bv([0-9]+\.[0-9]+\.[0-9]+)/);
const actual = match ? match[1] : null;
if (actual !== expected) {
throw new Error('Expected Hugo v' + expected + ', got ' + (actual || 'unparseable version') + ' from: ' + versionOutput);
}
}).catch((error) => {
console.error(error);
process.exit(1);
});
"
pack:
name: Pack Dry Run
needs: unit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 24
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Generate current platform binary package
run: npm run generate-packages
- name: Root package dry run
run: npm pack --dry-run
- name: Binary package dry run
shell: bash
run: |
package_dir="./dist-platforms/hugo-extended-linux-amd64"
if [[ ! -d "$package_dir" ]]; then
echo "::error::Expected generated binary package at $package_dir"
find dist-platforms -mindepth 1 -maxdepth 1 -type d -print
exit 1
fi
npm pack --dry-run "$package_dir"