-
Notifications
You must be signed in to change notification settings - Fork 4
116 lines (98 loc) · 3.58 KB
/
action-build-deploy.yml
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
name: CI/CD
on: [push]
jobs:
test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
# Compare requirement files
- name: Compare requirement files
run: |
# Extract requirements from setup.cfg, remove leading spaces, and store in req_compare.txt
sed -n '/install_requires/,/^\[/{//!p}' setup.cfg | awk '/^ *$/ { next; } { print; }' | sed 's/^ //' > req_compare.txt
# Compare req_compare.txt with requirements.txt
# If files are different, echo the differences and exit with error status
if DIFF=$(diff req_compare.txt requirements.txt) ; then
echo "Files are the same"
else
echo "Files are different:"
diff req_compare.txt requirements.txt
exit 1
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install -e . && pytest src/tests
build-and-publish:
needs: test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build Package
run: python -m build .
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }} # For testing purposes: use secrets.PYPI_TEST_TOKEN
print_hash: true
verbose: true
docker:
needs: test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: tdspora
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta (BASE)
id: docker_meta_base
uses: docker/metadata-action@v5
with:
images: tdspora/syngen
tags: |
type=ref,event=branch
type=semver,pattern={{raw}}
- name: Build and push (BASE)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.docker_meta_base.outputs.tags }}
labels: ${{ steps.docker_meta_base.outputs.labels }}
cache-from: type=registry,ref=tdspora/syngen:buildcache
cache-to: type=registry,ref=tdspora/syngen:buildcache,mode=max