@punkbit/demo-changeset-ci-workflow 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +215 -0
  2. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # @punkbit/demo-changeset-ci-workflow
2
+
3
+ A demo TypeScript package for showcasing the changeset-based CI/CD release workflow.
4
+
5
+ ## Overview
6
+
7
+ This package demonstrates how to use [Changesets](https://github.com/changesets/changesets) for version management and automated releases with GitHub Actions.
8
+
9
+ ## Features
10
+
11
+ - **Changeset-based versioning**: Track and manage changes incrementally
12
+ - **Automated releases**: Create release PRs and publish to NPM automatically
13
+ - **Pre-release support**: Support for rc, test, and latest release types
14
+ - **ESM only**: Modern ES module exports
15
+ - **OIDC trusted publishing**: Secure NPM publishing without long-lived tokens
16
+
17
+ ## Quick Start
18
+
19
+ ### Installation
20
+
21
+ ```bash
22
+ npm install @punkbit/demo-changeset-ci-workflow
23
+ ```
24
+
25
+ ### Usage
26
+
27
+ ```typescript
28
+ import { greet, getVersion } from '@punkbit/demo-changeset-ci-workflow';
29
+
30
+ console.log(greet('World')); // "Hello, World!"
31
+ console.log(getVersion()); // Current package version
32
+ ```
33
+
34
+ ## Development Workflow
35
+
36
+ ### 1. Create a Changeset
37
+
38
+ When you make changes, create a changeset to document them:
39
+
40
+ ```bash
41
+ npx changeset
42
+ ```
43
+
44
+ This will:
45
+ - Ask about the semver impact (patch, minor, or major)
46
+ - Create a markdown file in `.changeset/` describing your changes
47
+ - Commit this file with your changes
48
+
49
+ ### 2. Merge to Main
50
+
51
+ When your PR with the changeset is merged to `main`, the changeset is stored for the next release.
52
+
53
+ ### 3. Create a Release
54
+
55
+ Go to GitHub Actions → "📦 Create Release" → Run workflow:
56
+
57
+ - Select release type:
58
+ - `test` - For testing the workflow
59
+ - `rc` - Release candidate with prerelease tag
60
+ - `latest` - Stable production release
61
+
62
+ This workflow will:
63
+ 1. Enter/exit pre-release mode if needed
64
+ 2. Consume all changesets and update version
65
+ 3. Generate CHANGELOG.md
66
+ 4. Create a release branch and PR
67
+ 5. Create a git tag
68
+
69
+ ### 4. Merge the Release PR
70
+
71
+ When the release PR is merged, the "🚀 Release Publisher" workflow automatically:
72
+ 1. Publishes to NPM
73
+ 2. Creates a GitHub Release with changelog
74
+ 3. Tags the release
75
+
76
+ ## GitHub Setup Instructions
77
+
78
+ ### 1. Create the GitHub Repository
79
+
80
+ 1. Go to https://github.com/new
81
+ 2. Name: `demo-changeset-ci-workflow`
82
+ 3. Make it public (for easier NPM publishing)
83
+ 4. Don't initialize with README (we have our own)
84
+ 5. Click "Create repository"
85
+
86
+ ### 2. Push Your Code
87
+
88
+ ```bash
89
+ cd /Users/punkbit/www/punkbit/clickhouse/demo-changeset-ci-workflow
90
+
91
+ # Initialize git (if not already done)
92
+ git init
93
+ git add .
94
+ git commit -m "Initial commit: changeset-based release workflow demo"
95
+
96
+ # Add remote and push
97
+ git remote add origin https://github.com/punkbit/demo-changeset-ci-workflow.git
98
+ git branch -M main
99
+ git push -u origin main
100
+ ```
101
+
102
+ ### 3. Configure GitHub Actions Permissions (CRITICAL)
103
+
104
+ The Create Release workflow needs permission to create pull requests. Without this, you'll get the error: *"GitHub Actions is not permitted to create or approve pull requests"*
105
+
106
+ **Required Settings:**
107
+
108
+ 1. Go to your GitHub repo → **Settings** → **Actions** → **General**
109
+ 2. Under **Workflow permissions**, select:
110
+ - ✅ **Read and write permissions** (not just "Read repository contents")
111
+ 3. Check the box:
112
+ - ✅ **Allow GitHub Actions to create and approve pull requests**
113
+
114
+ **Visual guide:**
115
+ ```
116
+ Settings → Actions → General
117
+ ├─ Workflow permissions
118
+ │ ├─ ⭕ Read repository contents and packages permissions [DON'T SELECT]
119
+ │ └─ ✅ Read and write permissions [SELECT THIS]
120
+
121
+ └─ ☑️ Allow GitHub Actions to create and approve pull requests [CHECK THIS]
122
+ ```
123
+
124
+ ### 4. Configure NPM Trusted Publisher (OIDC)
125
+
126
+ This workflow uses **OIDC (OpenID Connect)** for secure, tokenless publishing to NPM. This means:
127
+ - ✅ No NPM tokens to manage or rotate
128
+ - ✅ No 2FA/OTP required during CI/CD
129
+ - ✅ Cryptographic proof of package origin (provenance)
130
+
131
+ **Setup Steps:**
132
+
133
+ 1. **Enable 2FA on your NPM account** (required for trusted publishers)
134
+ - Go to https://www.npmjs.com/settings/punkbit/security
135
+ - Enable Two-Factor Authentication if not already enabled
136
+
137
+ 2. **Add GitHub Actions as a Trusted Publisher**
138
+ - Go to your package page on NPM: https://www.npmjs.com/package/@punkbit/demo-changeset-ci-workflow
139
+ - Click **"Settings"** tab
140
+ - Under **"Trusted Publishers"**, click **"Add Publisher"**
141
+ - Select **"GitHub Actions"** as the provider
142
+ - Enter your repository: `punkbit/demo-changeset-ci-workflow`
143
+ - Click **"Add"**
144
+
145
+ 3. **Alternative: Use NPM CLI to add trusted publisher**
146
+ ```bash
147
+ npm access grant publish @punkbit/demo-changeset-ci-workflow github-actions:punkbit/demo-changeset-ci-workflow
148
+ ```
149
+
150
+ **Verification:**
151
+ After setup, you should see `github-actions:punkbit/demo-changeset-ci-workflow` listed under Trusted Publishers on your package's settings page.
152
+
153
+ **Important:**
154
+ - The package must already exist on NPM (create it manually first if needed)
155
+ - Your GitHub repository name must match exactly
156
+ - This setup only needs to be done once per package
157
+
158
+ For more details, see: https://docs.npmjs.com/trusted-publishers
159
+
160
+ ### 5. Configure Branch Protection (Recommended)
161
+
162
+ 1. Go to Settings → Branches
163
+ 2. Click "Add rule"
164
+ 3. Branch name pattern: `main`
165
+ 4. Enable:
166
+ - "Require a pull request before merging"
167
+ - "Require status checks to pass"
168
+ - "Require conversation resolution before merging"
169
+ 5. Click "Create"
170
+
171
+ ## Testing the Workflow
172
+
173
+ ### 1. Create a Test Changeset
174
+
175
+ ```bash
176
+ npx changeset
177
+ # Select 'patch' for a simple change
178
+ # Write: "Added a friendly greeting function"
179
+ ```
180
+
181
+ ### 2. Commit and Push
182
+
183
+ ```bash
184
+ git add .
185
+ git commit -m "feat: add greeting function with changeset"
186
+ git push origin main
187
+ ```
188
+
189
+ ### 3. Create a Test Release
190
+
191
+ 1. Go to GitHub → Actions → "📦 Create Release"
192
+ 2. Click "Run workflow"
193
+ 3. Select `test` as release type
194
+ 4. Click "Run workflow"
195
+
196
+ ### 4. Merge the Release PR
197
+
198
+ The workflow will create a PR. Review and merge it to trigger publishing.
199
+
200
+ ## Package.json Scripts
201
+
202
+ - `npm run build` - Compile TypeScript
203
+ - `npm run changeset:add` - Create a new changeset
204
+ - `npm run changeset:status` - Check changeset status
205
+ - `npm run changeset:version` - Update versions and changelog
206
+
207
+ ## Learn More
208
+
209
+ - [Changesets Documentation](https://github.com/changesets/changesets)
210
+ - [NPM Provenance](https://docs.npmjs.com/generating-provenance-statements)
211
+ - [GitHub OIDC Trust](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
212
+
213
+ ## License
214
+
215
+ MIT
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@punkbit/demo-changeset-ci-workflow",
3
+ "version": "0.0.0",
4
+ "description": "Demo package for showcasing changeset-based CI/CD workflow",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "keywords": [
19
+ "demo",
20
+ "changeset",
21
+ "ci-cd"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/punkbit/demo-changeset-ci-workflow.git"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "changeset:add": "changeset",
30
+ "changeset:status": "changeset status",
31
+ "changeset:version": "changeset version"
32
+ },
33
+ "devDependencies": {
34
+ "@changesets/cli": "^2.29.8",
35
+ "typescript": "^5.5.3"
36
+ },
37
+ "engines": {
38
+ "node": ">=18"
39
+ }
40
+ }