|
| 1 | +name: Version Guard |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - 'pyproject.toml' |
| 9 | + - 'mempalace/version.py' |
| 10 | + - '.claude-plugin/marketplace.json' |
| 11 | + - '.claude-plugin/plugin.json' |
| 12 | + - '.codex-plugin/plugin.json' |
| 13 | + - '.github/workflows/version-guard.yml' |
| 14 | + |
| 15 | +jobs: |
| 16 | + check-versions: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Extract versions from all sources |
| 22 | + id: versions |
| 23 | + run: | |
| 24 | + set -euo pipefail |
| 25 | + py_version=$(grep -E '^__version__' mempalace/version.py | cut -d'"' -f2) |
| 26 | + pyproject_version=$(grep -E '^version' pyproject.toml | head -1 | cut -d'"' -f2) |
| 27 | + marketplace_version=$(jq -r '.plugins[0].version' .claude-plugin/marketplace.json) |
| 28 | + plugin_version=$(jq -r '.version' .claude-plugin/plugin.json) |
| 29 | + codex_version=$(jq -r '.version' .codex-plugin/plugin.json) |
| 30 | +
|
| 31 | + echo "py_version=$py_version" >> "$GITHUB_OUTPUT" |
| 32 | + echo "pyproject_version=$pyproject_version" >> "$GITHUB_OUTPUT" |
| 33 | + echo "marketplace_version=$marketplace_version" >> "$GITHUB_OUTPUT" |
| 34 | + echo "plugin_version=$plugin_version" >> "$GITHUB_OUTPUT" |
| 35 | + echo "codex_version=$codex_version" >> "$GITHUB_OUTPUT" |
| 36 | +
|
| 37 | + { |
| 38 | + echo "## Detected versions" |
| 39 | + echo "" |
| 40 | + echo "| Source | Version |" |
| 41 | + echo "| --- | --- |" |
| 42 | + echo "| mempalace/version.py | \`$py_version\` |" |
| 43 | + echo "| pyproject.toml | \`$pyproject_version\` |" |
| 44 | + echo "| .claude-plugin/marketplace.json | \`$marketplace_version\` |" |
| 45 | + echo "| .claude-plugin/plugin.json | \`$plugin_version\` |" |
| 46 | + echo "| .codex-plugin/plugin.json | \`$codex_version\` |" |
| 47 | + } >> "$GITHUB_STEP_SUMMARY" |
| 48 | +
|
| 49 | + - name: Verify all sources agree |
| 50 | + env: |
| 51 | + PY: ${{ steps.versions.outputs.py_version }} |
| 52 | + PYPROJECT: ${{ steps.versions.outputs.pyproject_version }} |
| 53 | + MARKETPLACE: ${{ steps.versions.outputs.marketplace_version }} |
| 54 | + PLUGIN: ${{ steps.versions.outputs.plugin_version }} |
| 55 | + CODEX: ${{ steps.versions.outputs.codex_version }} |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | + fail=0 |
| 59 | + check() { |
| 60 | + local name="$1" value="$2" expected="$3" |
| 61 | + if [[ "$value" != "$expected" ]]; then |
| 62 | + echo "::error file=$name::version mismatch — expected $expected, got $value" |
| 63 | + fail=1 |
| 64 | + fi |
| 65 | + } |
| 66 | + # All five must agree with each other (use version.py as the reference, per CLAUDE.md) |
| 67 | + check "pyproject.toml" "$PYPROJECT" "$PY" |
| 68 | + check ".claude-plugin/marketplace.json" "$MARKETPLACE" "$PY" |
| 69 | + check ".claude-plugin/plugin.json" "$PLUGIN" "$PY" |
| 70 | + check ".codex-plugin/plugin.json" "$CODEX" "$PY" |
| 71 | + exit $fail |
| 72 | +
|
| 73 | + - name: Verify tag matches manifest (tag pushes only) |
| 74 | + if: startsWith(github.ref, 'refs/tags/v') |
| 75 | + env: |
| 76 | + PY: ${{ steps.versions.outputs.py_version }} |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + tag_version="${GITHUB_REF_NAME#v}" |
| 80 | +
|
| 81 | + # Semver pre-release tags (v3.4.0-rc1, v1.0.0-beta.2, ...) are treated |
| 82 | + # as internal/staging and are not validated against the manifest. They |
| 83 | + # do not flow to end users via `/plugin update`, which reads the |
| 84 | + # manifest on the default branch. |
| 85 | + if [[ "$tag_version" == *-* ]]; then |
| 86 | + echo "Pre-release tag $GITHUB_REF_NAME — skipping strict manifest match." |
| 87 | + { |
| 88 | + echo "" |
| 89 | + echo "> Pre-release tag detected: \`$GITHUB_REF_NAME\`." |
| 90 | + echo "> Manifest ($PY) is not required to match. Pre-releases are not published via \`/plugin update\`." |
| 91 | + } >> "$GITHUB_STEP_SUMMARY" |
| 92 | + exit 0 |
| 93 | + fi |
| 94 | +
|
| 95 | + if [[ "$tag_version" != "$PY" ]]; then |
| 96 | + echo "::error::tag $GITHUB_REF_NAME does not match manifest version $PY" |
| 97 | + echo "Bump mempalace/version.py, pyproject.toml, and all plugin manifests before tagging a stable release." |
| 98 | + echo "For an internal/staging tag, use a semver pre-release suffix (e.g. v${PY}-rc1)." |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + echo "Tag $GITHUB_REF_NAME matches manifest version $PY" |
0 commit comments