Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 16, 2025

This PR implements a comprehensive GitHub Actions workflow system that automatically publishes packages to both npmjs.com and GitHub Packages using Changesets for version management, addressing the need for reliable dual-registry publishing with proper safeguards and explicit version control.

Key Features

🔄 Dual Registry Publishing

  • Automatically publishes to npmjs.com with public access and provenance
  • Simultaneously publishes to GitHub Packages using existing configuration
  • Smart publishConfig handling to switch between registries seamlessly

📦 Changeset Integration

  • Uses Changesets for explicit version management and changelog generation
  • Automated release workflow that creates version PRs when changesets exist
  • Publishes to both registries when version PRs are merged
  • Manual version management workflow for controlled version bumping

🛡️ Robust Safeguards

  • Version conflict detection - skips npm publishing if version already exists
  • Retry logic with exponential backoff (3 attempts) for transient failures
  • Build fallback system - continues with esbuild-only if TypeScript compilation fails
  • Comprehensive artifact verification before publishing

🔒 Security & Compliance

  • npm provenance enabled for supply chain security
  • Minimal required permissions (contents: read, packages: write, id-token: write)
  • Environment protection for npm-publish operations
  • No credential exposure in logs

🧪 Testing & Validation

  • Dry-run support via manual workflow dispatch
  • Local test script (test-publish-workflow.sh) to validate workflow steps
  • YAML syntax validation and comprehensive error handling
  • Detailed logging and GitHub Actions summaries

Changeset Workflow

The new changeset-based workflow provides better control over versioning compared to Lerna's conventional commits:

  1. Create Changes: Make code changes as usual
  2. Add Changeset: Run npm run changeset to specify version bump type and changelog
  3. Commit & Push: Push changes including changeset files to main branch
  4. Automated Release: GitHub Actions creates a "Version Packages" PR automatically
  5. Publish: Merge the version PR to publish to both npm registries

Usage

Primary Changeset Workflow

# Make your changes
npm run changeset          # Create changeset
git add . && git commit -m "feat: your changes"
git push origin main       # Triggers version PR creation
# Merge the "Version Packages" PR to publish

Legacy Release Workflow

# Manual trigger with dry-run
gh workflow run publish.yml --input dry_run=true

# Or use the test script locally
./test-publish-workflow.sh

Implementation Details

The workflow handles existing TypeScript build issues gracefully - when npm run build fails due to type definition conflicts, it falls back to the esbuild-only build process that generates the required CommonJS and ESM bundles. This ensures publishing can proceed even with compilation errors.

Repository secrets required:

  • NPM_TOKEN: NPM automation token for npmjs.com publishing
  • GITHUB_TOKEN: Automatically provided for GitHub Packages

Complete documentation is included at .github/PUBLISH_WORKFLOW.md and .changeset/USAGE.md with setup instructions, troubleshooting, and maintenance guidelines.

Fixes #38.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] req(github): Introduce a GitHub Action to publish to both npmjs.com and GitHub Packages feat: Add GitHub Actions workflow for dual registry publishing Aug 16, 2025
Copilot AI requested a review from lxcid August 16, 2025 15:33
Copilot finished work on behalf of lxcid August 16, 2025 15:33
Copy link
Collaborator

@lxcid lxcid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add changeset support for version bumping?

Copy link
Contributor Author

Copilot AI commented Aug 17, 2025

@copilot add changeset support for version bumping?

Added changeset support with commit eadacfb. The implementation includes:

  • Changesets configuration for automated version management
  • New release workflow that creates version PRs when changesets exist
  • Publishing to both npmjs.com and GitHub Packages when version PRs are merged
  • Manual version management workflow for controlled bumping
  • Updated documentation and usage guides

Contributors can now run npm run changeset to specify version bumps, and the system will automatically handle releases when those changesets are merged to main.

Copilot AI changed the title feat: Add GitHub Actions workflow for dual registry publishing feat: Add GitHub Actions workflow for dual registry publishing with changeset support Aug 17, 2025
Copilot AI requested a review from lxcid August 17, 2025 04:48
Copilot finished work on behalf of lxcid August 17, 2025 04:48
Copy link
Collaborator

@lxcid lxcid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lxcid lxcid marked this pull request as ready for review August 17, 2025 04:58
@lxcid lxcid merged commit 47499cb into master Aug 17, 2025
2 checks passed
@lxcid lxcid deleted the copilot/fix-38 branch August 17, 2025 04:58
@github-actions github-actions bot mentioned this pull request Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

req(github): Introduce a GitHub Action to publish to both npmjs.com and GitHub Packages

2 participants