-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (100 loc) · 2.99 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
Test:
environment:
name: production
runs-on: ubuntu-latest
name: Build and Test
# env:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.11.2'
- name: Install poetry
shell: bash
run: |
python -m pip install poetry==1.5.1
- name: Configure poetry
shell: bash
run: |
python -m poetry config virtualenvs.in-project true
- name: Cache the virtualenv
uses: actions/cache@v4
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
shell: bash
run: |
python -m poetry install --no-root
# - name: Code quality checks
# shell: bash
# run: |
# poetry run python -m black --check .
- name: Run unit tests
shell: bash
run: |
poetry run python -m pytest -xvvv tests/
- name: Create checks.yaml file
shell: bash
run: |
echo "- name: test check" >> checks.yaml
echo " url: 'https://github.com'" >> checks.yaml
echo " retries: 1" >> checks.yaml
echo " status_accepted:" >> checks.yaml
echo " - 200" >> checks.yaml
- name: Start application
shell: bash
run: |
# Start the application in the background
poetry run python src/main.py &
APP_PID=$!
# Allow the application some time to start
sleep 15
# Check that the application is running
if ps -p $APP_PID > /dev/null
then
echo "Application is up and running"
else
echo "Application failed to start"
exit 1
fi
# Shut down the application
kill $APP_PID
Docker-Publish:
needs: Test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
runs-on: ubuntu-latest
steps:
- name: pull git repo
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/python-urlchecker:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}