-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (99 loc) · 2.95 KB
/
Copy pathbasic-ci.yaml
File metadata and controls
117 lines (99 loc) · 2.95 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
name: Python CI/CD
on:
push:
branches: [main]
paths:
- ".github/workflows/basic-ci.yaml"
- "basic-ci/**"
pull_request:
branches: [main]
paths:
- ".github/workflows/basic-ci.yaml"
- "basic-ci/**"
workflow_dispatch:
inputs:
environment:
description: "Which environment to deploy to"
required: false
default: "dev"
version:
description: "Version to deploy"
required: false
default: "latest"
env:
REGISTRY: ghcr.io
jobs:
test:
runs-on: ubuntu-latest
env:
PROJECT_DIR: basic-ci
steps:
- uses: actions/checkout@v2
- name: Extract Python version from pyproject.toml
run: |
PYTHON_VERSION=$(grep -Po '(?<=python = ")[^"]*' ${{ env.PROJECT_DIR }}/pyproject.toml | sed 's/\^//')
echo "Python version extracted: $PYTHON_VERSION"
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "export PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
- name: Install dependencies (dev)
run: |
cd ${{ env.PROJECT_DIR }}
poetry install
- name: Run tests and collect coverage
run: |
cd ${{ env.PROJECT_DIR }}
poetry run pytest --cov=./ --cov-report=xml
continue-on-error: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ env.PROJECT_DIR }}
file: ${{ env.PROJECT_DIR }}/coverage.xml
name: ${{ env.PROJECT_DIR }}-coverage-report
build:
runs-on: ubuntu-latest
needs:
- test
permissions:
contents: read
packages: write
env:
PROJECT_DIR: basic-ci
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push Docker image
working-directory: ./${{ env.PROJECT_DIR }}
run: |
docker buildx build . \
--platform linux/amd64 \
--push \
-t ${{ env.REGISTRY }}/${{ github.actor }}/practice/${{ env.PROJECT_DIR }}:latest
deploy:
runs-on: ubuntu-latest
needs:
- test
- build
env:
PROJECT_DIR: basic-ci
steps:
- uses: actions/checkout@v2
- name: Deploy application
run: |
cd ${{ env.PROJECT_DIR }}
echo "Deploying version ${{ github.event.inputs.version }} to ${{ github.event.inputs.environment }} environment"