-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (115 loc) · 4.57 KB
/
sfs.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: "CI for SFS project"
on:
push:
branches:
- develop
pull_request:
branches:
- main
- develop
jobs:
quality-code:
name: "Quality code"
strategy:
fail-fast: false
matrix:
python-version:
- '3.12.3'
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: 'Checkout code'
uses: actions/checkout@v3
- name: 'Setup Python ${{ matrix.python-version }}'
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: 'Setup cache pip and poetry'
uses: ./.github/actions/cache-package-managment
with:
cache-key: ${{ runner.os }}-pip-poetry-${{ hashFiles('**/poetry.lock') }}
- name: 'Setup python environment'
uses: ./.github/actions/setup-python-environment
- name: 'Install dependencies'
run: poetry add black flake8 bandit
- name: 'Run black'
run: poetry run black . --check
- name: 'Run flake8'
run: poetry run flake8 .
- name: 'Run bandit'
run: poetry run bandit .
test-code:
name: "Test Code"
needs: [quality-code]
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version:
- '3.12.3'
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: 'Checkout code'
uses: actions/checkout@v3
- name: 'Cache pip and poetry'
uses: ./.github/actions/cache-package-managment
with:
cache-key: ${{ runner.os }}-pip-poetry-${{ hashFiles('**/poetry.lock') }}
- name: 'Setup Python ${{ matrix.python-version }}'
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: 'Setup python environment'
uses: ./.github/actions/setup-python-environment
- name: 'Install dependencies'
run: poetry install --no-root
- name: 'Run pytest'
run: |
echo "Running pytest"
poetry run pytest --cov --cov-report term --cov-report xml:coverage.xml tests
- name: 'Upload coverage report'
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage.xml
create-docker-image:
needs: [test-code]
runs-on: ubuntu-latest
environment:
name: ${{ (github.ref == 'refs/heads/main' && 'latest') || (github.ref == 'refs/heads/develop' && 'develop') }}
steps:
- name: 'Checkout code'
uses: actions/checkout@v3
- name: 'Login to Gihtub Docker registry'
run: |
echo "Logging in to Github Docker registry"
echo "${{ secrets.GHRC_PASSWORD }}" | \
docker login ghcr.io -u "${{ secrets.GHRC_USERNAME }}" --password-stdin
echo "Logged in to Github Docker registry"
- name: 'Determine image tag and build (improved logic)'
id: build
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
BRANCH_NAME="${{ github.ref_name }}"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
BRANCH_NAME="${{ github.base_ref }}"
else
echo "Unsupported event: ${{ github.event_name }}"
exit 1
fi
echo "Branch name: $BRANCH_NAME"
if [[ "$BRANCH_NAME" == "main" || "$BRANCH_NAME" == "master" ]]; then
DOCKER_TAG_NAME="latest"
elif [[ "$BRANCH_NAME" == "develop" ]]; then
DOCKER_TAG_NAME="dev"
else
echo "No valid tag found for branch $BRANCH_NAME, exiting..."
exit 1
fi
echo "Building Docker image with tag: $DOCKER_TAG_NAME ..."
docker build --no-cache -t ${{ secrets.GHRC_REGISTRY_ADDR }}:$DOCKER_TAG_NAME .
docker push ${{ secrets.GHRC_REGISTRY_ADDR }}:$DOCKER_TAG_NAME
echo "Docker image built and pushed to Github Docker registry"