-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (124 loc) · 3.69 KB
/
ci-cd.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
name: ci/cd
on:
push:
branches:
- main
workflow_dispatch:
env:
PROJECT_NAME: pg_upsert
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dev
jobs:
tests:
strategy:
matrix:
os:
- ubuntu-latest
python-version:
- "3.10"
- "3.11"
- "3.12"
services:
postgres:
image: postgis/postgis:16-3.4-alpine
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Import PostgreSQL data
run: >-
psql -h ${{ env.POSTGRES_HOST }} -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -f tests/data.sql
env:
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
python -m pip install pytest
python -m pytest
env:
POSTGRES_HOST: ${{ env.POSTGRES_HOST }}
POSTGRES_PORT: ${{ env.POSTGRES_PORT }}
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
build:
name: Build distribution 📦
runs-on: ubuntu-latest
needs: [tests]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build binary distribution package
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install --upgrade build
python -m build --sdist --wheel --outdir dist/
- name: Store the distribution package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}
path: dist/
publish:
name: PyPI Publish 🚀
needs: [build]
runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/${{ env.PROJECT_NAME }}
permissions:
id-token: write
steps:
- name: Download the dist
uses: actions/download-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
docker-build:
name: Docker Build+Push
needs: [build]
uses: geocoug/github-actions-templates/.github/workflows/docker-build.yml@main
# if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
pull-requests: write
with:
ghcr-enable: true
image-names: |
ghcr.io/${{ github.repository }}
tag-rules: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=gha-${{ github.run_id }}
platforms: linux/amd64,linux/arm64