Skip to content

Commit 27852f2

Browse files
authored
feat(repo): add Changesets with Trusted Publishing for automated releases (#27)
1 parent d380516 commit 27852f2

7 files changed

Lines changed: 768 additions & 11 deletions

File tree

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/CI.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Continuous Integration
1+
# Continuous Integration & Release
22

33
## Overview
4-
This project uses GitHub Actions for continuous integration. The CI workflow runs automatically on all pull requests and pushes to the `main` branch.
4+
This project uses GitHub Actions for continuous integration and automated releases. Workflows run automatically on all pull requests and pushes to the `main` branch.
55

66
## CI Workflow
77
The CI workflow (`.github/workflows/ci.yml`) runs the following checks in sequence:
@@ -58,6 +58,64 @@ The `main` branch is protected and requires:
5858
- Pull request reviews (if configured)
5959
- Branches to be up to date before merging
6060

61+
## Release Process
62+
63+
This project uses [Changesets](https://github.com/changesets/changesets) for automated versioning and publishing to npm.
64+
65+
### How It Works
66+
67+
1. **Create changes** - Make your code changes as usual
68+
2. **Add changeset** - Run `yarn changeset` to document the change
69+
3. **Open PR** - Create a pull request with your changes + changeset
70+
4. **PR merged** - After review, your PR is merged to main
71+
5. **Version PR created** - The release workflow automatically creates a "Version Packages" PR
72+
6. **Publish** - When the Version PR is merged, packages are published to npm
73+
74+
### For Contributors
75+
76+
When making user-facing changes, always create a changeset:
77+
78+
```bash
79+
yarn changeset
80+
```
81+
82+
Select the affected packages, choose the bump type (patch/minor/major), and describe your changes. This will be included in the changelog.
83+
84+
See [CONTRIBUTING.md](../CONTRIBUTING.md) for detailed instructions.
85+
86+
### For Maintainers
87+
88+
#### Normal Releases
89+
1. Review and merge PRs with changesets
90+
2. Review the auto-generated "Version Packages" PR
91+
3. Merge the Version PR to trigger publishing
92+
93+
#### Dry Run Testing
94+
To test the release process without publishing:
95+
96+
```bash
97+
# Trigger the release workflow manually
98+
# Go to Actions → Release → Run workflow
99+
# Select "dry_run: true"
100+
```
101+
102+
#### NPM Trusted Publishing Setup
103+
This project uses NPM's Trusted Publishing (OIDC) for secure, token-free publishing:
104+
105+
**One-time setup on NPM:**
106+
1. Go to each package's settings on npmjs.com
107+
2. Configure Trusted Publisher:
108+
- Publisher: GitHub Actions
109+
- Repository: `lytics/lytics-lab`
110+
- Workflow: `release.yml`
111+
- Environment: `production`
112+
3. Set publishing access to "Require 2FA and disallow tokens" for maximum security
113+
114+
**GitHub Environment:**
115+
The `production` environment must exist in repository settings (Settings → Environments).
116+
117+
No NPM tokens required! Authentication happens automatically via OIDC.
118+
61119
## Adding New Checks
62120
To add additional CI checks, edit `.github/workflows/ci.yml` and add new steps under the `steps` section.
63121

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
dry_run:
10+
description: "Run in dry-run mode (no actual publishing)"
11+
required: false
12+
default: "false"
13+
type: choice
14+
options:
15+
- "true"
16+
- "false"
17+
18+
concurrency: ${{ github.workflow }}-${{ github.ref }}
19+
20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
id-token: write
24+
25+
jobs:
26+
release:
27+
name: Release
28+
runs-on: ubuntu-latest
29+
environment: production
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: "22.20.0"
38+
cache: "yarn"
39+
registry-url: "https://registry.npmjs.org"
40+
41+
- name: Install dependencies
42+
run: yarn install --frozen-lockfile
43+
44+
- name: Setup Nx cache
45+
uses: actions/cache@v3
46+
with:
47+
path: .nx/cache
48+
key: ${{ runner.os }}-nx-${{ hashFiles('**/yarn.lock') }}
49+
restore-keys: |
50+
${{ runner.os }}-nx-
51+
52+
- name: Create Release Pull Request or Publish to npm
53+
id: changesets
54+
uses: changesets/action@v1
55+
with:
56+
publish: yarn release
57+
version: yarn version-packages
58+
commit: "chore: version packages"
59+
title: "chore: version packages"
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
NPM_CONFIG_PROVENANCE: true
63+
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
64+
65+
- name: Publish Summary
66+
if: steps.changesets.outputs.published == 'true'
67+
run: |
68+
echo "### 📦 Published Packages" >> $GITHUB_STEP_SUMMARY
69+
echo "" >> $GITHUB_STEP_SUMMARY
70+
echo "${{ steps.changesets.outputs.publishedPackages }}" | jq -r '.[] | "- \(.name)@\(.version)"' >> $GITHUB_STEP_SUMMARY

CONTRIBUTING.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Contributing to Lytics Lab
2+
3+
Thank you for contributing to Lytics Lab! This guide will help you get started.
4+
5+
## Development Setup
6+
7+
### Prerequisites
8+
9+
- Node.js 22.20.0 (managed via Volta)
10+
- Yarn 1.22.18
11+
12+
### Getting Started
13+
14+
```bash
15+
# Clone the repository
16+
git clone https://github.com/lytics/lytics-lab.git
17+
cd lytics-lab
18+
19+
# Install dependencies
20+
yarn install
21+
22+
# Run tests
23+
yarn test
24+
25+
# Run linting
26+
yarn lint
27+
28+
# Type check
29+
yarn typecheck
30+
31+
# Build all packages
32+
yarn build
33+
```
34+
35+
## Making Changes
36+
37+
### 1. Create a Branch
38+
39+
```bash
40+
git checkout -b issue/[number]-[description]
41+
```
42+
43+
### 2. Make Your Changes
44+
45+
- Write clear, concise code
46+
- Add tests for new features
47+
- Update documentation as needed
48+
- Follow the existing code style (enforced by Biome)
49+
50+
### 3. Run Quality Checks
51+
52+
```bash
53+
# Run all checks locally before pushing
54+
yarn lint
55+
yarn typecheck
56+
yarn test
57+
yarn build
58+
```
59+
60+
## Changesets Workflow
61+
62+
We use [Changesets](https://github.com/changesets/changesets) for versioning and publishing. This ensures clear changelogs and semantic versioning.
63+
64+
### Creating a Changeset
65+
66+
When you make changes that should be released, create a changeset:
67+
68+
```bash
69+
yarn changeset
70+
```
71+
72+
This will prompt you to:
73+
74+
1. **Select packages** - Which packages did you change?
75+
2. **Select bump type** - What type of change is this?
76+
- **patch** (1.0.0 → 1.0.1) - Bug fixes, minor changes
77+
- **minor** (1.0.0 → 1.1.0) - New features, backwards compatible
78+
- **major** (1.0.0 → 2.0.0) - Breaking changes
79+
3. **Write a summary** - Describe your changes (will appear in CHANGELOG)
80+
81+
This creates a markdown file in `.changeset/` that will be committed with your PR.
82+
83+
### Example Workflow
84+
85+
```bash
86+
# 1. Make your changes
87+
git checkout -b feat/add-new-feature
88+
89+
# 2. Create a changeset
90+
yarn changeset
91+
# Select: experience-editor
92+
# Choose: minor
93+
# Summary: "Add support for custom themes"
94+
95+
# 3. Commit everything together
96+
git add .
97+
git commit -m "feat(experience-editor): add custom theme support"
98+
git push origin feat/add-new-feature
99+
100+
# 4. Open a PR
101+
```
102+
103+
### What Happens Next?
104+
105+
1. **Your PR is reviewed** - Maintainers review your code and changeset
106+
2. **PR is merged** - Your changeset is merged to main
107+
3. **Version PR is created** - A bot creates a "Version Packages" PR with:
108+
- Updated package versions
109+
- Updated CHANGELOGs
110+
- All pending changesets combined
111+
4. **Maintainer merges Version PR** - Packages are automatically published to npm
112+
113+
### Changeset Guidelines
114+
115+
**Do create a changeset when:**
116+
117+
- Adding features
118+
- Fixing bugs
119+
- Making breaking changes
120+
- Updating dependencies that affect users
121+
122+
**Don't create a changeset for:**
123+
124+
- Documentation updates
125+
- Internal refactors (no API changes)
126+
- CI/build configuration changes
127+
- Development dependencies
128+
129+
## Commit Message Convention
130+
131+
We use [Conventional Commits](https://www.conventionalcommits.org/):
132+
133+
```
134+
<type>(<scope>): <subject>
135+
136+
<body>
137+
```
138+
139+
### Types
140+
141+
- `feat` - New feature
142+
- `bug` - Bug fix
143+
- `maint` - Maintenance/refactoring
144+
145+
### Scopes
146+
147+
- `experience-editor` - Changes to experience-editor package
148+
- `recommendation-block` - Changes to recommendation-block package
149+
- `repo` - Repository-level changes
150+
- `ci` - CI/CD changes
151+
- `deps` - Dependency updates
152+
- `docs` - Documentation
153+
- `tests` - Test changes
154+
155+
### Examples
156+
157+
```
158+
feat(experience-editor): add date range display condition
159+
160+
bug(recommendation-block): fix API timeout issue
161+
162+
maint(repo): upgrade to Biome 2.0
163+
```
164+
165+
## Pull Request Process
166+
167+
1. **Create a clear PR title** - Following conventional commit format
168+
2. **Include changeset** - Add changeset if user-facing changes
169+
3. **Fill out PR template** - Provide context and testing notes
170+
4. **Wait for CI** - All checks must pass
171+
5. **Address feedback** - Respond to review comments
172+
6. **Squash and merge** - Maintainers will merge when ready
173+
174+
## Testing
175+
176+
### Running Tests
177+
178+
```bash
179+
# Run all tests
180+
yarn test
181+
182+
# Run tests in watch mode
183+
yarn test:watch
184+
185+
# Run tests with coverage
186+
yarn cover
187+
188+
# Run tests for specific package
189+
cd packages/experience-editor
190+
yarn test
191+
```
192+
193+
### Writing Tests
194+
195+
- Place tests in `__tests__` folders
196+
- Use descriptive test names
197+
- Follow existing patterns
198+
- Aim for good coverage of new code
199+
200+
## Code Style
201+
202+
We use [Biome](https://biomejs.dev/) for linting and formatting:
203+
204+
```bash
205+
# Check for issues
206+
yarn lint
207+
208+
# Auto-fix issues
209+
yarn lint:fix
210+
211+
# Format code
212+
yarn format
213+
```
214+
215+
Your editor should auto-format on save if configured properly.
216+
217+
## Need Help?
218+
219+
- **Questions?** Open an issue with the "question" label
220+
- **Bug?** Open an issue with the "bug" label
221+
- **Feature idea?** Open an issue with the "enhancement" label
222+
223+
## License
224+
225+
By contributing, you agree that your contributions will be licensed under the project's license.

0 commit comments

Comments
 (0)