|
| 1 | +name: Release & Bump JS SDK |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'New semver version (e.g., 1.2.3)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + js_sdk_version: |
| 11 | + description: 'Version to pin for @layercode/js-sdk (e.g., 2.5.0)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + npm_tag: |
| 15 | + description: 'npm dist-tag to publish under (e.g., latest, next)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + default: latest |
| 19 | + |
| 20 | +jobs: |
| 21 | + release: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Setup Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: '20' |
| 37 | + registry-url: 'https://registry.npmjs.org' |
| 38 | + |
| 39 | + - name: Install dependencies |
| 40 | + run: npm ci |
| 41 | + |
| 42 | + # Configure git early so the bump step can commit if needed |
| 43 | + - name: Configure Git (early) |
| 44 | + run: | |
| 45 | + git config --local user.email "action@github.com" |
| 46 | + git config --local user.name "GitHub Action" |
| 47 | +
|
| 48 | + # EXTRA: bump @layercode/js-sdk to requested version, commit only if it changed |
| 49 | + - name: Bump @layercode/js-sdk |
| 50 | + id: bump_js_sdk |
| 51 | + run: | |
| 52 | + set -euo pipefail |
| 53 | + JS_SDK_VERSION="${{ github.event.inputs.js_sdk_version }}" |
| 54 | + echo "Target @layercode/js-sdk version: ${JS_SDK_VERSION}" |
| 55 | +
|
| 56 | + npm i @layercode/js-sdk@"${JS_SDK_VERSION}" --save-exact |
| 57 | +
|
| 58 | + if git diff --quiet -- package.json package-lock.json; then |
| 59 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 60 | + echo "No dependency change detected — skipping release." |
| 61 | + else |
| 62 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 63 | + git add package.json package-lock.json |
| 64 | + git commit -m "chore: bump @layercode/js-sdk to ${JS_SDK_VERSION}" |
| 65 | + fi |
| 66 | +
|
| 67 | + # If nothing changed from the bump, exit early (no release) |
| 68 | + - name: Stop if no changes from bump |
| 69 | + if: steps.bump_js_sdk.outputs.changed == 'false' |
| 70 | + run: | |
| 71 | + echo "No changes detected. Exiting without release." |
| 72 | + exit 0 |
| 73 | +
|
| 74 | + - name: Update package.json version |
| 75 | + run: npm version ${{ github.event.inputs.version }} --no-git-tag-version |
| 76 | + |
| 77 | + # Build before tagging/publishing so broken builds never ship |
| 78 | + - name: Build package |
| 79 | + run: npm run build |
| 80 | + |
| 81 | + # (Optional duplicate config; harmless if you want to keep original style) |
| 82 | + - name: Configure Git |
| 83 | + run: | |
| 84 | + git config --local user.email "action@github.com" |
| 85 | + git config --local user.name "GitHub Action" |
| 86 | +
|
| 87 | + - name: Commit and push changes |
| 88 | + run: | |
| 89 | + git add package.json package-lock.json |
| 90 | + if git diff --cached --quiet; then |
| 91 | + echo "Nothing to commit after version bump." |
| 92 | + else |
| 93 | + git commit -m "chore: release v${{ github.event.inputs.version }}" |
| 94 | + fi |
| 95 | + git push origin main |
| 96 | +
|
| 97 | + - name: Create Git tag |
| 98 | + run: | |
| 99 | + TAG="v${{ github.event.inputs.version }}" |
| 100 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 101 | + echo "Tag $TAG already exists — skipping create." |
| 102 | + else |
| 103 | + git tag "$TAG" |
| 104 | + git push origin "$TAG" |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Publish to npm |
| 108 | + env: |
| 109 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 110 | + run: | |
| 111 | + echo "Publishing to npm with tag '${{ github.event.inputs.npm_tag }}'..." |
| 112 | + npm publish --access public --tag "${{ github.event.inputs.npm_tag }}" |
| 113 | + echo "✅ Published successfully." |
| 114 | +
|
| 115 | + - name: Create GitHub Release |
| 116 | + uses: actions/create-release@v1 |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + with: |
| 120 | + tag_name: v${{ github.event.inputs.version }} |
| 121 | + release_name: Release v${{ github.event.inputs.version }} |
| 122 | + draft: false |
| 123 | + prerelease: false |
| 124 | + generate_release_notes: true |
0 commit comments