From fa74804ba3a3cb36811c5241e5941aa27bc495ae Mon Sep 17 00:00:00 2001 From: badrogger Date: Mon, 11 May 2026 15:43:05 +0100 Subject: [PATCH] Update .gitignore. Add test.yml workflow and publish-clawhub-plugin.yaml --- .github/workflows/publish-clawhub-plugin.yaml | 122 ++++++++++++++++++ .github/workflows/test.yaml | 39 ++++++ .gitignore | 3 + 3 files changed, 164 insertions(+) create mode 100644 .github/workflows/publish-clawhub-plugin.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/publish-clawhub-plugin.yaml b/.github/workflows/publish-clawhub-plugin.yaml new file mode 100644 index 0000000..ddfa4d8 --- /dev/null +++ b/.github/workflows/publish-clawhub-plugin.yaml @@ -0,0 +1,122 @@ +name: Publish ClawBits Plugin to ClawHub + +# Auto-triggers disabled — publishing is currently done manually via +# workflow_dispatch. Re-enable by restoring the `push:` and `workflow_run:` +# blocks below; the version-rewrite step is already gated on the +# `test-publish` ref name. +on: + workflow_dispatch: + # push: + # branches: [test-publish] + # workflow_run: + # workflows: ["Test"] + # types: [completed] + # branches: [main, prod] + +permissions: + contents: read + +concurrency: + group: publish-clawbits-${{ github.ref_name }} + cancel-in-progress: false + +jobs: + test: + name: Test + uses: ./.github/workflows/test.yaml + + publish-plugin: + name: Publish plugin + needs: test + runs-on: ubuntu-24.04 + steps: + - name: Checkout tested commit + uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install plugin dependencies + run: bun install --frozen-lockfile + + - name: Mark plugin package as test-publish + if: github.ref_name == 'test-publish' + run: | + node <<'NODE' + const fs = require('node:fs'); + const suffix = `test-publish.${process.env.GITHUB_RUN_NUMBER}`; + function updateVersion(path) { + const json = JSON.parse(fs.readFileSync(path, 'utf8')); + const base = String(json.version || '0.0.0').replace(/-test-publish(?:\.[0-9]+)?$/u, ''); + json.version = `${base}-${suffix}`; + fs.writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`); + return json.version; + } + const packageVersion = updateVersion('package.json'); + const manifestVersion = updateVersion('openclaw.plugin.json'); + if (packageVersion !== manifestVersion) { + throw new Error(`Version mismatch: package=${packageVersion} manifest=${manifestVersion}`); + } + console.log(`Marked ClawBits plugin as ${packageVersion}`); + NODE + + - name: Verify version parity + if: github.ref_name != 'test-publish' + run: | + node <<'NODE' + const fs = require('node:fs'); + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; + const mft = JSON.parse(fs.readFileSync('openclaw.plugin.json', 'utf8')).version; + if (pkg !== mft) { + console.error(`Version mismatch: package=${pkg} manifest=${mft}`); + process.exit(1); + } + console.log(`Publishing version ${pkg}`); + NODE + + - name: Build plugin + run: node node_modules/typescript/bin/tsc + + - name: Stage publish directory + id: pack + run: | + rm -rf publish/clawbits-openclaw-plugin + mkdir -p publish/clawbits-openclaw-plugin + cp -r dist src docs openclaw.plugin.json clawbits.config.example.json package.json publish/clawbits-openclaw-plugin/ + [ -f PLUGIN_SPEC.md ] && cp PLUGIN_SPEC.md publish/clawbits-openclaw-plugin/ || true + [ -f STREAMING_DESIGN.md ] && cp STREAMING_DESIGN.md publish/clawbits-openclaw-plugin/ || true + echo "publish_path=publish/clawbits-openclaw-plugin" >> "$GITHUB_OUTPUT" + + - name: Install ClawHub CLI + run: npm install --global clawhub@latest + + - name: Authenticate ClawHub CLI + env: + CLAWHUB_API_TOKEN: ${{ secrets.CLAWHUB_API_TOKEN }} + run: | + if [ -z "$CLAWHUB_API_TOKEN" ]; then + echo "::error::Missing required secret CLAWHUB_API_TOKEN" + exit 1 + fi + clawhub login --token "$CLAWHUB_API_TOKEN" --no-browser + + - name: Verify ClawHub authentication + run: clawhub whoami + + - name: Publish package to ClawHub + run: | + clawhub package publish "${{ steps.pack.outputs.publish_path }}" \ + --family code-plugin \ + --source-repo "${{ github.repository }}" \ + --source-commit "${{ github.sha }}" \ + --source-ref "${{ github.ref_name }}" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..a202e63 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,39 @@ +name: Test + +on: + push: + pull_request: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + name: Test + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Typecheck + run: node node_modules/typescript/bin/tsc --noEmit + + - name: Run tests + run: bun run test diff --git a/.gitignore b/.gitignore index 02e6034..a5fb963 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ dist/ clawbits.config.json package-lock.json .DS_Store +*.swp +*.swo +