|
| 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: Upgrade npm for trusted publishing |
| 71 | + run: npm install -g npm@latest |
| 72 | + |
| 73 | + - name: Install dependencies |
| 74 | + run: pnpm install --frozen-lockfile |
| 75 | + |
| 76 | + - name: Create snapshot versions |
| 77 | + if: steps.release-type.outputs.type == 'nightly' |
| 78 | + run: | |
| 79 | + SNAPSHOT="0.0.0-nightly.$(date +%Y%m%d%H%M%S)" |
| 80 | + for pkg in packages/b2c-tooling-sdk packages/b2c-cli packages/b2c-dx-mcp; do |
| 81 | + node -e " |
| 82 | + const fs = require('fs'); |
| 83 | + const path = '$pkg/package.json'; |
| 84 | + const pkg = JSON.parse(fs.readFileSync(path)); |
| 85 | + pkg.version = '$SNAPSHOT'; |
| 86 | + fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n'); |
| 87 | + " |
| 88 | + done |
| 89 | + echo "Set snapshot version: $SNAPSHOT" |
| 90 | +
|
| 91 | + - name: Build packages |
| 92 | + run: pnpm run build |
| 93 | + |
| 94 | + - name: Run tests |
| 95 | + run: pnpm run test |
| 96 | + |
| 97 | + - name: Publish to npm |
| 98 | + run: | |
| 99 | + pnpm --filter @salesforce/b2c-tooling-sdk publish --provenance --no-git-checks --tag ${{ steps.release-type.outputs.tag }} |
| 100 | + pnpm --filter @salesforce/b2c-cli publish --provenance --no-git-checks --tag ${{ steps.release-type.outputs.tag }} |
| 101 | + # pnpm --filter @salesforce/b2c-dx-mcp publish --provenance --no-git-checks --tag ${{ steps.release-type.outputs.tag }} |
| 102 | +
|
| 103 | + - name: Extract changelog for release |
| 104 | + if: steps.release-type.outputs.type == 'stable' |
| 105 | + run: | |
| 106 | + VERSION="${GITHUB_REF_NAME#v}" |
| 107 | +
|
| 108 | + # Function to extract version section from a changelog |
| 109 | + extract_version() { |
| 110 | + awk -v ver="$1" ' |
| 111 | + /^## / { if (found) exit; if ($2 == ver) found=1; next } |
| 112 | + found { print } |
| 113 | + ' "$2" |
| 114 | + } |
| 115 | +
|
| 116 | + # Build combined release notes |
| 117 | + { |
| 118 | + echo "## @salesforce/b2c-cli" |
| 119 | + echo "" |
| 120 | + extract_version "$VERSION" packages/b2c-cli/CHANGELOG.md |
| 121 | + echo "" |
| 122 | + echo "## @salesforce/b2c-dx-mcp" |
| 123 | + echo "" |
| 124 | + extract_version "$VERSION" packages/b2c-dx-mcp/CHANGELOG.md |
| 125 | + echo "" |
| 126 | + echo "## @salesforce/b2c-tooling-sdk" |
| 127 | + echo "" |
| 128 | + extract_version "$VERSION" packages/b2c-tooling-sdk/CHANGELOG.md |
| 129 | + } > /tmp/release-notes.md |
| 130 | +
|
| 131 | + - name: Create GitHub Release |
| 132 | + if: steps.release-type.outputs.type == 'stable' |
| 133 | + run: | |
| 134 | + PRERELEASE_FLAG="" |
| 135 | + if [[ "${{ steps.release-type.outputs.prerelease }}" == "true" ]]; then |
| 136 | + PRERELEASE_FLAG="--prerelease" |
| 137 | + fi |
| 138 | + gh release create "$GITHUB_REF_NAME" --notes-file /tmp/release-notes.md $PRERELEASE_FLAG |
| 139 | + env: |
| 140 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + |
| 142 | + - name: Package skills artifacts |
| 143 | + if: steps.release-type.outputs.type == 'stable' |
| 144 | + run: | |
| 145 | + # Create b2c-skills.zip containing plugins/b2c/skills/ |
| 146 | + cd plugins/b2c && zip -r ../../b2c-skills.zip skills/ |
| 147 | + cd ../.. |
| 148 | + # Create b2c-cli-skills.zip containing plugins/b2c-cli/skills/ |
| 149 | + cd plugins/b2c-cli && zip -r ../../b2c-cli-skills.zip skills/ |
| 150 | + cd ../.. |
| 151 | + echo "Created skills artifacts:" |
| 152 | + ls -la *.zip |
| 153 | +
|
| 154 | + - name: Upload skills to release |
| 155 | + if: steps.release-type.outputs.type == 'stable' |
| 156 | + run: | |
| 157 | + gh release upload "$GITHUB_REF_NAME" b2c-skills.zip b2c-cli-skills.zip |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments