Skip to content

Publish Package

Publish Package #18

Workflow file for this run

name: Publish Package
on:
workflow_dispatch:
inputs:
version:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
- prepatch
- preminor
- premajor
- prerelease
custom_version:
description: "Custom version (optional, overrides version type)"
required: false
type: string
dry_run:
description: "Dry run (do not actually publish)"
required: false
type: boolean
default: false
tag:
description: "NPM dist-tag"
required: false
type: choice
options:
- latest
- next
- beta
- alpha
default: "latest"
# Prevent concurrent publishes
concurrency:
group: publish-package
cancel-in-progress: false
permissions:
contents: write
id-token: write
env:
NPM_CONFIG_FUND: false
jobs:
# Build and version the package
build:
name: Build & Version
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
cache: "npm"
cache-dependency-path: package-lock.json
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Version package
id: bump
run: |
CUSTOM_VERSION="${{ github.event.inputs.custom_version }}"
VERSION_TYPE="${{ github.event.inputs.version }}"
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
if [ -n "$CUSTOM_VERSION" ]; then
echo "Setting version to custom value: $CUSTOM_VERSION"
npm version "$CUSTOM_VERSION" --no-git-tag-version --allow-same-version
else
echo "Bumping version: $VERSION_TYPE"
npm version "$VERSION_TYPE" --no-git-tag-version --preid=beta
fi
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Build
run: npm run build
- name: Run tests
run: npm run test:run
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output
path: |
package.json
package-lock.json
dist/
retention-days: 1
# Publish to npm
publish:
name: Publish to NPM
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
registry-url: "https://registry.npmjs.org"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Update npm for OIDC support
run: npm install -g npm@latest
- name: Dry run check
if: github.event.inputs.dry_run == 'true'
run: |
echo "Dry run - would publish @agent-workforce/trajectories@${{ needs.build.outputs.new_version }}"
npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts
- name: Publish to NPM
if: github.event.inputs.dry_run != 'true'
run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts
# Create git tag and release
create-release:
name: Create Release
needs: [build, publish]
runs-on: ubuntu-latest
if: github.event.inputs.dry_run != 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
path: .
- name: Setup Node.js for changelog
uses: actions/setup-node@v4
with:
node-version: "22.14.0"
- name: Generate changelog
run: |
npx --yes conventional-changelog-cli -p angular -i CHANGELOG.md -s
echo "Changelog updated for v${{ needs.build.outputs.new_version }}"
- name: Commit and tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
NEW_VERSION="${{ needs.build.outputs.new_version }}"
git add package.json package-lock.json CHANGELOG.md
if ! git diff --staged --quiet; then
git commit -m "chore(release): v${NEW_VERSION}"
git push origin HEAD:main
fi
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
git push origin "v${NEW_VERSION}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build.outputs.new_version }}
name: v${{ needs.build.outputs.new_version }}
body: |
## @agent-workforce/trajectories v${{ needs.build.outputs.new_version }}
### Installation
```bash
npm install @agent-workforce/trajectories@${{ needs.build.outputs.new_version }}
```
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Summary
summary:
name: Summary
needs: [build, publish, create-release]
runs-on: ubuntu-latest
if: always()
steps:
- name: Summary
run: |
echo "## NPM Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version**: \`${{ needs.build.outputs.new_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**NPM Tag**: \`${{ github.event.inputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Dry Run**: \`${{ github.event.inputs.dry_run }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Results" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Build | ${{ needs.build.result == 'success' && '✅' || '❌' }} ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Publish | ${{ needs.publish.result == 'success' && '✅' || '❌' }} ${{ needs.publish.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Create Release | ${{ needs.create-release.result == 'success' && '✅' || (needs.create-release.result == 'skipped' && '⏭️' || '❌') }} ${{ needs.create-release.result }} |" >> $GITHUB_STEP_SUMMARY