Skip to content

Commit c4af602

Browse files
committed
simplify CI/CD
1 parent 82d2a8c commit c4af602

File tree

4 files changed

+126
-164
lines changed

4 files changed

+126
-164
lines changed

.github/workflows/ci-cd.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
tags: [ 'v*' ]
6+
pull_request:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
test-build:
14+
name: Test and Build
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.12", "3.13"]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v4
25+
with:
26+
version: "latest"
27+
28+
- name: Set up Python ${{ matrix.python-version }}
29+
run: uv python install ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: uv sync --dev
33+
34+
- name: Lint with flake8
35+
run: |
36+
uv run flake8 github_backup/
37+
38+
- name: Check code formatting with black
39+
run: |
40+
uv run black --check github_backup/
41+
42+
- name: Test import
43+
run: |
44+
uv run python -c "import github_backup; print('Import successful')"
45+
46+
- name: Test CLI help
47+
run: |
48+
uv run github-backup --help
49+
50+
- name: Build package
51+
if: matrix.python-version == '3.12'
52+
run: uv build
53+
54+
- name: Upload build artifacts
55+
if: matrix.python-version == '3.12'
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: dist
59+
path: dist/
60+
61+
docker:
62+
name: GHCR Release
63+
runs-on: ubuntu-latest
64+
needs: test-build
65+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
66+
permissions:
67+
contents: read
68+
packages: write
69+
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v4
73+
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
77+
- name: Log in to Container Registry
78+
uses: docker/login-action@v3
79+
with:
80+
registry: ${{ env.REGISTRY }}
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
84+
- name: Extract metadata
85+
id: meta
86+
uses: docker/metadata-action@v5
87+
with:
88+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
89+
tags: |
90+
type=ref,event=branch
91+
type=semver,pattern={{version}}
92+
type=semver,pattern={{major}}.{{minor}}
93+
type=semver,pattern={{major}}
94+
type=raw,value=latest,enable={{is_default_branch}}
95+
96+
- name: Build and push Docker image
97+
uses: docker/build-push-action@v5
98+
with:
99+
context: .
100+
platforms: linux/amd64,linux/arm64
101+
push: true
102+
tags: ${{ steps.meta.outputs.tags }}
103+
labels: ${{ steps.meta.outputs.labels }}
104+
cache-from: type=gha
105+
cache-to: type=gha,mode=max
106+
107+
release:
108+
name: PyPI Release
109+
runs-on: ubuntu-latest
110+
needs: test-build
111+
if: startsWith(github.ref, 'refs/tags/')
112+
permissions:
113+
contents: write
114+
id-token: write
115+
116+
steps:
117+
- name: Download build artifacts
118+
uses: actions/download-artifact@v4
119+
with:
120+
name: dist
121+
path: dist/
122+
123+
- name: Publish to PyPI
124+
uses: pypa/gh-action-pypi-publish@release/v1
125+
with:
126+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/ci.yml

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

.github/workflows/docker.yml

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

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)