Skip to content

Commit 8ac56b8

Browse files
committed
Ci/CD
1 parent 23d364c commit 8ac56b8

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ci-cd-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
test:
14+
name: Test (Python ${{ matrix.python-version }})
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.10", "3.11"]
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
cache: pip
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -e ".[dev]"
36+
37+
- name: Run test suite
38+
run: pytest tests/ -v
39+
40+
docker:
41+
name: Build and publish Docker image
42+
runs-on: ubuntu-latest
43+
needs: test
44+
if: >
45+
github.event_name == 'workflow_dispatch' ||
46+
(github.event_name == 'push' &&
47+
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
48+
permissions:
49+
contents: read
50+
packages: write
51+
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v4
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: Normalize image name
60+
id: vars
61+
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
62+
63+
- name: Log in to GitHub Container Registry
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ghcr.io
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Generate Docker metadata
71+
id: meta
72+
uses: docker/metadata-action@v5
73+
with:
74+
images: ${{ steps.vars.outputs.image }}
75+
tags: |
76+
type=sha,format=short
77+
type=ref,event=branch
78+
type=ref,event=tag
79+
type=raw,value=latest,enable={{is_default_branch}}
80+
81+
- name: Build and push Docker image
82+
uses: docker/build-push-action@v6
83+
with:
84+
context: .
85+
push: true
86+
tags: ${{ steps.meta.outputs.tags }}
87+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)