-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (113 loc) · 4.56 KB
/
generate-badges.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: generate-badges
on:
push:
branches: [ "main" ]
permissions:
contents: write
jobs:
generate-badges:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Fetch status from _badges
uses: actions/checkout@v4
with:
path: _badges
fetch-depth: 0
- name: Initialize storage branch
working-directory: _badges
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# Switch to the branch if it already exists
git switch _badges || true
git pull origin _badges || true
# Create the branch if it doesn't exist yet
git checkout --orphan _badges || true
# Ensure that the bare minimum components exist in the branch
mkdir -p data
touch README.md data/.gitkeep
# Copy necessary files and folders to a temporary location
mkdir -p /tmp/${{ github.sha }}
echo "Copying data to /tmp/${{ github.sha }}"
cp -r .git README.md data /tmp/${{ github.sha }}
# Remove everything else
# Attribution: https://unix.stackexchange.com/a/77313
rm -rf ..?* .[!.]* *
# Restore files from the temporary location
echo "Copying data from /tmp/${{ github.sha }}"
cp -r /tmp/${{ github.sha }}/.git /tmp/${{ github.sha }}/README.md /tmp/${{ github.sha }}/data .
rm -rf /tmp/${{ github.sha }}
git add --all -f
git commit -m "Update storage branch: $(date)" || true
shell: bash
- name: Push storage branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: _badges
directory: _badges
force: true
- name: Get flake8 status
id: flake8_status
run: |
poetry run flake8 src/ && echo "status=passing" >> $GITHUB_OUTPUT || echo "status=failing" >> $GITHUB_OUTPUT
- name: Generate the flake8 badge SVG image
uses: emibcn/[email protected]
id: flake8_badge
with:
label: 'Flake8'
status: "${{ steps.flake8_status.outputs.status }}"
color: ${{ steps.flake8_status.outputs.status == 'passing' && 'green' || 'red' }}
path: _badges/data/flake8_badge.svg
- name: Get complexity check status
id: complexity_check_status
run: |
poetry run flake8 --max-complexity 10 src/ && echo "status=passing" >> $GITHUB_OUTPUT || echo "status=failing" >> $GITHUB_OUTPUT
- name: Generate the complexity check badge SVG image
uses: emibcn/[email protected]
id: complexity_check_badge
with:
label: 'Cyclomatic complexity'
status: "${{ steps.complexity_check_status.outputs.status }}"
color: ${{ steps.complexity_check_status.outputs.status == 'passing' && 'green' || 'red' }}
path: _badges/data/cyclomatic_complexity.svg
- name: Get bandit status
id: bandit_status
run: |
poetry run bandit -c bandit.yaml -r src/ && echo "status=passing" >> $GITHUB_OUTPUT || echo "status=failing" >> $GITHUB_OUTPUT
- name: Generate the bandit badge SVG image
uses: emibcn/[email protected]
id: bandit_badge
with:
label: 'Bandit'
status: "${{ steps.bandit_status.outputs.status }}"
color: ${{ steps.bandit_status.outputs.status == 'passing' && 'green' || 'red' }}
path: _badges/data/bandit_badge.svg
- name: Commit badges
working-directory: _badges/data
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git switch _badges || true
git pull origin _badges
git add "bandit_badge.svg"
git add "flake8_badge.svg"
git add "cyclomatic_complexity.svg"
git commit -m "Add/Update badge: ${{ github.sha }}" || true
shell: bash
- name: Push badges
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: _badges
directory: _badges/data