-
Notifications
You must be signed in to change notification settings - Fork 2
148 lines (117 loc) · 4.34 KB
/
main.yml
File metadata and controls
148 lines (117 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: cicd
on:
push:
pull_request:
jobs:
code-scan:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install --no-cache-dir -U pip ruff
- name: Lint and security check with Ruff
run: ruff check pyproxy tests
- name: Check code formatting with Ruff
run: ruff format --check pyproxy tests
unittest:
needs: code-scan
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Install build dependencies
run: pip install --no-cache-dir -r requirements.txt
- name: Run tests
run: python -m unittest discover -s tests
build-docker:
needs: unittest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Get version
run: |
VERSION=$(grep '^__version__' pyproxy/__init__.py | cut -d'"' -f2)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Convert repository owner to lowercase
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build Docker image
run: docker build -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }} -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest .
- name: Build Docker slim image
run: docker build -f Dockerfile.slim -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }}-slim -t ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest-slim .
- name: Push Docker image
run: |
docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }}-slim
docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest-slim
docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:${{ env.VERSION }}
docker push ghcr.io/${{ env.REPO_OWNER }}/pyproxy:latest
build-packages:
needs: unittest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Get version
id: get_version
run: |
version=$(grep '^__version__' pyproxy/__init__.py | cut -d'"' -f2)
echo "version=${version}" >> $GITHUB_OUTPUT
- name: Create Tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag v${{ steps.get_version.outputs.version }}
git push origin v${{ steps.get_version.outputs.version }}
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: Release v${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install build dependencies
run: pip install --no-cache-dir -U pip . build
- name: Build package
run: python -m build --sdist --wheel
- name: Upload built distributions
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
- name: Install release dependencies
run: pip install --no-cache-dir -U pip . twine packaging
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1