chore: auto npm publish on main#32
Merged
Merged
Conversation
- Add trigger for main branch pushes (in addition to tags)
- Generate pre-release versions for main branch: {base}-next.{n}.g{hash}
- Use 'next' NPM tag for pre-releases, 'latest' for stable releases
- Add version existence check for idempotent publishing
- Skip if pre-release already exists (safe for CI re-runs)
- Update dist-tag only if stable release already exists
- Preserve existing tag validation and CI checks
Example versions:
- Main branch: 0.1.1-next.6.g9816568 (tagged as 'next')
- Tag v0.1.2: 0.1.2 (tagged as 'latest')
Follows cmux workflow pattern for automated pre-release publishing.
- Create .github/actions/npm-publish for reusable publish logic - CI workflow now publishes pre-releases after all checks pass on main - Publish workflow simplified to just run checks + call action for tags - Publishing only happens after fmt, lint, typecheck, test, build succeed Benefits: - DRY: Single source of truth for version generation and publishing - Safe: Pre-releases only published after all CI checks pass - Clear: Separate concerns (CI checks vs publishing) - Consistent: Same publish logic for both main and tags Workflows: - Push to main → CI runs all checks → publishes 'next' tag (if checks pass) - Push tag → Publish runs all checks → publishes 'latest' tag (if checks pass) - Pull requests → CI runs all checks → no publishing
The action now automatically detects whether it's publishing a stable release (from tag) or pre-release (from main) by checking $GITHUB_REF. Benefits: - No flimsy boolean flag to pass around - Action is self-contained and context-aware - Less error-prone (can't pass wrong flag) - Cleaner workflow files (no inputs needed) - Better logging (shows trigger source) The action inspects $GITHUB_REF: - refs/tags/* → stable release (latest tag) - refs/heads/main → pre-release (next tag)
Moved trigger detection into its own step for better separation of concerns.
Benefits:
- Single Responsibility: Detection logic isolated from version generation
- Clear outputs: is_tag, trigger_type, trigger_name
- Easier to test and debug
- Other steps can reference ${{ steps.detect.outputs.is_tag }}
- Better GitHub Actions UI (shows detection as separate step)
The detect step runs first and outputs:
- is_tag: 'true' or 'false'
- trigger_type: 'tag' or 'branch'
- trigger_name: e.g. 'v0.1.1' or 'main'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.