Skip to content

Publish to NPM

Publish to NPM #119

Workflow file for this run

name: Publish to NPM
on:
push:
tags:
- 'v*'
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version to publish (optional)'
required: false
default: ''
jobs:
publish:
name: Publish to NPM
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: arkstack_dev
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/arkstack_dev?schema=public
NODE_ENV: test
NODE_CI: true
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout publish branch
if: github.event_name == 'release' || github.ref_type == 'tag'
shell: bash
run: |
TARGET_BRANCH="${{ github.event.release.target_commitish || github.event.repository.default_branch }}"
if [[ -z "$TARGET_BRANCH" || "$TARGET_BRANCH" == refs/tags/* || "$TARGET_BRANCH" =~ ^[0-9a-f]{40}$ ]]; then
TARGET_BRANCH="${{ github.event.repository.default_branch }}"
fi
git fetch origin "$TARGET_BRANCH"
git checkout "$TARGET_BRANCH"
- name: Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10
cache: true
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
scope: '@arkstack'
- name: Configure NPM auth
shell: bash
run: |
if [[ -z "$NODE_AUTH_TOKEN" ]]; then
echo "NPM_TOKEN secret is not configured." >&2
exit 1
fi
npm config set //registry.npmjs.org/:_authToken "$NODE_AUTH_TOKEN"
npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Resolve release version
id: release_version
shell: bash
run: |
VERSION="${{ github.event.inputs.version || github.event.release.tag_name || github.ref_name }}"
VERSION="${VERSION#v}"
if [[ -z "$VERSION" ]]; then
echo "Unable to resolve a release version. Provide workflow_dispatch input 'version' or run from a release/tag." >&2
exit 1
fi
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid semver version: $VERSION" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Set package versions
run: pnpm prepare:release-version ${{ steps.release_version.outputs.version }}
- name: Prepare Template Arkstack TSConfig
run: |
for template in templates/*; do
mkdir -p "$template/.arkstack"
printf '{"compilerOptions":{"module":"es2022"}}\n' > "$template/.arkstack/tsconfig.json"
done
- name: Build Templates
run: pnpm -w run build:templates
- name: Rebuild Console
run: |
pnpm --filter @arkstack/console run build
pnpm install --frozen-lockfile
- name: Prepare Templates
run: |
cd templates/express && pnpm prepare
cd ../h3 && pnpm prepare
- name: Run linter
run: pnpm lint
- name: Build Create Arkstack
run: |
cd create-arkstack
pnpm run build
- name: Run database migrations
run: pnpm arkorm migrate:fresh;
- name: Run tests
run: pnpm test
- name: Commit release version changes
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
if git diff --cached --quiet; then
echo "Release version files are already up to date."
exit 0
fi
git commit -m "chore: prepare release v${{ steps.release_version.outputs.version }}"
git push
- name: Publish to NPM
run: pnpm publish:packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish summary
if: steps.release_version.outputs.version
run: |
PACKAGE_COUNT=$(ls -d packages/*/ | wc -l | tr -d ' ')
echo "## Publish Report" >> $GITHUB_STEP_SUMMARY
echo "### Summary" >> $GITHUB_STEP_SUMMARY
echo "* **Version**: ✅ ${{ steps.release_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "* **Packages**: ✅ $PACKAGE_COUNT" >> $GITHUB_STEP_SUMMARY