-
Notifications
You must be signed in to change notification settings - Fork 20
111 lines (94 loc) · 3.41 KB
/
run-tests.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
name: Run Tests
on:
push:
branches: [master]
defaults:
run:
shell: bash
jobs:
pytest:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
REPORTS_DIR: .reports
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Checkout albs-sign-file repository
uses: actions/checkout@v4
with:
repository: AlmaLinux/albs-sign-file
path: albs-sign-file
- name: Set up Docker Buildx
# https://github.com/marketplace/actions/docker-setup-buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
# https://github.com/marketplace/actions/build-and-push-docker-images
uses: docker/build-push-action@v5
with:
context: .
target: web-server-tests
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Prepare GPG key
run: |
mv albs-sign-file ../
bash tests/prepare_gpg_key.sh
- name: Prepare working directory
run: |
mkdir -p $REPORTS_DIR
mkdir -p ../{alts,albs-frontend,albs-node,albs-sign-node,alma-tests-cacher}
ln -sf tests/test-vars.env vars.env
- name: Start services
run: docker compose up -d test_db sign_file
- name: Run pytest
id: pytest
run: |
docker compose run --rm web_server_tests bash -o pipefail -c "
pytest -v --cov \
--cov-report=json:$REPORTS_DIR/pytest-report.json \
--cov-report=term | tee $REPORTS_DIR/pytest-output.txt"
python -c "
import json
coverage = json.load(open('$REPORTS_DIR/pytest-report.json'))['totals']['percent_covered_display']
print(f'percent_covered={coverage}', file=open('$GITHUB_OUTPUT', 'a'))"
- name: Stop services
if: always()
run: docker compose down --volumes
- name: Create Coverage Badge
# https://github.com/marketplace/actions/dynamic-badges
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: 082466afa48717ae249ff072a0db02a3
filename: coverage-badge.json
label: Test Coverage
message: ${{ steps.pytest.outputs.percent_covered }}%
valColorRange: ${{ steps.pytest.outputs.percent_covered }}
minColorRange: 25
maxColorRange: 60
namedLogo: pytest
- name: Generate .md reports
if: success() || failure()
run: |
awk 'NR == 1 {next}; /^-+ coverage:/ {exit}; {print}' $REPORTS_DIR/pytest-output.txt \
> $REPORTS_DIR/pytest-report.txt
awk '/^-+ coverage:/, /^TOTAL/' $REPORTS_DIR/pytest-output.txt \
> $REPORTS_DIR/coverage-report.txt
for tool in coverage pytest; do
if [[ -s $REPORTS_DIR/${tool}-report.txt ]]; then
{
printf "<details><summary>${tool^} report</summary>\n"
printf '\n```\n'
cat $REPORTS_DIR/${tool}-report.txt
printf '\n```\n'
printf '\n</details>\n\n'
} > $REPORTS_DIR/${tool}-report.md
fi
done
- name: Publish Job Summary
if: success() || failure()
run: |
cat $REPORTS_DIR/{coverage,pytest}-report.md \
> $GITHUB_STEP_SUMMARY 2>/dev/null || true