|
| 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 }} |
0 commit comments