Skip to content

Publish @epubknowledge/common package #6

Publish @epubknowledge/common package

Publish @epubknowledge/common package #6

name: Publish @epubknowledge/common package
on:
release:
types:
- published
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: yarn install --frozen-lockfile
- name: Run Vitest and capture results
continue-on-error: true
run: yarn test --reporter=json --outputFile=.test-results.json
- name: Require 85% test pass rate
run: node .github/scripts/verify-test-pass-rate.mjs .test-results.json 85
- name: Build package
run: npm run build
- name: Pack release artifact
id: pack
run: |
npm pack --json > pack-output.json
filename=$(node -e "console.log(JSON.parse(require('fs').readFileSync('pack-output.json', 'utf8'))[0].filename)")
test -n "$filename"
test -f "$filename"
echo "filename=$filename" >> "$GITHUB_OUTPUT"
- name: Verify packed artifact output
run: |
test -n "${{ steps.pack.outputs.filename }}"
test -f "${{ steps.pack.outputs.filename }}"
- name: Verify packed dist assets
run: |
node -e "const pack = JSON.parse(require('fs').readFileSync('pack-output.json', 'utf8'))[0]; const files = pack.files.map(file => file.path); const hasJs = files.some(file => file.startsWith('dist/') && file.endsWith('.js')); const hasDts = files.some(file => file.startsWith('dist/') && file.endsWith('.d.ts')); if (!hasJs || !hasDts) { console.error('Packed tarball is missing compiled dist assets.'); process.exit(1); }"
- name: Consumer smoke test
run: |
tmp_dir="$(mktemp -d)"
npm init -y --prefix "$tmp_dir" >/dev/null
npm install --prefix "$tmp_dir" "$PWD/${{ steps.pack.outputs.filename }}" typescript
cat <<'EOF' > "$tmp_dir/runtime.mjs"
import { fileExists } from '@epubknowledge/common/file'
if (typeof fileExists !== 'function') {
throw new Error('Expected fileExists export to be a function.')
}
EOF
cat <<'EOF' > "$tmp_dir/types.mts"
import type { EpubObj } from '@epubknowledge/common/types'
const book: EpubObj | null = null
void book
EOF
cat <<'EOF' > "$tmp_dir/tsconfig.json"
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmit": true
},
"include": ["types.mts"]
}
EOF
node "$tmp_dir/runtime.mjs"
(cd "$tmp_dir" && ./node_modules/.bin/tsc -p tsconfig.json)
- name: Set up npm registry auth
uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
scope: '@epubknowledge'
- name: Publish to npm
run: npm publish "${{ steps.pack.outputs.filename }}" --access public
- name: Set up GitHub Packages auth
uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@epubknowledge'
- name: Publish to GitHub Packages
run: npm publish "${{ steps.pack.outputs.filename }}" --registry=https://npm.pkg.github.com
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}