-
Notifications
You must be signed in to change notification settings - Fork 2
156 lines (124 loc) · 4.41 KB
/
main.yml
File metadata and controls
156 lines (124 loc) · 4.41 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
149
150
151
152
153
154
155
156
name: cicd
on:
push:
branches:
- main
tags:
- "*"
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 black flake8 bandit
- name: Lint with flake8
run: flake8 pyproxy tests benchmark
- name: Check with black
run: black --check pyproxy tests benchmark
- name: Check with bandit
run: bandit -r pyproxy tests benchmark
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.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: 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
id: 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.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
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