Skip to content

Commit 5631bcf

Browse files
authored
Merge pull request #42 from hypercerts-org/publish-pipeline
2 parents d1e4ff1 + 00b19ba commit 5631bcf

File tree

9 files changed

+311
-7
lines changed

9 files changed

+311
-7
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and release - staging
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: "Run in dry-run mode (test without publishing)"
8+
required: false
9+
default: false
10+
type: boolean
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: ubuntu-latest
16+
environment: staging
17+
permissions:
18+
contents: write
19+
id-token: write # to enable use of OIDC for npm provenance
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
# fetch-depth: 0 means fetch full/unlimited git history (all commits,
26+
# branches, tags). This is required for semantic-release to:
27+
# 1. Find the last release tag (could be anywhere in history)
28+
# 2. Analyze all commits since that tag to determine version bumps
29+
# 3. Generate changelog entries from those commits
30+
# Without full history, semantic-release cannot function correctly.
31+
fetch-depth: 0
32+
persist-credentials: false
33+
34+
- name: Install Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: 20
38+
cache: "npm"
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
43+
- name: Run lint
44+
run: npm run lint
45+
46+
- name: Prepare prerelease semantic
47+
if: github.ref != 'refs/heads/main'
48+
run: mv .releaserc.prerelease.yaml .releaserc.yaml
49+
50+
- name: Semantic Release
51+
uses: cycjimmy/semantic-release-action@v4
52+
id: semantic # Need an `id` for output variables
53+
with:
54+
dry_run: ${{ inputs.dry_run }}
55+
extra_plugins: |
56+
@semantic-release/commit-analyzer
57+
@semantic-release/release-notes-generator
58+
@semantic-release/changelog
59+
@semantic-release/github
60+
@semantic-release/npm
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GH_PA_TOKEN }}
63+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
64+
65+
- name: Do something when a new release published
66+
if: steps.semantic.outputs.new_release_published == 'true'
67+
run: |
68+
echo ${{ steps.semantic.outputs.new_release_version }}
69+
echo ${{ steps.semantic.outputs.new_release_major_version }}
70+
echo ${{ steps.semantic.outputs.new_release_minor_version }}
71+
echo ${{ steps.semantic.outputs.new_release_patch_version }}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: "Run in dry-run mode (test without publishing)"
8+
required: false
9+
default: false
10+
type: boolean
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: ubuntu-latest
16+
environment: staging
17+
permissions:
18+
contents: write # to be able to publish a GitHub release
19+
issues: write # to be able to comment on released issues
20+
pull-requests: write # to be able to comment on released pull requests
21+
id-token: write # to enable use of OIDC for npm provenance
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
# fetch-depth: 0 means fetch full/unlimited git history (all commits,
28+
# branches, tags). This is required for semantic-release to:
29+
# 1. Find the last release tag (could be anywhere in history)
30+
# 2. Analyze all commits since that tag to determine version bumps
31+
# 3. Generate changelog entries from those commits
32+
# Without full history, semantic-release cannot function correctly.
33+
fetch-depth: 0
34+
persist-credentials: false
35+
36+
- name: Install Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 20
40+
cache: "npm"
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Run lint
46+
run: npm run lint
47+
48+
- name: Semantic Release
49+
uses: cycjimmy/semantic-release-action@v4
50+
id: semantic # Need an `id` for output variables
51+
with:
52+
dry_run: ${{ inputs.dry_run }}
53+
extra_plugins: |
54+
@semantic-release/commit-analyzer
55+
@semantic-release/release-notes-generator
56+
@semantic-release/changelog
57+
@semantic-release/github
58+
@semantic-release/npm
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GH_PA_TOKEN }}
61+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
62+
63+
- name: Do something when a new release published
64+
if: steps.semantic.outputs.new_release_published == 'true'
65+
run: |
66+
echo ${{ steps.semantic.outputs.new_release_version }}
67+
echo ${{ steps.semantic.outputs.new_release_major_version }}
68+
echo ${{ steps.semantic.outputs.new_release_minor_version }}
69+
echo ${{ steps.semantic.outputs.new_release_patch_version }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Validate release (PR)
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
release:
8+
name: Release
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
# fetch-depth: 0 means fetch full/unlimited git history (all commits,
18+
# branches, tags). This is required for semantic-release to:
19+
# 1. Find the last release tag (could be anywhere in history)
20+
# 2. Analyze all commits since that tag to determine version bumps
21+
# 3. Generate changelog entries from those commits
22+
# Without full history, semantic-release cannot function correctly.
23+
fetch-depth: 0
24+
persist-credentials: false
25+
26+
- name: Install Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: "npm"
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Run lint
36+
run: npm run lint
37+
38+
- name: Prepare prerelease semantic
39+
if: github.ref != 'refs/heads/main'
40+
run: mv .releaserc.prerelease.yaml .releaserc.yaml
41+
42+
- name: Semantic Release
43+
uses: cycjimmy/semantic-release-action@v4
44+
id: semantic # Need an `id` for output variables
45+
with:
46+
dry_run: true
47+
extra_plugins: |
48+
@semantic-release/commit-analyzer
49+
@semantic-release/release-notes-generator
50+
@semantic-release/changelog
51+
@semantic-release/github
52+
@semantic-release/npm
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GH_PA_TOKEN }}
55+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ node_modules/
88
*.log
99
results/
1010
bun.lockb
11-
lexicons/

.releaserc.prerelease.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins:
2+
- "@semantic-release/commit-analyzer"
3+
- "@semantic-release/release-notes-generator"
4+
- "@semantic-release/changelog"
5+
- "@semantic-release/github"
6+
- "@semantic-release/npm"
7+
8+
branches:
9+
- "+([0-9])?(.{+([0-9]),x}).x"
10+
- main
11+
- name: develop
12+
prerelease: "beta"

.releaserc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins:
2+
- "@semantic-release/commit-analyzer"
3+
- "@semantic-release/release-notes-generator"
4+
- "@semantic-release/changelog"
5+
- "@semantic-release/github"
6+
- "@semantic-release/npm"
7+
8+
branches:
9+
- "+([0-9])?(.{+([0-9]),x}).x"
10+
- main

PUBLISHING.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Publishing Guide for Maintainers
2+
3+
This document describes how to publish the `@hypercerts-org/lexicon`
4+
package to npm using GitHub Actions workflows. All publishing
5+
workflows are manually triggered to give you full control over when
6+
releases are made.
7+
8+
## Prerequisites
9+
10+
Before publishing, ensure you have:
11+
12+
1. **GitHub Secrets configured:**
13+
- `GH_PA_TOKEN`: GitHub Personal Access Token with permissions for
14+
releases
15+
- `NPM_TOKEN`: npm access token with publish permissions for
16+
`@hypercerts-org` scope
17+
18+
2. **GitHub Environments configured:**
19+
- `test`: For the build-and-test job
20+
- `staging`: For the semantic-release job
21+
22+
## Publishing a Release
23+
24+
To publish a new release to npm:
25+
26+
1. **Navigate to GitHub Actions:**
27+
- Go to the repository on GitHub
28+
- Click on the "Actions" tab
29+
30+
2. **Select the workflow:**
31+
- Choose "Build and release" from the workflow list
32+
33+
3. **Run the workflow:**
34+
- Click "Run workflow"
35+
- Select the branch (typically `main`)
36+
- Click "Run workflow" to start
37+
38+
4. **What happens:**
39+
- The workflow runs linting and regenerates TypeScript types
40+
- If successful, semantic-release analyzes your commits
41+
- If there are version-worthy changes, it:
42+
- Determines the new version based on
43+
[Conventional Commits](https://www.conventionalcommits.org/)
44+
- Updates `CHANGELOG.md`
45+
- Creates a GitHub release
46+
- Publishes to npm with the new version
47+
48+
## Publishing a Prerelease
49+
50+
To publish a beta/prerelease version:
51+
52+
1. **Navigate to GitHub Actions:**
53+
- Go to the "Actions" tab
54+
55+
2. **Select the prerelease workflow:**
56+
- Choose "Build and release - staging"
57+
58+
3. **Run the workflow:**
59+
- Click "Run workflow"
60+
- Select the branch (typically `develop` or a feature branch)
61+
- Click "Run workflow"
62+
63+
4. **What happens:**
64+
- Same process as above, but publishes with a `beta` tag
65+
- Version format: `1.2.3-beta.1`, `1.2.3-beta.2`, etc.
66+
67+
## Validating Releases (PRs)
68+
69+
When you open a pull request, the "Build and release - staging"
70+
workflow automatically runs in dry-run mode to:
71+
72+
- Validate that the code builds successfully
73+
- Check that types regenerate correctly
74+
- Show what version would be released (without actually publishing)
75+
76+
This helps catch issues before merging.
77+
78+
## Version Management
79+
80+
Versions are automatically determined by semantic-release based on
81+
commit messages:
82+
83+
- `feat:` → minor version bump (1.0.0 → 1.1.0)
84+
- `fix:` → patch version bump (1.0.0 → 1.0.1)
85+
- `BREAKING CHANGE:` or `!` → major version bump (1.0.0 → 2.0.0)
86+
87+
The `prepublishOnly` script ensures types are regenerated before
88+
publishing, so the published package always includes the latest
89+
generated TypeScript types.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ following icons:
3737

3838
## Installation
3939

40-
```
40+
```bash
4141
npm i @hypercerts-org/lexicon
4242
```
4343

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
"version": "0.1.0",
44
"description": "ATProto lexicon definitions and TypeScript types for the Hypercerts protocol",
55
"type": "module",
6-
"main": "./index.js",
7-
"types": "./index.ts",
6+
"main": "./types/index.ts",
7+
"types": "./types/index.ts",
88
"exports": {
99
".": {
10-
"types": "./index.ts",
11-
"import": "./index.ts"
10+
"types": "./types/index.ts",
11+
"import": "./types/index.ts"
1212
}
1313
},
1414
"files": [
15-
"index.ts",
1615
"types",
1716
"lexicons"
1817
],

0 commit comments

Comments
 (0)