chore/no-ref: v0.3.3 code quality, CI improvements, and test coverage #32
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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| concurrency: | |
| group: ci-${{ github.head_ref || github.sha }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint-and-test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| outputs: | |
| code_changed: ${{ steps.changes.outputs.code_changed }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect code changes | |
| id: changes | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| BASE="${{ github.event.pull_request.base.sha }}" | |
| else | |
| BASE="${{ github.event.before }}" | |
| fi | |
| # Only track files that affect the distributed package. | |
| # Test, CI, and doc changes do not require a version bump or release. | |
| CHANGED=$(git diff --name-only "$BASE" HEAD -- \ | |
| 'squawk_alembic/' \ | |
| 'pyproject.toml' \ | |
| '.pre-commit-hooks.yaml') | |
| if [ -n "$CHANGED" ]; then | |
| echo "code_changed=true" >> "$GITHUB_OUTPUT" | |
| echo "Code files changed:" | |
| echo "$CHANGED" | |
| else | |
| echo "code_changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Only non-code files changed, skipping version check and release." | |
| fi | |
| - name: Setup Python and Poetry | |
| uses: ./.github/actions/setup-python-poetry | |
| - name: Run pre-commit hooks | |
| run: poetry run pre-commit run --all-files | |
| - name: Check version consistency | |
| if: steps.changes.outputs.code_changed == 'true' | |
| run: | | |
| PYPROJECT_VERSION=$(poetry version -s) | |
| INIT_VERSION=$(python -c "import squawk_alembic; print(squawk_alembic.__version__)") | |
| if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then | |
| echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)" | |
| echo "Run 'make bump VERSION=x.y.z' to update both files." | |
| exit 1 | |
| fi | |
| echo "Versions match: $PYPROJECT_VERSION" | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| git fetch origin main --depth=1 | |
| MAIN_VERSION=$(git show origin/main:pyproject.toml | python -c "import sys, tomllib; print(tomllib.loads(sys.stdin.read())['tool']['poetry']['version'])" || true) | |
| if [ -z "$MAIN_VERSION" ]; then | |
| echo "::warning::Could not determine version on main, skipping version bump check" | |
| elif [ "$PYPROJECT_VERSION" = "$MAIN_VERSION" ]; then | |
| echo "::error::Version $PYPROJECT_VERSION is the same as on main. Please bump the version." | |
| echo "Run 'make bump VERSION=x.y.z' to update both files." | |
| exit 1 | |
| fi | |
| fi | |
| - name: Run tests | |
| run: poetry run pytest tests/ -v | |
| auto-tag: | |
| needs: lint-and-test | |
| if: github.event_name == 'push' && needs.lint-and-test.outputs.code_changed == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: write | |
| outputs: | |
| tag: ${{ steps.tag.outputs.tag }} | |
| created: ${{ steps.tag.outputs.created }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python and Poetry | |
| uses: ./.github/actions/setup-python-poetry | |
| with: | |
| install-dependencies: 'false' | |
| - name: Create tag if needed | |
| id: tag | |
| run: | | |
| VERSION=$(poetry version -s) | |
| TAG="v${VERSION}" | |
| echo "Detected version: $VERSION" | |
| echo "Tag: $TAG" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG already exists. Nothing to do." | |
| echo "created=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "Creating and pushing tag $TAG" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| echo "created=true" >> "$GITHUB_OUTPUT" | |
| release: | |
| needs: auto-tag | |
| if: needs.auto-tag.outputs.created == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG: ${{ needs.auto-tag.outputs.tag }} | |
| run: | | |
| gh release create "$TAG" \ | |
| --title "Release $TAG" \ | |
| --generate-notes |