Merge pull request #42 from VioletCranberry/feat/batch-deps-query #34
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| jobs: | |
| validate: | |
| name: Validate Tag | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.extract.outputs.version }} | |
| steps: | |
| - name: Extract and validate version | |
| id: extract | |
| run: | | |
| TAG="${GITHUB_REF_NAME}" | |
| VERSION="${TAG#v}" | |
| echo "Extracted version: ${VERSION}" | |
| if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$ ]]; then | |
| echo "::error::Invalid semver format: ${VERSION}" | |
| exit 1 | |
| fi | |
| echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" | |
| test: | |
| name: Test | |
| needs: validate | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Ruff check | |
| run: uvx ruff check src/ tests/ | |
| - name: Ruff format check | |
| run: uvx ruff format --check src/ tests/ | |
| - name: Restore cached virtual environment | |
| uses: actions/cache@v4 | |
| with: | |
| path: .venv | |
| key: venv-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-${{ hashFiles('uv.lock') }} | |
| - name: Install dependencies | |
| run: uv sync --frozen | |
| - name: Run unit tests | |
| run: uv run pytest | |
| build: | |
| name: Build Package | |
| needs: validate | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Set version | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: sed -i "s/^version = .*/version = \"${VERSION}\"/" pyproject.toml | |
| - name: Build package | |
| run: uv build | |
| - name: Upload dist artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| publish-testpypi: | |
| name: Publish to TestPyPI | |
| needs: [validate, test, build] | |
| runs-on: ubuntu-latest | |
| environment: testpypi | |
| steps: | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: false | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Publish to TestPyPI | |
| run: uv publish --publish-url https://test.pypi.org/legacy/ --check-url https://test.pypi.org/simple/cocosearch/ dist/* | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| publish-pypi: | |
| name: Publish to PyPI | |
| needs: [validate, publish-testpypi] | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| steps: | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: false | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Publish to PyPI | |
| run: uv publish --check-url https://pypi.org/simple/cocosearch/ dist/* | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| update-version: | |
| name: Update Version in Main | |
| needs: [validate, publish-pypi] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Set version | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: uv version "$VERSION" --no-sync | |
| - name: Sync version to all files | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: | | |
| sed -i "s/__version__ = \".*\"/__version__ = \"${VERSION}\"/" src/cocosearch/__init__.py | |
| jq --arg v "$VERSION" '.version = $v' .claude-plugin/plugin.json > .claude-plugin/plugin.json.tmp | |
| mv .claude-plugin/plugin.json.tmp .claude-plugin/plugin.json | |
| jq --arg v "$VERSION" '.metadata.version = $v | .plugins[0].version = $v' .claude-plugin/marketplace.json > .claude-plugin/marketplace.json.tmp | |
| mv .claude-plugin/marketplace.json.tmp .claude-plugin/marketplace.json | |
| - name: Commit and push version bump | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml uv.lock src/cocosearch/__init__.py .claude-plugin/plugin.json .claude-plugin/marketplace.json | |
| if git diff --cached --quiet; then | |
| echo "No version change detected, skipping commit." | |
| exit 0 | |
| fi | |
| git commit -m "chore: bump version to ${VERSION} [skip ci]" | |
| for i in 1 2 3; do | |
| git pull --rebase origin main | |
| git push origin main && exit 0 | |
| echo "Push attempt ${i} failed, retrying..." | |
| sleep 2 | |
| done | |
| echo "::error::Failed to push version bump after 3 attempts" | |
| exit 1 | |
| github-release: | |
| name: GitHub Release | |
| needs: [validate, publish-pypi] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: v${{ needs.validate.outputs.version }} | |
| generate_release_notes: true |