Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Prerelease Snapshot (Alpha/Beta)

on:
push:
branches:
- prerelase # ← change to your branch name, or use '**' carefully
# - 'feature/**' # optional: also run on feature branches
workflow_dispatch:
inputs:
channel:
description: "npm dist-tag to publish to (alpha, beta, next, ...)"
required: true
default: "alpha"
snapshot_suffix:
description: "Optional custom suffix (defaults to short commit sha)"
required: false
description:
description: "Short description of this prerelease (used in commit message)"
required: false

jobs:
snapshot:
name: Build → Snapshot Version → Publish Prerelease
runs-on: ubuntu-latest
permissions:
contents: write # needed to commit version bump + tag (if any)
pull-requests: write # optional, if you want to comment on PRs

steps:
- name: ⬇️ Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # full history needed for changeset snapshot

- name: ⚙️ Setup pnpm
uses: pnpm/action-setup@v4

- name: 🟢 Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile

# Optional: build your packages if needed before publish
- name: 🛠 Build
run: pnpm build # ← adjust to your build script

- name: 🔖 Create & Publish Snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
SUFFIX="${{ inputs.snapshot_suffix || github.sha }}"
SUFFIX_SHORT=$(echo $SUFFIX | cut -c1-8)

TAG="${{ inputs.channel || 'alpha' }}"

# Optional: nice commit message with description
MSG="chore: snapshot prerelease ${{ inputs.description && format('({0})', inputs.description) || '' }} [ci skip]"

# Run snapshot version + publish in one go
# --snapshot=VALUE → custom suffix (commit-sha, timestamp, custom string, etc.)
pnpm exec changeset version --snapshot=$SUFFIX_SHORT
git add .
git commit -m "$MSG" || echo "No changes to commit (already up-to-date?)"
git push origin HEAD --follow-tags || true

# Publish to npm with the tag, no permanent git tags
pnpm exec changeset publish --tag $TAG --no-git-tag

- name: 📝 Optional – Create summary / comment
if: always()
run: |
echo "📦 Published snapshot to npm @ ${{ inputs.channel || 'alpha' }}"
echo "Version suffix used: ${{ inputs.snapshot_suffix || github.sha }}"
if [ -n "${{ inputs.description }}" ]; then
echo "Description: ${{ inputs.description }}"
fi
shell: bash
44 changes: 44 additions & 0 deletions docs/prerelease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Prerelease workflow

## Overview

This repository includes a manual GitHub Actions workflow to create prereleases (alpha/beta) of packages using Changesets and pnpm. The workflow is at `.github/workflows/prerelease.yml` and is triggered via `workflow_dispatch` with two inputs: `channel` and `publish`.

## How to trigger from GitHub

- Open the repository on GitHub, go to the **Actions** tab and select the **Prerelease** workflow.
- Click **Run workflow** and set the inputs:
- `channel`: `alpha` or `beta` (dist-tag used when publishing)
- `publish`: `true` to publish to npm, `false` to only run changesets and create PRs

## Required secrets

- `NPM_TOKEN` — token with publish access for npm
- `SLACK_WEBHOOK_URL` — optional, used by the repo's Slack notify action

## Run locally (build / publish with tag)

To run the local build step used by the workflow:

```bash
pnpm install --frozen-lockfile
pnpm build
```

To publish a prerelease locally (passes `--tag` through to the release script):

```bash
pnpm release -- --tag alpha
# or for beta
pnpm release -- --tag beta
```

## Notes

- The repo `package.json` defines `release` as `turbo run build && changeset publish`. Passing `-- --tag <tag>` forwards the extra args to the npm script which in turn is received by `changeset publish`.
- If you only want to test the workflow behavior without publishing, run the workflow with `publish` set to `false` from GitHub.

## Troubleshooting

- If publishing fails, confirm `NPM_TOKEN` is set and has correct permissions.
- Ensure you pushed all changesets and that `fetch-depth: 0` is present in the checkout step (the prerelease workflow already includes this).