-
Notifications
You must be signed in to change notification settings - Fork 1
93 lines (77 loc) · 2.45 KB
/
format_and_lint.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
name: Format and Lint
on:
push:
branches:
- main
pull_request:
permissions:
contents: write
jobs:
format:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install black isort
- name: Run Black and isort
run: |
black custom_components/sensus_analytics
isort custom_components/sensus_analytics
- name: Commit changes
id: commit_changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git commit -m "Auto-format code with Black and isort"; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Determine Branch to Push
id: determine_branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "branch=${GITHUB_HEAD_REF}" >> $GITHUB_OUTPUT
else
BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "branch=${BRANCH_NAME}" >> $GITHUB_OUTPUT
fi # Added 'fi' to close the if statement
- name: Push changes
if: steps.commit_changes.outputs.changes == 'true'
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.determine_branch.outputs.branch }}
lint:
needs: format
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bandit pylint
pip install -r requirements.txt
- name: Run Bandit Security Linter
run: bandit -r custom_components/sensus_analytics
- name: Run Pylint
run: pylint custom_components/sensus_analytics