|
| 1 | +# Publish @cloudbase/open-agent-kernel to npm. |
| 2 | +# |
| 3 | +# Required repository secret (Settings → Secrets and variables → Actions): |
| 4 | +# NPM_TOKEN npm Automation or Granular Access Token with publish permission |
| 5 | +# for @cloudbase/open-agent-kernel |
| 6 | +# |
| 7 | +# Trigger: Actions → Publish to npm → Run workflow |
| 8 | +# Default bump is prerelease (current line is 0.1.0-beta.x, dist-tag: beta). |
| 9 | + |
| 10 | +name: Publish to npm |
| 11 | + |
| 12 | +on: |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + bump: |
| 16 | + description: Version bump type |
| 17 | + required: true |
| 18 | + type: choice |
| 19 | + default: prerelease |
| 20 | + options: |
| 21 | + - prerelease |
| 22 | + - prepatch |
| 23 | + - preminor |
| 24 | + - premajor |
| 25 | + - patch |
| 26 | + - minor |
| 27 | + - major |
| 28 | + preid: |
| 29 | + description: Prerelease identifier (prerelease / prepatch / preminor / premajor) |
| 30 | + required: false |
| 31 | + default: beta |
| 32 | + type: string |
| 33 | + |
| 34 | +concurrency: |
| 35 | + group: npm-publish |
| 36 | + cancel-in-progress: false |
| 37 | + |
| 38 | +permissions: |
| 39 | + contents: write |
| 40 | + |
| 41 | +jobs: |
| 42 | + publish: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + timeout-minutes: 20 |
| 45 | + steps: |
| 46 | + - name: Guard branch |
| 47 | + run: | |
| 48 | + if [[ "${GITHUB_REF}" != "refs/heads/main" ]]; then |
| 49 | + echo "Publishing is only allowed from main. Current ref: ${GITHUB_REF}" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup pnpm |
| 57 | + uses: pnpm/action-setup@v4 |
| 58 | + with: |
| 59 | + version: 10 |
| 60 | + |
| 61 | + - name: Setup Node.js |
| 62 | + uses: actions/setup-node@v4 |
| 63 | + with: |
| 64 | + node-version: 20 |
| 65 | + registry-url: https://registry.npmjs.org |
| 66 | + cache: pnpm |
| 67 | + |
| 68 | + - name: Install dependencies |
| 69 | + run: pnpm install --frozen-lockfile |
| 70 | + |
| 71 | + - name: Type check |
| 72 | + run: pnpm type-check |
| 73 | + |
| 74 | + - name: Test |
| 75 | + run: pnpm test |
| 76 | + |
| 77 | + - name: Configure git identity |
| 78 | + run: | |
| 79 | + git config user.name "github-actions[bot]" |
| 80 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 81 | +
|
| 82 | + - name: Bump version |
| 83 | + id: bump |
| 84 | + env: |
| 85 | + BUMP: ${{ inputs.bump }} |
| 86 | + PREID: ${{ inputs.preid }} |
| 87 | + run: | |
| 88 | + set -euo pipefail |
| 89 | + if [[ "$BUMP" == pre* ]]; then |
| 90 | + pnpm version "$BUMP" --preid "${PREID:-beta}" -m "chore(release): v%s" |
| 91 | + else |
| 92 | + pnpm version "$BUMP" -m "chore(release): v%s" |
| 93 | + fi |
| 94 | +
|
| 95 | + VERSION="$(node -p "require('./package.json').version")" |
| 96 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 97 | + if [[ "${VERSION}" == *-* ]]; then |
| 98 | + echo "tag=beta" >> "$GITHUB_OUTPUT" |
| 99 | + else |
| 100 | + echo "tag=latest" >> "$GITHUB_OUTPUT" |
| 101 | + fi |
| 102 | + echo "Bumped to v${VERSION}" |
| 103 | +
|
| 104 | + - name: Publish to npm |
| 105 | + env: |
| 106 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 107 | + run: pnpm publish --access public --no-git-checks --tag "${{ steps.bump.outputs.tag }}" |
| 108 | + |
| 109 | + - name: Push version commit and tag |
| 110 | + run: git push origin HEAD --follow-tags |
| 111 | + |
| 112 | + - name: Summary |
| 113 | + run: | |
| 114 | + { |
| 115 | + echo "## Published @cloudbase/open-agent-kernel@${{ steps.bump.outputs.version }}" |
| 116 | + echo "" |
| 117 | + echo "- bump: \`${{ inputs.bump }}\`" |
| 118 | + echo "- npm dist-tag: \`${{ steps.bump.outputs.tag }}\`" |
| 119 | + echo "- package: https://www.npmjs.com/package/@cloudbase/open-agent-kernel" |
| 120 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments