|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + version-match: |
| 17 | + name: version-match (plugin.json == tag) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 22 | + |
| 23 | + - name: Assert plugin.json.version == tag without v |
| 24 | + run: | |
| 25 | + set -euo pipefail |
| 26 | + tag="${GITHUB_REF_NAME}" |
| 27 | + expected="${tag#v}" |
| 28 | + actual=$(python3 -c "import json; print(json.load(open('.claude-plugin/plugin.json'))['version'])") |
| 29 | + if [ "$expected" != "$actual" ]; then |
| 30 | + echo "::error ::tag $tag (without v: $expected) != plugin.json.version $actual" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + echo "ok: tag=$tag matches plugin.json.version=$actual" |
| 34 | +
|
| 35 | + selftest: |
| 36 | + name: selftest (ubuntu, py 3.11) |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: [version-match] |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 42 | + |
| 43 | + - name: Setup Node |
| 44 | + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 |
| 45 | + with: |
| 46 | + node-version-file: .nvmrc |
| 47 | + cache: npm |
| 48 | + |
| 49 | + - name: Install Node deps |
| 50 | + run: npm ci |
| 51 | + |
| 52 | + - name: Setup Python |
| 53 | + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 54 | + with: |
| 55 | + python-version: "3.11" |
| 56 | + cache: pip |
| 57 | + cache-dependency-path: requirements-dev.txt |
| 58 | + |
| 59 | + - name: Install dev deps |
| 60 | + run: python -m pip install --upgrade pip && pip install -r requirements-dev.txt |
| 61 | + |
| 62 | + - name: Pytest selftest (smoke + scenarios) |
| 63 | + run: pytest bin/tests -q |
| 64 | + |
| 65 | + build-bundle: |
| 66 | + name: build-bundle (curated plugin-only) |
| 67 | + runs-on: ubuntu-latest |
| 68 | + needs: [version-match] |
| 69 | + outputs: |
| 70 | + bundle_path: ${{ steps.pack.outputs.bundle_path }} |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 74 | + |
| 75 | + - name: Pack curated bundle |
| 76 | + id: pack |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + tag="${GITHUB_REF_NAME}" |
| 80 | + bundle="pos-${tag}.tar.gz" |
| 81 | + tar -czf "$bundle" \ |
| 82 | + .claude-plugin \ |
| 83 | + .claude/skills \ |
| 84 | + .claude/rules \ |
| 85 | + hooks \ |
| 86 | + agents \ |
| 87 | + policy.yaml \ |
| 88 | + bin/pos-selftest.sh \ |
| 89 | + bin/_selftest.py \ |
| 90 | + docs/RELEASE.md |
| 91 | + echo "bundle_path=$bundle" >> "$GITHUB_OUTPUT" |
| 92 | + echo "ok: built $bundle" |
| 93 | + ls -lh "$bundle" |
| 94 | +
|
| 95 | + - name: Upload bundle artifact |
| 96 | + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45581b # v4.6.0 |
| 97 | + with: |
| 98 | + name: pos-bundle |
| 99 | + path: ${{ steps.pack.outputs.bundle_path }} |
| 100 | + if-no-files-found: error |
| 101 | + retention-days: 30 |
| 102 | + |
| 103 | + publish-release: |
| 104 | + name: publish-release |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: [version-match, selftest, build-bundle] |
| 107 | + steps: |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 110 | + |
| 111 | + - name: Download bundle artifact |
| 112 | + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 |
| 113 | + with: |
| 114 | + name: pos-bundle |
| 115 | + |
| 116 | + - name: Create GitHub release |
| 117 | + env: |
| 118 | + GH_TOKEN: ${{ github.token }} |
| 119 | + run: | |
| 120 | + set -euo pipefail |
| 121 | + tag="${GITHUB_REF_NAME}" |
| 122 | + bundle="pos-${tag}.tar.gz" |
| 123 | + gh release create "$tag" \ |
| 124 | + --title "$tag" \ |
| 125 | + --generate-notes \ |
| 126 | + "$bundle" |
| 127 | +
|
| 128 | + mirror-marketplace: |
| 129 | + name: mirror-marketplace (skippable) |
| 130 | + runs-on: ubuntu-latest |
| 131 | + needs: [publish-release] |
| 132 | + if: ${{ vars.POS_MARKETPLACE_REPO != '' }} |
| 133 | + steps: |
| 134 | + - name: Checkout |
| 135 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 136 | + |
| 137 | + - name: Open PR against marketplace repo |
| 138 | + env: |
| 139 | + GH_TOKEN: ${{ secrets.POS_MARKETPLACE_TOKEN }} |
| 140 | + MARKETPLACE_REPO: ${{ vars.POS_MARKETPLACE_REPO }} |
| 141 | + run: | |
| 142 | + set -euo pipefail |
| 143 | + tag="${GITHUB_REF_NAME}" |
| 144 | + version="${tag#v}" |
| 145 | + if [ -z "${MARKETPLACE_REPO:-}" ]; then |
| 146 | + echo "POS_MARKETPLACE_REPO unset; skip mirror" |
| 147 | + exit 0 |
| 148 | + fi |
| 149 | + workdir=$(mktemp -d) |
| 150 | + cd "$workdir" |
| 151 | + gh repo clone "$MARKETPLACE_REPO" mp -- --depth=1 |
| 152 | + cd mp |
| 153 | + branch="bump/pos-${version}" |
| 154 | + git checkout -b "$branch" |
| 155 | + python3 - <<PY |
| 156 | + import json, pathlib |
| 157 | + src = json.loads(pathlib.Path('${{ github.workspace }}/.claude-plugin/marketplace.json').read_text()) |
| 158 | + dst_path = pathlib.Path('marketplace.json') |
| 159 | + dst = json.loads(dst_path.read_text()) if dst_path.exists() else src |
| 160 | + plugins = dst.get('plugins') or [] |
| 161 | + target = next((p for p in plugins if p.get('name') == 'pos'), None) |
| 162 | + if target is None: |
| 163 | + plugins.append(src['plugins'][0]) |
| 164 | + else: |
| 165 | + target['source'] = src['plugins'][0]['source'] |
| 166 | + target['version'] = src['plugins'][0]['version'] |
| 167 | + target['description'] = src['plugins'][0].get('description', target.get('description', '')) |
| 168 | + dst['plugins'] = plugins |
| 169 | + dst_path.write_text(json.dumps(dst, indent=2) + '\n') |
| 170 | + PY |
| 171 | + git add marketplace.json |
| 172 | + if git diff --cached --quiet --exit-code; then |
| 173 | + echo "No marketplace changes detected; skip mirror" |
| 174 | + exit 0 |
| 175 | + fi |
| 176 | + git -c user.email=actions@github.com -c user.name="github-actions[bot]" \ |
| 177 | + commit -m "bump pos to ${tag}" |
| 178 | + git push -u origin "$branch" |
| 179 | + existing_pr=$(gh pr list \ |
| 180 | + --repo "$MARKETPLACE_REPO" \ |
| 181 | + --head "$branch" \ |
| 182 | + --state open \ |
| 183 | + --json number \ |
| 184 | + --jq '.[0].number') |
| 185 | + if [ -n "$existing_pr" ]; then |
| 186 | + echo "Open PR #$existing_pr already exists for branch $branch; skip create" |
| 187 | + else |
| 188 | + gh pr create \ |
| 189 | + --repo "$MARKETPLACE_REPO" \ |
| 190 | + --title "bump pos to ${tag}" \ |
| 191 | + --body "Automated bump of pos plugin to ${tag}." \ |
| 192 | + --head "$branch" |
| 193 | + fi |
0 commit comments