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