Skip to content

CD - Deploy Core Package to npm #10

CD - Deploy Core Package to npm

CD - Deploy Core Package to npm #10

name: "CD - Deploy Core Package to npm"
on:
workflow_dispatch:
inputs:
release_tag:
description: "Release tag (e.g., @common-grants/core@0.2.0)"
required: true
type: string
previous_tag:
description: "Previous tag (e.g., @common-grants/core@0.1.0) - optional"
required: false
type: string
dry_run:
description: "Dry run mode (default: false) - set to true to preview the release notes"
required: false
type: boolean
default: false
jobs:
create-release-from-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate tags and generate release notes
id: release-notes
run: |
DRY_RUN_FLAG=""
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
DRY_RUN_FLAG="--dry-run"
fi
.github/scripts/validate-and-generate-release-notes.sh \
--prefix "@common-grants/core@" \
--config-file ".github/release-config/lib-core.yml" \
--release-tag "${{ github.event.inputs.release_tag }}" \
--previous-tag "${{ github.event.inputs.previous_tag }}" \
--repository "${{ github.repository }}" \
$DRY_RUN_FLAG
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release
if: github.event.inputs.dry_run != 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.release_tag }}
body: ${{ steps.release-notes.outputs.notes }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
needs: create-release-from-tag
if: github.event.inputs.dry_run != 'true'
runs-on: ubuntu-latest
environment:
name: npm-core
url: https://www.npmjs.com/package/@common-grants/core
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: ./lib/core
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.release_tag }}
# Setup .npmrc file to publish to npm
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: https://registry.npmjs.org
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.3
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run checks
run: pnpm --filter @common-grants/core run checks
- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm publish --access public --no-git-checks
- name: Notify completion
run: |
echo "Core package deployed to npm"
echo "Tag: ${{ github.event.inputs.release_tag }}"