Skip to content

fix(gha): make up the mind about jobs #28

fix(gha): make up the mind about jobs

fix(gha): make up the mind about jobs #28

Workflow file for this run

name: CI - Node.js
on:
push:
branches:
- "main"
- "prod-**"
pull_request:
branches:
- "main"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.workflow_run.head_branch || github.ref }}
cancel-in-progress: ${{ !contains(github.ref, 'main') && !contains(github.ref, 'prod-') }}
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [22]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Check number of lockfiles
run: |
if [ $(find . -name 'package-lock.json' | grep -vc -e 'node_modules') -gt 0 ]
then
echo -e 'Error: found package-lock files in the repository.\nWe use pnpm workspaces to manage packages so all dependencies should be added via pnpm add'
exit 1
fi
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
id: pnpm-install
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Check formatting
run: |
pnpm format:check || [ $? -eq 1 ] && printf "\nTip: Run 'pnpm run format' in your terminal to fix this.\n\n"
- name: Lint
run: pnpm lint
test:
name: Test
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node-version: [22]
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
id: pnpm-install
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install Dependencies
run: |
pnpm install
pnpm fetch-data
- name: Run Tests
run: pnpm test
build:
name: Build
needs: [lint, test]
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [22]
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
id: pnpm-install
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install and Build
run: |
pnpm install
pnpm fetch-data
pnpm build
- name: Upload build artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: dist
path: packages/server/dist
retention-days: 7
test-coverage:
name: Test Coverage
needs: [lint, test]
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [22]
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
id: pnpm-install
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install Dependencies
run: |
pnpm install
pnpm fetch-data
- name: Run tests with coverage
run: pnpm test:coverage
env:
CI: true
- name: Generate coverage summary
if: always()
run: |
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Extract coverage summary from packages/server
if [ -f packages/server/coverage/coverage-summary.json ]; then
node -e "
const fs = require('fs');
const coverage = JSON.parse(fs.readFileSync('packages/server/coverage/coverage-summary.json', 'utf8'));
const total = coverage.total;
const formatPercent = (pct) => {
const color = pct >= 90 ? '🟢' : pct >= 80 ? '🟡' : '🔴';
return \`\${color} \${pct.toFixed(2)}%\`;
};
console.log('Coverage Summary:');
console.log('');
console.log('Statements :', formatPercent(total.statements.pct));
console.log('Branches :', formatPercent(total.branches.pct));
console.log('Functions :', formatPercent(total.functions.pct));
console.log('Lines :', formatPercent(total.lines.pct));
console.log('');
console.log('Files tested:', Object.keys(coverage).length - 1);
" >> $GITHUB_STEP_SUMMARY
else
echo "Coverage report not found" >> $GITHUB_STEP_SUMMARY
fi
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Upload coverage reports
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
if: always()
with:
files: ./packages/server/coverage/coverage-final.json
flags: unittests
name: codecov-curriculum-db