-
Notifications
You must be signed in to change notification settings - Fork 7
105 lines (92 loc) · 3.38 KB
/
test.yaml
File metadata and controls
105 lines (92 loc) · 3.38 KB
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
name: Tests
on:
push:
branches-ignore:
- 'badges'
jobs:
build:
name: Run Python Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: isbang/compose-action@v1.0.0
with:
compose-file: './docker-compose.yml'
down-flags: '--volumes'
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install Python dependencies
run: |
sudo apt install -y $(grep -o ^[^#][[:alnum:]-]* "packages.list")
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install -e .
- name: Test with pytest
id: pytest
run: |
python3 tests/add_access_token.py
pytest --exitfirst --verbose --failed-first --cov=. --cov-report html
total=$(cat htmlcov/index.html | grep -i -C 4 total | tail -n 1 | grep -Eo '[0-9]+%|[0-9]+\.[0-9]+%' | grep -Eo '[0-9]+|[0-9]+\.[0-9]+')
if (( $(echo "$total <= 50" | bc -l) )) ; then
COLOR=red
elif (( $(echo "$total > 80" | bc -l) )); then
COLOR=green
else
COLOR=orange
fi
# Generates a GitHub Workflow output named `lines` with a coverage value
echo "##[set-output name=coverage;]${total}"
echo "##[set-output name=color;]${COLOR}"
# Get current banch name to use it as dest directory
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Prepare environment
id: coverage
run: |
# Output values to be used by other steps
echo "##[set-output name=path;]${BADGE_PATH}"
echo "##[set-output name=branch;]${BRANCH}"
env:
BADGE_PATH: ${{ steps.extract_branch.outputs.branch }}/coverage-badge.svg
BRANCH: badges
- uses: actions/checkout@v3
with:
ref: ${{ steps.coverage.outputs.branch }}
# Create the directory where badges will be saved, if needed
- name: Create destination directory
env:
BADGE_PATH: ${{ steps.coverage.outputs.path }}
run: mkdir -p "${BADGE_PATH%/*}"
# Use the output from the `coverage` step
- name: Generate the badge SVG image
id: badge
env:
COVERAGE: ${{ steps.pytest.outputs.coverage }}
COLOR: ${{ steps.pytest.outputs.color }}
BADGE_PATH: ${{ steps.coverage.outputs.path }}
run: curl "https://img.shields.io/badge/coverage-$COVERAGE%25-$COLOR" > ${BADGE_PATH}
- name: Upload badge as artifact
uses: actions/upload-artifact@v3
with:
name: badge
path: ${{ steps.coverage.outputs.path }}
if-no-files-found: error
- name: Commit badge
continue-on-error: true
env:
BADGE: ${{ steps.coverage.outputs.path }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add "${BADGE}"
git commit -m "Add/Update badge"
- name: Push badge commit
uses: ad-m/github-push-action@master
if: ${{ success() }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.coverage.outputs.branch }}