Skip to content

Commit 35fb077

Browse files
authored
ci: centralized workflow shared (#39)
1 parent a8a12c8 commit 35fb077

10 files changed

Lines changed: 152 additions & 198 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Code Quality Checks'
2+
description: 'Runs formatting, linting, and type checking'
3+
4+
inputs:
5+
check-type:
6+
description: 'Type of check to run (format, lint, or type-check)'
7+
required: true
8+
source-dir:
9+
description: 'Source directory to check'
10+
required: false
11+
default: 'src/'
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Run Ruff Formatting
17+
if: inputs.check-type == 'format'
18+
shell: bash
19+
run: poetry run ruff format --config pyproject.toml ${{ inputs.source-dir }}
20+
21+
- name: Run Ruff Linting
22+
if: inputs.check-type == 'lint'
23+
shell: bash
24+
run: poetry run ruff check --config pyproject.toml ${{ inputs.source-dir }}
25+
26+
- name: Run Mypy Type Checking
27+
if: inputs.check-type == 'type-check'
28+
shell: bash
29+
run: poetry run mypy --config-file pyproject.toml ${{ inputs.source-dir }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: 'Setup Environment'
2+
description: 'Sets up Python, Poetry, and dependencies with caching'
3+
4+
inputs:
5+
python-version:
6+
description: 'Python version to use'
7+
required: false
8+
default: '3.12'
9+
cache-key-suffix:
10+
description: 'Additional suffix for cache key'
11+
required: false
12+
default: ''
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ inputs.python-version }}
21+
22+
- name: Install Poetry
23+
shell: bash
24+
run: pip install poetry
25+
26+
- name: Cache Poetry dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.cache/pypoetry
31+
~/.poetry
32+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}${{ inputs.cache-key-suffix }}
33+
34+
- name: Install dependencies
35+
shell: bash
36+
run: poetry install

.github/workflows/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Shared Configuration
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
python-version:
7+
description: "Python version to use"
8+
value: '3.12'
9+
poetry-cache-path:
10+
description: "Poetry cache paths"
11+
value: |
12+
~/.cache/pypoetry
13+
~/.poetry
14+
source-dir:
15+
description: "Source directory to check"
16+
value: 'src/'
17+
18+
jobs:
19+
config:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
python-version: '3.12'
23+
poetry-cache-path: |
24+
~/.cache/pypoetry
25+
~/.poetry
26+
source-dir: 'src/'
27+
steps:
28+
- run: echo "Shared configuration loaded"

.github/workflows/format.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,64 @@ on:
77
pull_request:
88

99
jobs:
10+
config:
11+
uses: ./.github/workflows/config.yml
12+
1013
setup:
11-
uses: ./.github/workflows/setup.yml
14+
needs: config
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ./.github/actions/setup-env
19+
with:
20+
python-version: ${{ needs.config.outputs.python-version }}
1221

1322
format:
14-
needs: setup
15-
uses: ./.github/workflows/format.yml
23+
needs: [ config, setup ]
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: ./.github/actions/setup-env
28+
with:
29+
python-version: ${{ needs.config.outputs.python-version }}
30+
- uses: ./.github/actions/code-quality
31+
with:
32+
check-type: 'format'
33+
source-dir: ${{ needs.config.outputs.source-dir }}
1634

1735
lint:
18-
needs: format
19-
uses: ./.github/workflows/lint.yml
36+
needs: [ config, format ]
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: ./.github/actions/setup-env
41+
with:
42+
python-version: ${{ needs.config.outputs.python-version }}
43+
- uses: ./.github/actions/code-quality
44+
with:
45+
check-type: 'lint'
46+
source-dir: ${{ needs.config.outputs.source-dir }}
2047

2148
type-check:
22-
needs: format
23-
uses: ./.github/workflows/type-check.yml
49+
needs: [ config, format ]
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: ./.github/actions/setup-env
54+
with:
55+
python-version: ${{ needs.config.outputs.python-version }}
56+
- uses: ./.github/actions/code-quality
57+
with:
58+
check-type: 'type-check'
59+
source-dir: ${{ needs.config.outputs.source-dir }}
2460

2561
test:
26-
needs: setup
27-
uses: ./.github/workflows/test.yml
28-
29-
create_release:
30-
if: github.ref == 'refs/heads/main'
31-
needs: [ lint, type-check, test ]
32-
uses: ./.github/workflows/release.yml
62+
needs: [ config, setup ]
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v4
66+
- uses: ./.github/actions/setup-env
67+
with:
68+
python-version: ${{ needs.config.outputs.python-version }}
69+
- name: Run Tests
70+
run: poetry run pytest

.github/workflows/release.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
name: Lint
1+
name: Create Release
22

33
on:
44
workflow_call:
55

66
jobs:
77
release:
88
runs-on: ubuntu-latest
9-
if: github.ref == 'refs/heads/main' # Only run on main branch
10-
9+
if: github.ref == 'refs/heads/main'
1110
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v4
11+
- uses: actions/checkout@v4
1412
with:
15-
fetch-depth: 0 # Fetch all history
16-
ref: main # Explicitly checkout main branch
13+
fetch-depth: 0
1714

18-
- name: Set up Python
19-
uses: actions/setup-python@v5
20-
with:
21-
python-version: '3.12'
22-
23-
- name: Install Poetry
24-
run: |
25-
pip install poetry
15+
- uses: ./.github/actions/setup-env
2616

2717
- name: Read version from pyproject.toml
2818
id: get_version
@@ -31,7 +21,6 @@ jobs:
3121
echo "VERSION=${VERSION}" >> $GITHUB_ENV
3222
3323
- name: Check if release exists
34-
id: check_release
3524
run: |
3625
RELEASE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.VERSION }})
3726
if [ "$RELEASE_EXISTS" == "404" ]; then
@@ -42,17 +31,14 @@ jobs:
4231
4332
- name: Find Previous Release
4433
if: env.CREATE_RELEASE == 'true'
45-
id: previous_release
4634
run: |
47-
git fetch --tags
4835
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
4936
if [ -n "$PREV_TAG" ]; then
5037
echo "PREV_TAG=${PREV_TAG}" >> $GITHUB_ENV
5138
fi
5239
5340
- name: Generate Compare URL
5441
if: env.CREATE_RELEASE == 'true'
55-
id: compare_url
5642
run: |
5743
if [ -n "${{ env.PREV_TAG }}" ]; then
5844
echo "URL=${{ github.server_url }}/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" >> $GITHUB_ENV
@@ -62,13 +48,10 @@ jobs:
6248
6349
- name: Generate Changelog
6450
if: env.CREATE_RELEASE == 'true'
65-
id: changelog
6651
run: |
67-
# Make the script executable
6852
chmod +x .github/generate_changelog.sh
6953
source .github/generate_changelog.sh
70-
71-
# Generate the changelog and store it in the GITHUB_ENV
54+
7255
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
7356
if [ -n "${{ env.PREV_TAG }}" ]; then
7457
generate_categorized_changelog "${{ env.PREV_TAG }}" >> $GITHUB_ENV
@@ -89,6 +72,6 @@ jobs:
8972
**Full Changelog**: ${{ env.URL }}
9073
draft: false
9174
prerelease: false
92-
target_commitish: main # Explicitly use main branch
75+
target_commitish: main
9376
env:
9477
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/setup.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)