-
Notifications
You must be signed in to change notification settings - Fork 20
146 lines (129 loc) · 4.41 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
144
145
146
on:
push:
branches: [main]
pull_request:
release:
types: [ published ]
jobs:
test:
name: Unit tests / ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
python: [ "3.11", "3.12" ]
fail-fast: true
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ matrix.python }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-1.8.3-1 # increment to reset cache
# The key configuration value here is `virtualenvs-in-project: true`: this creates the
# venv as a `.venv` in your testing directory, which allows the next step to easily
# cache it.
- name: Install Poetry
uses: snok/install-poetry@v1
#if: steps.cached-poetry.outputs.cache-hit != 'true'
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cache-deps
uses: actions/cache@v3
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Install dependencies. `--no-root` means "install all dependencies but not the project
# itself", which is what you want to avoid caching _your_ code. The `if` statement
# ensures this only runs on a cache miss.
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
#if: steps.cache-deps.outputs.cache-hit != 'true'
# Now install _your_ project. This isn't necessary for many types of projects -- particularly
# things like Django apps don't need this. But it's a good idea since it fully-exercises the
# pyproject.toml and makes that if you add things like console-scripts at some point that
# they'll be installed and working.
- name: Install library
run: |
poetry install --no-interaction
# Run Tests.
#- run: |source $VENV
#poetry run pytest
- name: Artifact creation
run: |
poetry build
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-${{ matrix.python }}"
path: ./dist
upload_pypi:
name: Release to PyPi
needs: [test]
permissions:
id-token: write
runs-on: ubuntu-latest
# upload to PyPI only on release
if: github.event.release && github.event.action == 'published'
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
build_and_push_docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write # needed for signing the images with GitHub OIDC Token
env:
IMAGE_NAME: qabot
IMAGE_REGISTRY: ghcr.io
IMAGE_REPOSITORY: hardbyte
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{env.IMAGE_REGISTRY}}/${{env.IMAGE_REPOSITORY}}/${{env.IMAGE_NAME}}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}