name: Release
on:
push:
tags:
- "v*"
env:
PYTHON_VERSION: "3.11"
jobs:
build:
name: Build Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Get version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
- name: Update version in source files
run: |
VERSION=${{ steps.version.outputs.version }}
# Update pyproject.toml
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
# Update __init__.py
sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" src/contextfs/__init__.py
# Verify
echo "pyproject.toml:"
grep "^version" pyproject.toml
echo "__init__.py:"
grep "__version__" src/contextfs/__init__.py | head -1
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
name: dist
path: dist/
test:
name: Test Release Build
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Download artifacts
uses: actions/download-artifact@v7
with:
name: dist
path: dist/
- name: Install from wheel
run: |
pip install dist/*.whl
- name: Test import
run: |
python -c "import contextfs; print(f'contextfs version: {contextfs.__version__}')"
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build, test]
environment: release
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v7
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: [build, test]
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Update npm for OIDC trusted publishing
run: npm install -g npm@latest
- name: Verify plugin version matches tag
working-directory: claude-plugin
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
PKG_VERSION=$(node -p "require('./package.json').version")
echo "Tag version: $TAG_VERSION"
echo "Package version: $PKG_VERSION"
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match package.json ($PKG_VERSION)"
echo "Run scripts/release.sh to update all versions before tagging"
exit 1
fi
- name: Publish to NPM (OIDC trusted publishing)
working-directory: claude-plugin
run: npm publish --access public
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [build, test]
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v7
with:
name: dist
path: dist/
- name: Get version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Generate changelog
id: changelog
run: |
CHANGELOG=$(python scripts/generate_changelog.py --format markdown 2>/dev/null || echo "- See commit history for changes")
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: false
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
make_latest: true
body: |
## ContextFS v${{ steps.version.outputs.version }}
### Installation
```bash
pip install contextfs==${{ steps.version.outputs.version }}
```
Or with uvx:
```bash
uvx contextfs --version
```
### What's Changed
${{ steps.changelog.outputs.changelog }}
### Links
- [Documentation](https://contextfs.github.io/contextfs/)
- [PyPI](https://pypi.org/project/contextfs/${{ steps.version.outputs.version }}/)
- [Changelog](https://github.com/contextfs/contextfs/commits/v${{ steps.version.outputs.version }})
notify-slack:
name: Notify Slack
runs-on: ubuntu-latest
needs: [publish-pypi, publish-npm, github-release]
if: always() && needs.publish-pypi.result == 'success'
steps:
- uses: actions/checkout@v6
- name: Get version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Generate changelog
id: changelog
run: |
CHANGELOG=$(python scripts/generate_changelog.py --format slack 2>/dev/null || echo "See GitHub release for details")
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Send Slack notification
uses: slackapi/slack-github-action@v2.1.1
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🚀 ContextFS v${{ steps.version.outputs.version }} Released!",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*PyPI:*\n`pip install contextfs==${{ steps.version.outputs.version }}`"
},
{
"type": "mrkdwn",
"text": "*npm:*\n`npm i claude-plugin-contextfs@${{ steps.version.outputs.version }}`"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*What's Changed:*\n${{ steps.changelog.outputs.changelog }}"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "<https://github.com/contextfs/contextfs/releases/tag/v${{ steps.version.outputs.version }}|GitHub Release> • <https://pypi.org/project/contextfs/${{ steps.version.outputs.version }}/|PyPI> • <https://www.npmjs.com/package/claude-plugin-contextfs|npm>"
}
]
}
]
}