Merge pull request #2 from VioletCranberry/feat/search-grammar-filter… #7
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 | |
| 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 | |
| - name: Install dependencies | |
| run: uv sync --frozen | |
| - name: Ruff check | |
| run: uv run ruff check src/ tests/ | |
| - name: Ruff format check | |
| run: uv run ruff format --check src/ tests/ | |
| - name: Run unit tests | |
| run: uv run pytest | |
| publish-testpypi: | |
| name: Publish to TestPyPI | |
| needs: [validate, test] | |
| runs-on: ubuntu-latest | |
| environment: testpypi | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --frozen | |
| - name: Set version | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: uv version "$VERSION" | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to TestPyPI | |
| run: uv publish --publish-url https://test.pypi.org/legacy/ --check-url https://test.pypi.org/simple/cocosearch/ | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| publish-pypi: | |
| name: Publish to PyPI | |
| needs: [validate, test, publish-testpypi] | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --frozen | |
| - name: Set version | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: uv version "$VERSION" | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| run: uv publish --check-url https://pypi.org/simple/cocosearch/ | |
| 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 | |
| with: | |
| enable-cache: true | |
| - name: Set version | |
| env: | |
| VERSION: ${{ needs.validate.outputs.version }} | |
| run: uv version "$VERSION" | |
| - 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 | |
| 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 |