Repository navigation
113 lines (96 loc) · 4.15 KB
/
Copy pathupdate-ruff.yml
File metadata and controls
113 lines (96 loc) · 4.15 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
106
107
108
109
110
111
112
113
name: Update Ruff Version Monthly
on:
schedule:
# Run on the 1st of every month at 00:00 UTC
- cron: '0 0 1 * *'
workflow_dispatch: # Allow manual triggering
jobs:
update-ruff:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Get latest ruff version
id: latest-version
run: |
LATEST_VERSION=$(curl -s https://pypi.org/pypi/ruff/json | jq -r '.info.version')
echo "RUFF_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
echo "Latest ruff version: $LATEST_VERSION"
# Get current ruff version from pyproject.toml
if grep -q "ruff==" pyproject.toml; then
CURRENT_VERSION=$(grep "ruff==" pyproject.toml | sed -E 's/.*ruff==([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "Current ruff version: $CURRENT_VERSION"
if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then
echo "Already using the latest version of ruff. No updates needed."
echo "NEEDS_UPDATE=false" >> $GITHUB_ENV
else
echo "NEEDS_UPDATE=true" >> $GITHUB_ENV
fi
else
echo "No ruff version found in pyproject.toml"
echo "NEEDS_UPDATE=true" >> $GITHUB_ENV
fi
- name: Update ruff version in pyproject.toml
if: env.NEEDS_UPDATE == 'true'
run: |
if grep -q "ruff==" pyproject.toml; then
sed -i -E "s/ruff==([0-9]+\.[0-9]+\.[0-9]+)/ruff==${{ env.RUFF_VERSION }}/" pyproject.toml
fi
- name: Update ruff version in prek.toml
if: env.NEEDS_UPDATE == 'true'
run: |
if grep -q "https://github.com/astral-sh/ruff-pre-commit" prek.toml; then
sed -i -E '/repo = "https:\/\/github.com\/astral-sh\/ruff-pre-commit"/,/^rev = / s/^rev = "v[0-9]+\.[0-9]+\.[0-9]+"/rev = "v${{ env.RUFF_VERSION }}"/' prek.toml
fi
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Run ruff format on the project
if: env.NEEDS_UPDATE == 'true'
run: |
# format
uvx ruff format .
- name: Run ruff check on the project
if: env.NEEDS_UPDATE == 'true'
continue-on-error: true
id: ruff-check
run: |
set +e
uvx ruff check --fix .
CHECK_RESULT=$?
set -e
if [ $CHECK_RESULT -ne 0 ]; then
echo "RUFF_CHECK_FAILED=true" >> $GITHUB_ENV
else
echo "RUFF_CHECK_FAILED=false" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.NEEDS_UPDATE == 'true'
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.GITHUB_TOKEN }}
# open in draft mode if ruff check failed
draft: ${{ env.RUFF_CHECK_FAILED }}
commit-message: "chore(deps-dev): update ruff from ${{ env.CURRENT_VERSION }} to ${{ env.RUFF_VERSION }}"
title: "chore(deps-dev): update ruff from ${{ env.CURRENT_VERSION }} to ${{ env.RUFF_VERSION }}"
body: |
## Ruff Version Update
This PR updates the ruff version from ${{ env.CURRENT_VERSION }} to ${{ env.RUFF_VERSION }}.
Changes:
- Updated version in `pyproject.toml`
- Updated version in `prek.toml`
- Ran `ruff format` on the codebase
${{ env.RUFF_CHECK_FAILED == 'true' && '- Attempted to run `ruff check --fix` on the codebase' || '- Ran `ruff check --fix` on the codebase' }}
${{ env.RUFF_CHECK_FAILED == 'true' && '⚠️ **WARNING**: `ruff check --fix` encountered errors during execution. A maintainer should run this command manually to complete the update process.' || '' }}
This PR was created automatically by a GitHub Actions workflow.
branch: chore-deps-update-ruff-${{ env.RUFF_VERSION }}
delete-branch: true
labels: |
dependencies
add-paths: |
pyproject.toml
prek.toml
**/*.py