Skip to content

Commit 9273ac4

Browse files
committed
Improved ci pipelines
1 parent 2e53009 commit 9273ac4

7 files changed

Lines changed: 354 additions & 94 deletions

File tree

.github/workflows/api-ci.yml

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- ".github/workflows/api-ci.yml"
1818

1919
jobs:
20-
test:
20+
lint:
2121
runs-on: ubuntu-latest
2222

2323
steps:
@@ -29,24 +29,75 @@ jobs:
2929
- name: Set up Python
3030
run: uv python install 3.11
3131

32-
- name: Install dependencies
33-
run: uv sync --extra dev
32+
- name: Install API package with dev dependencies
33+
run: uv sync --package shelly-manager-api --extra dev
34+
35+
- name: Run black
36+
run: uv run black --check packages/api/
37+
38+
- name: Run ruff
39+
run: uv run ruff check packages/api/
40+
41+
- name: Run mypy
42+
run: uv run mypy packages/api/src/api
43+
44+
test:
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- uses: actions/checkout@v4
3449

35-
- name: Lint
36-
run: |
37-
uv run black --check packages/api/
38-
uv run ruff check packages/api/
39-
uv run mypy packages/api/src/api
50+
- name: Install uv
51+
uses: astral-sh/setup-uv@v4
4052

41-
- name: Test
53+
- name: Set up Python
54+
run: uv python install 3.11
55+
56+
- name: Install API package with dev dependencies
57+
run: uv sync --package shelly-manager-api --extra dev
58+
59+
- name: Run tests
4260
run: uv run --package shelly-manager-api pytest packages/api/tests/ -v --cov=api
4361

44-
- name: Build Docker image
45-
run: docker build -f packages/api/Dockerfile -t shelly-manager-api:latest .
62+
build:
63+
runs-on: ubuntu-latest
64+
needs: [lint, test]
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
72+
- name: Log in to GitHub Container Registry
73+
if: github.event_name != 'pull_request'
74+
uses: docker/login-action@v3
75+
with:
76+
registry: ghcr.io
77+
username: ${{ github.actor }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Extract metadata
81+
id: meta
82+
uses: docker/metadata-action@v5
83+
with:
84+
images: ghcr.io/jfmlima/shelly-manager/api
85+
tags: |
86+
type=ref,event=branch
87+
type=ref,event=pr
88+
type=semver,pattern={{version}}
89+
type=semver,pattern={{major}}.{{minor}}
90+
type=semver,pattern={{major}}
91+
type=raw,value=latest,enable={{is_default_branch}}
4692
47-
- name: Test Docker image
48-
run: |
49-
docker run --rm -d -p 8000:8000 --name test-api shelly-manager-api:latest
50-
sleep 10
51-
curl -f http://localhost:8000/health || echo "Health check endpoint may not exist yet"
52-
docker stop test-api
93+
- name: Build and push Docker image
94+
uses: docker/build-push-action@v5
95+
with:
96+
context: .
97+
file: packages/api/Dockerfile
98+
platforms: linux/amd64,linux/arm64
99+
push: ${{ github.event_name != 'pull_request' }}
100+
tags: ${{ steps.meta.outputs.tags }}
101+
labels: ${{ steps.meta.outputs.labels }}
102+
cache-from: type=gha
103+
cache-to: type=gha,mode=max

.github/workflows/cli-ci.yml

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- ".github/workflows/cli-ci.yml"
1818

1919
jobs:
20-
test:
20+
lint:
2121
runs-on: ubuntu-latest
2222

2323
steps:
@@ -29,21 +29,75 @@ jobs:
2929
- name: Set up Python
3030
run: uv python install 3.11
3131

32-
- name: Install dependencies
33-
run: uv sync --extra dev
32+
- name: Install CLI package with dev dependencies
33+
run: uv sync --package shelly-manager-cli --extra dev
34+
35+
- name: Run black
36+
run: uv run black --check packages/cli/
37+
38+
- name: Run ruff
39+
run: uv run ruff check packages/cli/
40+
41+
- name: Run mypy
42+
run: uv run mypy packages/cli/src/cli
43+
44+
test:
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- uses: actions/checkout@v4
3449

35-
- name: Lint
36-
run: |
37-
uv run black --check packages/cli/
38-
uv run ruff check packages/cli/
39-
uv run mypy packages/cli/src/cli
50+
- name: Install uv
51+
uses: astral-sh/setup-uv@v4
4052

41-
- name: Test
53+
- name: Set up Python
54+
run: uv python install 3.11
55+
56+
- name: Install CLI package with dev dependencies
57+
run: uv sync --package shelly-manager-cli --extra dev
58+
59+
- name: Run tests
4260
run: uv run --package shelly-manager-cli pytest packages/cli/tests/ -v --cov=cli
4361

44-
- name: Build Docker image
45-
run: docker build -f packages/cli/Dockerfile -t shelly-manager-cli:latest .
62+
build:
63+
runs-on: ubuntu-latest
64+
needs: [lint, test]
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
72+
- name: Log in to GitHub Container Registry
73+
if: github.event_name != 'pull_request'
74+
uses: docker/login-action@v3
75+
with:
76+
registry: ghcr.io
77+
username: ${{ github.actor }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Extract metadata
81+
id: meta
82+
uses: docker/metadata-action@v5
83+
with:
84+
images: ghcr.io/jfmlima/shelly-manager/cli
85+
tags: |
86+
type=ref,event=branch
87+
type=ref,event=pr
88+
type=semver,pattern={{version}}
89+
type=semver,pattern={{major}}.{{minor}}
90+
type=semver,pattern={{major}}
91+
type=raw,value=latest,enable={{is_default_branch}}
4692
47-
- name: Test Docker image
48-
run: |
49-
docker run --rm shelly-manager-cli:latest --help
93+
- name: Build and push Docker image
94+
uses: docker/build-push-action@v5
95+
with:
96+
context: .
97+
file: packages/cli/Dockerfile
98+
platforms: linux/amd64,linux/arm64
99+
push: ${{ github.event_name != 'pull_request' }}
100+
tags: ${{ steps.meta.outputs.tags }}
101+
labels: ${{ steps.meta.outputs.labels }}
102+
cache-from: type=gha
103+
cache-to: type=gha,mode=max

.github/workflows/core-ci.yml

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- ".github/workflows/core-ci.yml"
1616

1717
jobs:
18-
test:
18+
lint:
1919
runs-on: ubuntu-latest
2020

2121
steps:
@@ -27,18 +27,52 @@ jobs:
2727
- name: Set up Python
2828
run: uv python install 3.11
2929

30-
- name: Install dependencies
31-
run: uv sync --extra dev
30+
- name: Install core package with dev dependencies
31+
run: uv sync --package shelly-manager-core --extra dev
32+
33+
- name: Run black
34+
run: uv run black --check packages/core/
35+
36+
- name: Run ruff
37+
run: uv run ruff check packages/core/
38+
39+
- name: Run mypy
40+
run: uv run mypy packages/core/src/core
41+
42+
test:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Install uv
49+
uses: astral-sh/setup-uv@v4
50+
51+
- name: Set up Python
52+
run: uv python install 3.11
3253

33-
- name: Lint
34-
run: |
35-
uv run black --check packages/core/
36-
uv run ruff check packages/core/
37-
uv run mypy packages/core/src/core
54+
- name: Install core package with dev dependencies
55+
run: uv sync --package shelly-manager-core --extra dev
3856

39-
- name: Test
57+
- name: Run tests
4058
run: uv run --package shelly-manager-core pytest packages/core/tests/ -v --cov=core
4159

60+
build:
61+
runs-on: ubuntu-latest
62+
needs: [lint, test]
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Install uv
68+
uses: astral-sh/setup-uv@v4
69+
70+
- name: Set up Python
71+
run: uv python install 3.11
72+
73+
- name: Install core package
74+
run: uv sync --package shelly-manager-core --no-dev
75+
4276
- name: Build package
4377
run: uv build --package shelly-manager-core
4478

.github/workflows/release.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_PREFIX: ghcr.io/jfmlima/shelly-manager
11+
12+
jobs:
13+
create-release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Create GitHub Release
20+
uses: actions/create-release@v1
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
with:
24+
tag_name: ${{ github.ref_name }}
25+
release_name: Release ${{ github.ref_name }}
26+
body: |
27+
## Docker Images
28+
29+
🐳 **Available Docker Images:**
30+
- `${{ env.IMAGE_PREFIX }}/api:${{ github.ref_name }}`
31+
- `${{ env.IMAGE_PREFIX }}/cli:${{ github.ref_name }}`
32+
- `${{ env.IMAGE_PREFIX }}/web:${{ github.ref_name }}`
33+
34+
## Quick Start
35+
36+
```bash
37+
# Run API server
38+
docker run -p 8000:8000 ${{ env.IMAGE_PREFIX }}/api:${{ github.ref_name }}
39+
40+
# Run CLI tool
41+
docker run --rm ${{ env.IMAGE_PREFIX }}/cli:${{ github.ref_name }} --help
42+
43+
# Run Web UI
44+
docker run -p 80:80 ${{ env.IMAGE_PREFIX }}/web:${{ github.ref_name }}
45+
```
46+
47+
## Changes
48+
49+
See the commits since the previous release for detailed changes.
50+
draft: false
51+
prerelease: ${{ contains(github.ref_name, '-') }}
52+
53+
build-and-push-all:
54+
runs-on: ubuntu-latest
55+
needs: create-release
56+
strategy:
57+
matrix:
58+
package:
59+
- name: api
60+
dockerfile: packages/api/Dockerfile
61+
context: .
62+
- name: cli
63+
dockerfile: packages/cli/Dockerfile
64+
context: .
65+
- name: web
66+
dockerfile: packages/web/Dockerfile
67+
context: packages/web
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Set up Docker Buildx
73+
uses: docker/setup-buildx-action@v3
74+
75+
- name: Log in to GitHub Container Registry
76+
uses: docker/login-action@v3
77+
with:
78+
registry: ${{ env.REGISTRY }}
79+
username: ${{ github.actor }}
80+
password: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Extract metadata
83+
id: meta
84+
uses: docker/metadata-action@v5
85+
with:
86+
images: ${{ env.IMAGE_PREFIX }}/${{ matrix.package.name }}
87+
tags: |
88+
type=semver,pattern={{version}}
89+
type=semver,pattern={{major}}.{{minor}}
90+
type=semver,pattern={{major}}
91+
92+
- name: Build and push Docker image
93+
uses: docker/build-push-action@v5
94+
with:
95+
context: ${{ matrix.package.context }}
96+
file: ${{ matrix.package.dockerfile }}
97+
platforms: linux/amd64,linux/arm64
98+
push: true
99+
tags: ${{ steps.meta.outputs.tags }}
100+
labels: ${{ steps.meta.outputs.labels }}
101+
cache-from: type=gha
102+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)