-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (141 loc) · 4.68 KB
/
ci.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
131
132
133
134
135
136
137
138
139
140
141
142
143
name: 'Run tests for ci cd'
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
is_package: false # set this to true if you use this template for a package that you want to publish
publish_docker: false # set this to true if you use this template to build and push a docker file to a registry
POETRY_VERSION: 1.8.3
jobs:
test-docker:
runs-on: ubuntu-latest
env:
tag: "docker-${{ github.sha }}:latest"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: buildx-${{ github.sha }}
restore-keys: |
buildx-
- name: Build docker image
uses: docker/build-push-action@v3
id: docker-build
with:
context: .
load: true
push: false
build-args: |
BUILD=test
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
tags: ${{env.tag}}
- name: Move cache # see https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: run tests in docker
uses: addnab/docker-run-action@v3
with:
shell: bash
image: ${{steps.docker-build.outputs.imageid}}
run: |
pytest -vv
prep-vars:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-vars.outputs.matrix }}
publish_docker: ${{ steps.set-vars.outputs.publish_docker }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- id: set-vars
run: |
echo "matrix={\"python-version\":${{ env.is_package && '[ \"3.9\", \"3.10\", \"3.11\", \"3.12\", ]' || '[ \"3.12\" ]' }} }" >> $GITHUB_OUTPUT
echo "publish_docker=${{env.publish_docker}}" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
needs: prep-vars
strategy:
matrix: ${{fromJson(needs.prep-vars.outputs.matrix)}}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: setup python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install Dependencies
run: poetry install
- name: Run tests
run: poetry run pytest -vv
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
needs: [test, test-docker]
if: github.ref_type == 'tag'
env:
python-version: 3.12
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: setup python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.python-version }}
cache: 'poetry'
- name: Install Dependencies
run: poetry install
- name: Set the right version
run: poetry version ${{ github.ref_name }}
- name: Build a binary wheel and a source tarball
run: poetry build
- name: Publish
if: ${{env.is_package}}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish --build
publish-docker:
name: Publish docker file and push it to a registry
runs-on: ubuntu-latest
needs: [test, test-docker, prep-vars]
if: needs.prep-vars.outputs.publish_docker && github.ref_type == 'tag'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: buildx-${{ github.sha }}
restore-keys: |
buildx-
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
cache-from: type=local,src=/tmp/.buildx-cache
tags: docker:${{ github.ref_name }}
build-args: |
BUILD_VERSION=${{ github.ref_name }}