-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (86 loc) · 2.49 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
name: Fibo Service CI
##
## Validate the service via unittests and verify the service runs within docker.defaults:
## During PR, tag the image with the branch name
## On main, push the image as "latest"
on:
push:
branches: main
pull_request:
branches: main
workflow_dispatch:
permissions: read-all
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
compute-tag:
runs-on: ubuntu-latest
steps:
- name: Compute docker image tag
id: out
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "DOCKER_TAG=latest" >> $GITHUB_OUTPUT
else
echo "DOCKER_TAG=$(echo ${{ github.ref_name }} | tr '/' '_')" >> $GITHUB_OUTPUT
fi
outputs:
docker_tag: ${{ steps.out.outputs.DOCKER_TAG }}
service-unittests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fibo unittest
run: |
python --version
python -m venv .venv
source .venv/bin/activate
python -m pip install -r fibo/requirements.txt
python -m pip install -e .
echo "==========================================="
python -m unittest discover --verbose -s tests
service-build-push:
needs:
- compute-tag
- service-unittests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker image
uses: docker/build-push-action@v5
with:
push: true
tags: tgthomson/fiboservice:${{ needs.compute-tag.outputs.DOCKER_TAG }}
service-validate:
needs:
- compute-tag
- service-build-push
runs-on: ubuntu-latest
services:
fibo:
image: tgthomson/fiboservice:${{ needs.compute-tag.outputs.DOCKER_TAG }}
ports:
- 8080:80
steps:
- name: Test service endpoint
run: |
## sleep before connecting, 'cause the service is just starting...
sleep 5
docker container ls
curl -v http://localhost:8080/fibo/9
ci-validated:
needs:
- service-unittests
- service-validate
runs-on: ubuntu-latest
steps:
- name: success
if: ${{ success() }}
run: |
echo "### Workflow succeeded!" >> $GITHUB_STEP_SUMMARY