-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (152 loc) · 5.09 KB
/
test.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Build
on:
push:
branches:
- main
tags:
- '*'
pull_request:
permissions:
# https://github.community/t/permissions-nesecary-to-comment-on-a-pr/179047/5
pull-requests: write
contents: write
jobs:
test:
name: Execute Functional & Unit Tests
strategy:
matrix:
python-version: [ '3.9' ]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Check isort, black, and flake8
run: |
pip install black flake8 isort
isort --profile black .
black --line-length 79 .
flake8 .
curl -sSL https://install.python-poetry.org | python3 -
- name: Install project dependencies
run: poetry install --no-interaction
- name: Run tests with coverage
env:
TEST_PLAN_PATH: tests/functional/testdata/plan.yaml
run: |
poetry run python3 -m coverage run -a -m pytest
poetry run python3 -m coverage html
poetry run python3 -m coverage json
- name: Publish coverage report to job summary
if: ${{ matrix.python-version == '3.9'}}
run: |
poetry run html2text --ignore-images --ignore-links -b 0 htmlcov/index.html >> $GITHUB_STEP_SUMMARY
- name: Upload json coverage
uses: actions/upload-artifact@v3
with:
name: coverage.json
path: coverage.json
if-no-files-found: error
- name: Upload coverage HTML artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: htmlcov
if-no-files-found: error
build-image:
name: Build and push container image
runs-on: ubuntu-latest
needs:
- test
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Build Docker image
run: |
docker build --no-cache -t quay.io/krkn-chaos/krkn-service-hijacking:latest .
docker tag quay.io/krkn-chaos/krkn-service-hijacking:latest quay.io/krkn-chaos/krkn-service-hijacking:${GITHUB_REF##*/}
- name: Login in quay
run: docker login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
env:
QUAY_USER: ${{ secrets.QUAY_USERNAME }}
QUAY_TOKEN: ${{ secrets.QUAY_PASSWORD }}
- name: Push Docker image
run: |
docker push quay.io/krkn-chaos/krkn-service-hijacking:latest
docker push quay.io/krkn-chaos/krkn-service-hijacking:${GITHUB_REF##*/}
badge:
name: Generate and Publish Coverage Badge
runs-on: ubuntu-latest
needs:
- build-image
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check out doc repo
uses: actions/checkout@master
with:
repository: krkn-chaos/krkn-lib-docs
path: krkn-lib-docs
ssh-key: ${{ secrets.KRKN_LIB_DOCS_PRIV_KEY }}
- name: Download json coverage
uses: actions/download-artifact@v3
with:
name: coverage.json
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Copy badge on GitHub Page Repo
env:
COLOR: red
run: |
# generate coverage badge on previously calculated total coverage
# and copy in the docs page
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
[[ $TOTAL > 90 ]] && COLOR=green
echo "TOTAL: $TOTAL"
echo "COLOR: $COLOR"
curl "https://img.shields.io/badge/coverage-$TOTAL%25-$COLOR" > ./krkn-lib-docs/coverage_badge_hijacking.svg
- name: Push updated Coverage Badge
run: |
cd krkn-lib-docs
git add .
git config user.name "krkn-chaos"
git config user.email "<>"
git commit -m "[KRKN SERVICE HIJACKING] Coverage Badge ${GITHUB_REF##*/}"
git push
# publish:
# name: Publish Library on PyPi
# runs-on: ubuntu-latest
# needs:
# - build
# if: startsWith(github.ref, 'refs/tags/')
# steps:
# - name: Check out code
# uses: actions/checkout@v3
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: dist
# path: dist
# - name: Install twine
# run: pip install -U twine
# - name: Publish
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{secrets.PYPI_TOKEN}}
# TWINE_NON_INTERACTIVE: true
# run: twine upload dist/*
# build_krkn:
# name: Build Krkn Image
# runs-on: ubuntu-latest
# steps:
# - name: Rebuild krkn
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# uses: redhat-chaos/actions/krkn@main
# with:
# QUAY_USER: ${{ secrets.RH_USERNAME }}
# QUAY_TOKEN: ${{ secrets.RH_PASSWORD }}