-
Notifications
You must be signed in to change notification settings - Fork 0
chore/no-ref: v0.3.3 code quality, CI improvements, and test coverage #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9004768
9dc608f
9c7507b
a65eaa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Setup Python Environment | ||
| description: Setup Python, Poetry, and cache dependencies | ||
|
|
||
| inputs: | ||
| python-version: | ||
| description: Python version | ||
| required: false | ||
| default: '3.12' | ||
| install-dependencies: | ||
| description: Whether to install project dependencies | ||
| required: false | ||
| default: 'true' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Set up Python | ||
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
|
|
||
| - name: Install Poetry | ||
| uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 | ||
| with: | ||
| version: "2.1.3" | ||
| virtualenvs-create: true | ||
| virtualenvs-in-project: true | ||
| installer-parallel: true | ||
|
|
||
| - name: Cache virtualenv | ||
| if: inputs.install-dependencies == 'true' | ||
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | ||
| with: | ||
| path: .venv | ||
| key: ${{ runner.os }}-py${{ inputs.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-py${{ inputs.python-version }}-poetry- | ||
|
|
||
| - name: Install dependencies | ||
| if: inputs.install-dependencies == 'true' | ||
| shell: bash | ||
| run: | | ||
| poetry sync -n | ||
| poetry env info -n | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,40 +6,57 @@ on: | |
| 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@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| python-version: '3.12' | ||
| fetch-depth: 0 | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| - name: Install Poetry | ||
| uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 | ||
| with: | ||
| version: "2.1.3" | ||
| virtualenvs-create: true | ||
| virtualenvs-in-project: true | ||
| - name: Detect code changes | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditional version bump and release based on package file changes Previously, every PR (including docs and test changes) required a version bump and triggered a release on merge. Now we diff against |
||
| 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: Install dependencies | ||
| run: poetry install --no-interaction | ||
| - 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=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/' || true) | ||
| INIT_VERSION=$(grep '^__version__ = ' squawk_alembic/__init__.py | sed 's/__version__ = "\(.*\)"/\1/' || true) | ||
| if [ -z "$PYPROJECT_VERSION" ] || [ -z "$INIT_VERSION" ]; then | ||
| echo "::error::Could not parse version from pyproject.toml or __init__.py" | ||
| exit 1 | ||
| fi | ||
| PYPROJECT_VERSION=$(poetry version -s) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced fragile The old version parsing ( |
||
| 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." | ||
|
|
@@ -49,7 +66,7 @@ jobs: | |
|
|
||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| git fetch origin main --depth=1 | ||
| MAIN_VERSION=$(git show origin/main:pyproject.toml | grep '^version = ' | sed 's/version = "\(.*\)"/\1/' || true) | ||
| 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 | ||
|
|
@@ -64,8 +81,9 @@ jobs: | |
|
|
||
| auto-tag: | ||
| needs: lint-and-test | ||
| if: github.event_name == 'push' | ||
| if: github.event_name == 'push' && needs.lint-and-test.outputs.code_changed == 'true' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: write | ||
| outputs: | ||
|
|
@@ -74,14 +92,19 @@ jobs: | |
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| 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=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | ||
| VERSION=$(poetry version -s) | ||
| TAG="v${VERSION}" | ||
|
|
||
| echo "Detected version: $VERSION" | ||
|
|
@@ -103,12 +126,13 @@ jobs: | |
| 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@v4 | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Create GitHub Release | ||
| env: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shared composite action for Python/Poetry setup
Extracted from the inline steps that were duplicated between
lint-and-testandauto-tagjobs. Follows the kintsugi-rules pattern: SHA-pinned actions,poetry sync -n,installer-parallel: true, and a cache key that includes the Python version for correctness across version bumps. Theinstall-dependenciesinput lets theauto-tagjob skippoetry installsince it only needspoetry version -s.