Skip to content

Commit da9ba81

Browse files
authored
Add changesets and npm publish workflows with OIDC trusted publishers (#39)
* Add changesets and npm publish workflows with OIDC trusted publishers - Add changesets for version management and changelog generation - Create changesets.yml workflow for automated version PRs - Create publish.yml workflow triggered by version tags - Configure npm OIDC trusted publishers (id-token: write) - Link b2c-cli, b2c-tooling-sdk, and b2c-dx-mcp versions together - Exclude b2c-plugin-example-config from publishing * Add publishing documentation * Explicitly filter published packages to only the 3 main packages * Aggregate all package changelogs for GitHub release notes * Add nightly and pre-release support to publish workflow * Document changesets workflow in CONTRIBUTING.md * Pin GitHub Actions to specific commit SHAs for security
1 parent fd97748 commit da9ba81

File tree

9 files changed

+1023
-25
lines changed

9 files changed

+1023
-25
lines changed

.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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "SalesforceCommerceCloud/b2c-developer-tooling" }
6+
],
7+
"commit": false,
8+
"fixed": [],
9+
"linked": [
10+
["@salesforce/b2c-cli", "@salesforce/b2c-tooling-sdk", "@salesforce/b2c-dx-mcp"]
11+
],
12+
"access": "public",
13+
"baseBranch": "main",
14+
"updateInternalDependencies": "patch",
15+
"ignore": ["@salesforce/b2c-plugin-example-config"]
16+
}

.github/workflows/changesets.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Changesets
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
version:
12+
name: Create Version PR
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
26+
with:
27+
node-version: 22
28+
cache: 'pnpm'
29+
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Create Release PR
34+
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
35+
with:
36+
version: pnpm changeset version
37+
title: 'chore: version packages'
38+
commit: 'chore: version packages'
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+' # Stable releases: v1.0.0, v2.1.3
7+
- 'v[0-9]+.[0-9]+.[0-9]+-*' # Pre-releases: v1.0.0-beta.1, v1.0.0-rc.1
8+
schedule:
9+
- cron: '0 2 * * 1-5' # Weekdays at 2 AM UTC (Mon-Fri)
10+
workflow_dispatch:
11+
inputs:
12+
release_type:
13+
description: 'Release type'
14+
required: true
15+
default: 'nightly'
16+
type: choice
17+
options:
18+
- nightly
19+
20+
jobs:
21+
publish:
22+
name: Publish
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write # For creating GitHub releases
26+
id-token: write # Required for npm OIDC trusted publishers
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
30+
31+
- name: Determine release type
32+
id: release-type
33+
run: |
34+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
35+
echo "type=stable" >> $GITHUB_OUTPUT
36+
# Pre-release versions (v1.0.0-beta.1) publish to @next, stable to @latest
37+
if [[ "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-.+ ]]; then
38+
echo "tag=next" >> $GITHUB_OUTPUT
39+
echo "prerelease=true" >> $GITHUB_OUTPUT
40+
else
41+
echo "tag=latest" >> $GITHUB_OUTPUT
42+
echo "prerelease=false" >> $GITHUB_OUTPUT
43+
fi
44+
else
45+
echo "type=nightly" >> $GITHUB_OUTPUT
46+
echo "tag=nightly" >> $GITHUB_OUTPUT
47+
echo "prerelease=false" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Validate tag matches package version
51+
if: steps.release-type.outputs.type == 'stable'
52+
run: |
53+
TAG_VERSION="${GITHUB_REF_NAME#v}"
54+
PKG_VERSION=$(node -p "require('./packages/b2c-tooling-sdk/package.json').version")
55+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
56+
echo "Error: Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)"
57+
exit 1
58+
fi
59+
60+
- name: Setup pnpm
61+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
65+
with:
66+
node-version: 22
67+
cache: 'pnpm'
68+
registry-url: 'https://registry.npmjs.org'
69+
70+
- name: Install dependencies
71+
run: pnpm install --frozen-lockfile
72+
73+
- name: Create snapshot versions
74+
if: steps.release-type.outputs.type == 'nightly'
75+
run: pnpm changeset version --snapshot nightly
76+
77+
- name: Build packages
78+
run: pnpm run build
79+
80+
- name: Run tests
81+
run: pnpm run test
82+
83+
- name: Publish to npm
84+
run: |
85+
pnpm --filter @salesforce/b2c-tooling-sdk publish --access public --no-git-checks --tag ${{ steps.release-type.outputs.tag }}
86+
pnpm --filter @salesforce/b2c-cli publish --access public --no-git-checks --tag ${{ steps.release-type.outputs.tag }}
87+
pnpm --filter @salesforce/b2c-dx-mcp publish --access public --no-git-checks --tag ${{ steps.release-type.outputs.tag }}
88+
89+
- name: Extract changelog for release
90+
if: steps.release-type.outputs.type == 'stable'
91+
run: |
92+
VERSION="${GITHUB_REF_NAME#v}"
93+
94+
# Function to extract version section from a changelog
95+
extract_version() {
96+
awk -v ver="$1" '
97+
/^## / { if (found) exit; if ($2 == ver) found=1; next }
98+
found { print }
99+
' "$2"
100+
}
101+
102+
# Build combined release notes
103+
{
104+
echo "## @salesforce/b2c-cli"
105+
echo ""
106+
extract_version "$VERSION" packages/b2c-cli/CHANGELOG.md
107+
echo ""
108+
echo "## @salesforce/b2c-dx-mcp"
109+
echo ""
110+
extract_version "$VERSION" packages/b2c-dx-mcp/CHANGELOG.md
111+
echo ""
112+
echo "## @salesforce/b2c-tooling-sdk"
113+
echo ""
114+
extract_version "$VERSION" packages/b2c-tooling-sdk/CHANGELOG.md
115+
} > /tmp/release-notes.md
116+
117+
- name: Create GitHub Release
118+
if: steps.release-type.outputs.type == 'stable'
119+
run: |
120+
PRERELEASE_FLAG=""
121+
if [[ "${{ steps.release-type.outputs.prerelease }}" == "true" ]]; then
122+
PRERELEASE_FLAG="--prerelease"
123+
fi
124+
gh release create "$GITHUB_REF_NAME" --notes-file /tmp/release-notes.md $PRERELEASE_FLAG
125+
env:
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,48 @@ Issues labelled `good first contribution`.
5858
- [x] Reviews
5959
- Changes must be approved via peer code review
6060

61+
# Changesets
62+
63+
This project uses [Changesets](https://github.com/changesets/changesets) to manage versions and changelogs.
64+
65+
## When to Add a Changeset
66+
67+
Add a changeset when your PR includes changes that users should know about:
68+
- Bug fixes
69+
- New features
70+
- Breaking changes
71+
- Significant improvements
72+
73+
You **don't need** a changeset for:
74+
- Documentation-only changes
75+
- Internal refactoring
76+
- Test improvements
77+
- CI/build changes
78+
79+
## How to Add a Changeset
80+
81+
1. Run the changeset command:
82+
```bash
83+
pnpm changeset
84+
```
85+
86+
2. Select the packages affected by your change (usually all three are linked)
87+
88+
3. Choose the change type:
89+
- `patch` - Bug fixes, minor improvements
90+
- `minor` - New features, non-breaking changes
91+
- `major` - Breaking changes
92+
93+
4. Write a brief summary of your change (this appears in the changelog)
94+
95+
5. Commit the generated `.changeset/*.md` file with your PR
96+
97+
## Notes
98+
99+
- Changesets are optional - maintainers can add them later if needed
100+
- Multiple changesets can exist for separate changes
101+
- See [PUBLISHING.md](./PUBLISHING.md) for full release process details
102+
61103
# Creating a Pull Request
62104

63105
1. **Ensure the bug/feature was not already reported** by searching on GitHub under Issues. If none exists, create a new issue so that other contributors can keep track of what you are trying to add/fix and offer suggestions (or let you know if there is already an effort in progress).

0 commit comments

Comments
 (0)