|
| 1 | +name: Publish ClawBits Plugin to ClawHub |
| 2 | + |
| 3 | +# Auto-triggers disabled — publishing is currently done manually via |
| 4 | +# workflow_dispatch. Re-enable by restoring the `push:` and `workflow_run:` |
| 5 | +# blocks below; the version-rewrite step is already gated on the |
| 6 | +# `test-publish` ref name. |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + # push: |
| 10 | + # branches: [test-publish] |
| 11 | + # workflow_run: |
| 12 | + # workflows: ["Test"] |
| 13 | + # types: [completed] |
| 14 | + # branches: [main, prod] |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: publish-clawbits-${{ github.ref_name }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + test: |
| 25 | + name: Test |
| 26 | + uses: ./.github/workflows/test.yaml |
| 27 | + |
| 28 | + publish-plugin: |
| 29 | + name: Publish plugin |
| 30 | + needs: test |
| 31 | + runs-on: ubuntu-24.04 |
| 32 | + steps: |
| 33 | + - name: Checkout tested commit |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} |
| 37 | + persist-credentials: false |
| 38 | + |
| 39 | + - name: Setup Node.js |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: '22' |
| 43 | + |
| 44 | + - name: Setup Bun |
| 45 | + uses: oven-sh/setup-bun@v2 |
| 46 | + with: |
| 47 | + bun-version: latest |
| 48 | + |
| 49 | + - name: Install plugin dependencies |
| 50 | + run: bun install --frozen-lockfile |
| 51 | + |
| 52 | + - name: Mark plugin package as test-publish |
| 53 | + if: github.ref_name == 'test-publish' |
| 54 | + run: | |
| 55 | + node <<'NODE' |
| 56 | + const fs = require('node:fs'); |
| 57 | + const suffix = `test-publish.${process.env.GITHUB_RUN_NUMBER}`; |
| 58 | + function updateVersion(path) { |
| 59 | + const json = JSON.parse(fs.readFileSync(path, 'utf8')); |
| 60 | + const base = String(json.version || '0.0.0').replace(/-test-publish(?:\.[0-9]+)?$/u, ''); |
| 61 | + json.version = `${base}-${suffix}`; |
| 62 | + fs.writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`); |
| 63 | + return json.version; |
| 64 | + } |
| 65 | + const packageVersion = updateVersion('package.json'); |
| 66 | + const manifestVersion = updateVersion('openclaw.plugin.json'); |
| 67 | + if (packageVersion !== manifestVersion) { |
| 68 | + throw new Error(`Version mismatch: package=${packageVersion} manifest=${manifestVersion}`); |
| 69 | + } |
| 70 | + console.log(`Marked ClawBits plugin as ${packageVersion}`); |
| 71 | + NODE |
| 72 | +
|
| 73 | + - name: Verify version parity |
| 74 | + if: github.ref_name != 'test-publish' |
| 75 | + run: | |
| 76 | + node <<'NODE' |
| 77 | + const fs = require('node:fs'); |
| 78 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; |
| 79 | + const mft = JSON.parse(fs.readFileSync('openclaw.plugin.json', 'utf8')).version; |
| 80 | + if (pkg !== mft) { |
| 81 | + console.error(`Version mismatch: package=${pkg} manifest=${mft}`); |
| 82 | + process.exit(1); |
| 83 | + } |
| 84 | + console.log(`Publishing version ${pkg}`); |
| 85 | + NODE |
| 86 | +
|
| 87 | + - name: Build plugin |
| 88 | + run: node node_modules/typescript/bin/tsc |
| 89 | + |
| 90 | + - name: Stage publish directory |
| 91 | + id: pack |
| 92 | + run: | |
| 93 | + rm -rf publish/clawbits-openclaw-plugin |
| 94 | + mkdir -p publish/clawbits-openclaw-plugin |
| 95 | + cp -r dist src docs openclaw.plugin.json clawbits.config.example.json package.json publish/clawbits-openclaw-plugin/ |
| 96 | + [ -f PLUGIN_SPEC.md ] && cp PLUGIN_SPEC.md publish/clawbits-openclaw-plugin/ || true |
| 97 | + [ -f STREAMING_DESIGN.md ] && cp STREAMING_DESIGN.md publish/clawbits-openclaw-plugin/ || true |
| 98 | + echo "publish_path=publish/clawbits-openclaw-plugin" >> "$GITHUB_OUTPUT" |
| 99 | +
|
| 100 | + - name: Install ClawHub CLI |
| 101 | + run: npm install --global clawhub@latest |
| 102 | + |
| 103 | + - name: Authenticate ClawHub CLI |
| 104 | + env: |
| 105 | + CLAWHUB_API_TOKEN: ${{ secrets.CLAWHUB_API_TOKEN }} |
| 106 | + run: | |
| 107 | + if [ -z "$CLAWHUB_API_TOKEN" ]; then |
| 108 | + echo "::error::Missing required secret CLAWHUB_API_TOKEN" |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + clawhub login --token "$CLAWHUB_API_TOKEN" --no-browser |
| 112 | +
|
| 113 | + - name: Verify ClawHub authentication |
| 114 | + run: clawhub whoami |
| 115 | + |
| 116 | + - name: Publish package to ClawHub |
| 117 | + run: | |
| 118 | + clawhub package publish "${{ steps.pack.outputs.publish_path }}" \ |
| 119 | + --family code-plugin \ |
| 120 | + --source-repo "${{ github.repository }}" \ |
| 121 | + --source-commit "${{ github.sha }}" \ |
| 122 | + --source-ref "${{ github.ref_name }}" |
0 commit comments