-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (107 loc) · 4.6 KB
/
improve.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
name: Improve code
on:
push:
branches-ignore:
- "main"
paths:
- "src/**/*.py"
pull_request:
types: [opened, synchronize]
paths:
- "src/**/*.py"
workflow_dispatch:
jobs:
commit_to_pr:
runs-on: ubuntu-latest
name: "Improve and format code"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Git Configuration
run: |
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git config core.autocrlf true
git config core.filemode false
- name: Fix code quality
uses: chartboost/ruff-action@v1
with:
src: "./src"
args: check --fix-only --unsafe-fixes --show-fixes
- name: Add changes code quality
run: git add **.py
- name: Check for changes code quality
run: |
if ! git diff --quiet --cached; then
echo "There are changes to commit."
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
id: check_changes_quality
- name: Commit changes code quality
if: steps.check_changes_quality.outputs.has_changes == 'true'
run: git commit -m "[ruff] Improve code quality"
- name: Fix code format
uses: chartboost/ruff-action@v1
with:
src: "./src"
args: format
- name: Add changes format
run: git add **.py
- name: Check for changes code quality
run: |
if ! git diff --quiet --cached; then
echo "There are changes to commit."
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
id: check_changes_format
- name: Commit code format
if: steps.check_changes_format.outputs.has_changes == 'true'
run: git commit -m "[ruff] Improve code format"
# Only in PR
- name: Push changes in pull request
if: ${{ github.event_name == 'pull_request' && (steps.check_changes_quality.outputs.has_changes == 'true' || steps.check_changes_format.outputs.has_changes == 'true') }}
run: |
git push origin HEAD:refs/heads/${{ github.ref_name }}
# Only in Push
- name: Check for existing pull request
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/pull') && (steps.check_changes_quality.outputs.has_changes == 'true' || steps.check_changes_format.outputs.has_changes == 'true') }}
run: |
if [[ $(gh pr list -s open -H auto-improve/${{ github.ref_name }}) ]]; then
gh pr close auto-improve/${{ github.ref_name }} -c "An other PR has been created"
fi
- name: Create Pull Request
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/pull') && (steps.check_changes_quality.outputs.has_changes == 'true' || steps.check_changes_format.outputs.has_changes == 'true') }}
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "[ruff] Auto improve format"
title: "[ruff] Auto improve format"
body: |
## Description
This PR implements an automated code formatting and quality improvement bot to enhance the codebase.
## Changes Made
- Integration of automated code formatting for consistent style and readability.
- Addition of static code analysis tools to identify and address potential issues.
- Implementation of pre-commit hooks to enforce coding standards.
## Benefits
- Improved code consistency and readability.
- Reduced manual effort for code formatting and quality checks.
- Enhanced code quality and stability.
## Checklist
- [ ] Verified the functionality of the modifications.
- [ ] Ensured the value addition of the modifications.
- [ ] Approved the PR after a thorough review.
Your feedback on the changes introduced by the code formatting and quality improvement bot is appreciated.
branch: auto-improve/${{ github.ref_name }}
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
# - name: Is the code quality good?
# uses: chartboost/ruff-action@v1
# with:
# src: "./src"
# args: check --show-source