Skip to content

Publish Package

Publish Package #12

Workflow file for this run

name: Publish Package
on:
workflow_dispatch:
inputs:
triggered-by:
description: "What triggered this workflow"
required: false
type: string
default: "manual"
dep-map-artifact:
description: "Artifact name containing the dependency map JSON"
required: false
type: string
default: ""
source-repo:
description: "Source repository (owner/repo) that triggered this workflow"
required: false
type: string
default: ""
source-run-id:
description: "Source workflow run ID"
required: false
type: string
default: ""
pre-build-script:
description: "Custom script to run before build"
required: false
default: ""
type: string
additional-deps:
description: "Additional build dependencies to install"
required: false
default: ""
type: string
version-increment:
description: "Version increment type (patch, minor, major, prerelease)"
required: false
default: "patch"
type: string
node-version:
description: "Node.js version to use"
required: false
default: "24"
type: string
access:
description: "Package access level (public, restricted)"
required: false
default: "public"
type: string
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
registry-url: https://registry.npmjs.org/
- name: Download dep-map artifact
if: ${{ inputs.dep-map-artifact != '' && inputs.source-repo != '' && inputs.source-run-id != '' }}
id: download-dep-map
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const [owner, repo] = '${{ inputs.source-repo }}'.split('/');
const fs = require('fs');
// Download artifact
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: ${{ inputs.source-run-id }}
});
const artifact = artifacts.data.artifacts.find(a => a.name === '${{ inputs.dep-map-artifact }}');
if (!artifact) {
throw new Error(`Artifact ${{ inputs.dep-map-artifact }} not found`);
}
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip'
});
// Write and extract artifact
fs.writeFileSync('artifact.zip', Buffer.from(download.data));
await exec.exec('unzip', ['-o', 'artifact.zip']);
// Read the dep-map
const depMap = JSON.parse(fs.readFileSync('dep-map-' + '${{ inputs.dep-map-artifact }}'.split('-').pop() + '.json', 'utf8'));
console.log('📥 Downloaded dep-map from artifact:', depMap);
// Output as JSON string
core.setOutput('dep-map', JSON.stringify(depMap));
- name: Update dependencies
if: ${{ inputs.dep-map-artifact != '' }}
uses: arcmantle/github-actions/replace-deps@main
with:
dep-map: ${{ steps.download-dep-map.outputs.dep-map }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18
- name: Run pre-build script
if: ${{ inputs.pre-build-script != '' }}
run: ${{ inputs.pre-build-script }}
- name: Install common build dependencies.
run: pnpm add -D rimraf typescript @arcmantle/tsconfig @types/node ${{ inputs.additional-deps }}
- name: Install dependencies.
run: pnpm install
- name: Build project.
run: pnpm build
- name: Calculate version with Prospector
id: version
run: |
echo "🔍 Using Prospector to calculate version..."
VERSION=$(node bin/bin.js)
echo "📦 Calculated version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
PACKAGE_NAME=$(node -p "require('./package.json').name")
echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT
- name: Set package version
run: |
echo "✅ Setting package version to ${{ steps.version.outputs.version }}"
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
echo "📦 Package ${{ steps.version.outputs.package }} ready to publish"
#- name: Publish to NPM
# run: pnpm publish --access ${{ inputs.access }} --no-git-checks
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH }}
# NPM_TOKEN: ${{ secrets.NPM_PUBLISH }}
#uses: arcmantle/github-workflows/.github/workflows/pnpm-publish.yml@main
#with:
# triggered-by: ${{ inputs.triggered-by }}
# dep-map: ${{ inputs.dep-map }}
# pre-build-script: ${{ inputs.pre-build-script }}
# additional-deps: ${{ inputs.additional-deps }}
# version-increment: ${{ inputs.version-increment }}
# node-version: ${{ inputs.node-version }}
# access: ${{ inputs.access }}
#secrets:
# NPM_PUBLISH: ${{ secrets.NPM_PUBLISH }}