Skip to content

chore: auto npm publish on main#32

Merged
sreya merged 4 commits into
mainfrom
auto-npm-publish-on-main
Nov 16, 2025
Merged

chore: auto npm publish on main#32
sreya merged 4 commits into
mainfrom
auto-npm-publish-on-main

Conversation

@sreya
Copy link
Copy Markdown
Contributor

@sreya sreya commented Nov 16, 2025

No description provided.

- 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'
@sreya sreya merged commit 635101f into main Nov 16, 2025
6 checks passed
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.

1 participant