Skip to content

Commit 07cd3ff

Browse files
committed
maybe update precommit?
1 parent 3f458e3 commit 07cd3ff

File tree

1 file changed

+24
-49
lines changed

1 file changed

+24
-49
lines changed

.github/workflows/update-python.yaml

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ jobs:
5454
git commit -m "Update ruff version to ${{ env.RUFF_VERSION }}" || exit 0 # Exit gracefully if no changes
5555
git push --set-upstream origin update-ruff-${{ env.RUFF_VERSION }}
5656
57+
- name: Check if there are new commits
58+
id: check_commits
59+
run: |
60+
if git diff --quiet origin/main..; then
61+
echo "new_commits=false" >> $GITHUB_ENV
62+
else
63+
echo "new_commits=true" >> $GITHUB_ENV
64+
5765
- name: Create pull request
66+
if: env.new_commits == 'true'
5867
run: |
5968
gh pr create --title "style(python): update ruff to ${{ env.RUFF_VERSION }}" \
6069
--body "Automatically update the Ruff version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
@@ -65,8 +74,8 @@ jobs:
6574
env:
6675
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6776

68-
update_precommit:
69-
name: Update Python pre-commit version pins
77+
update_precommit_and_hooks:
78+
name: Update Python pre-commit version pins and hooks
7079
runs-on: ubuntu-latest
7180
steps:
7281
- name: Check out repository
@@ -89,12 +98,15 @@ jobs:
8998
9099
- name: Update pre-commit version in pyproject.toml
91100
run: |
92-
sed -i "s/\"pre-commit==.*\"/\"pre-commit==${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
101+
sed -i "s/\"pre-commit>=.*\"/\"pre-commit>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
93102
94103
- name: Update min pre-commit version requirement in .pre-commit-config.yaml
95104
run: |
96105
sed -i "s/minimum_pre_commit_version: .*/minimum_pre_commit_version: ${{ env.PRECOMMIT_VERSION }}/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
97106
107+
- name: Update pre-commit-hooks version requirement
108+
run: pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks
109+
98110
- name: Create new branch for changes
99111
run: |
100112
git checkout -b update-precommit-${{ env.PRECOMMIT_VERSION }}
@@ -107,7 +119,16 @@ jobs:
107119
git commit -m "Update precommit version to ${{ env.PRECOMMIT_VERSION }}" || exit 0 # Exit gracefully if no changes
108120
git push --set-upstream origin update-precommit-${{ env.PRECOMMIT_VERSION }}
109121
122+
- name: Check if there are new commits
123+
id: check_commits
124+
run: |
125+
if git diff --quiet origin/main..; then
126+
echo "new_commits=false" >> $GITHUB_ENV
127+
else
128+
echo "new_commits=true" >> $GITHUB_ENV
129+
110130
- name: Create pull request
131+
if: env.new_commits == 'true'
111132
run: |
112133
gh pr create --title "cicd(python): update precommit to ${{ env.PRECOMMIT_VERSION }}" \
113134
--body "Automatically update the pre-commit version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
@@ -117,49 +138,3 @@ jobs:
117138
--label "priority:low"
118139
env:
119140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120-
121-
update_precommit_hooks:
122-
name: Update Python pre-commit-hooks version pins
123-
runs-on: ubuntu-latest
124-
steps:
125-
- name: Check out repository
126-
uses: actions/checkout@v4
127-
with:
128-
fetch-depth: 0
129-
130-
- name: Set up Python
131-
uses: actions/setup-python@v5
132-
with:
133-
python-version: ${{ env.MIN_PYTHON_VERSION }}
134-
135-
- name: Get latest pre-commit-hooks version
136-
run: |
137-
latest_tag=$(curl -s https://api.github.com/repos/pre-commit/pre-commit-hooks/releases | jq -r '.[0].tag_name')
138-
echo "PRECOMMIT_HOOKS_VERSION=$latest_tag" >> $GITHUB_ENV
139-
140-
- name: Update pre-commit-hooks version in .pre-commit-config.yaml
141-
run: |
142-
sed -i "s/rev: .* # pre-commit-hooks version/rev: ${{ env.PRECOMMIT_HOOKS_VERSION }} # pre-commit-hooks version/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
143-
144-
- name: Create new branch for changes
145-
run: |
146-
git checkout -b update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
147-
148-
- name: Commit and push changes
149-
run: |
150-
git config --local user.email "[email protected]"
151-
git config --local user.name "GitHub Action"
152-
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
153-
git commit -m "Update pre-commit-hooks version to ${{ env.PRECOMMIT_HOOKS_VERSION }}" || exit 0 # Exit gracefully if no changes
154-
git push --set-upstream origin update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
155-
156-
- name: Create pull request
157-
run: |
158-
gh pr create --title "cicd(python): update pre-commit-hooks to ${{ env.PRECOMMIT_HOOKS_VERSION }}" \
159-
--body "Automatically update the pre-commit-hooks version in \`.pre-commit-config.yaml\`." \
160-
--base main \
161-
--head update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }} \
162-
--reviewer "jsstevenson,korikuzma" \
163-
--label "priority:low"
164-
env:
165-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)