Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions .github/workflows/update-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ jobs:
run: |
sed -i "s/rev: .* # ruff version/rev: v${{ env.RUFF_VERSION }} # ruff version/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml

- name: Create new branch for changes
run: |
git checkout -b update-ruff-${{ env.RUFF_VERSION }}

- name: Commit and push changes
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update ruff version to ${{ env.RUFF_VERSION }}" || exit 0 # Exit gracefully if no changes
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-ruff-${{ env.RUFF_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update ruff version to ${{ env.RUFF_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-ruff-${{ env.RUFF_VERSION }}

- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "style(python): update ruff to ${{ env.RUFF_VERSION }}" \
--body "Automatically update the Ruff version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
Expand All @@ -66,8 +70,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update_precommit:
name: Update Python pre-commit version pins
update_precommit_and_hooks:
name: Update Python pre-commit version pins and hooks
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand All @@ -90,25 +94,29 @@ jobs:

- name: Update pre-commit version in pyproject.toml
run: |
sed -i "s/\"pre-commit==.*\"/\"pre-commit==${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
sed -i "s/\"pre-commit>=.*\"/\"pre-commit>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml

- name: Update min pre-commit version requirement in .pre-commit-config.yaml
run: |
sed -i "s/minimum_pre_commit_version: .*/minimum_pre_commit_version: ${{ env.PRECOMMIT_VERSION }}/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml

- name: Create new branch for changes
run: |
git checkout -b update-precommit-${{ env.PRECOMMIT_VERSION }}

- name: Commit and push changes
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update precommit version to ${{ env.PRECOMMIT_VERSION }}" || exit 0 # Exit gracefully if no changes
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-precommit-${{ env.PRECOMMIT_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update precommit to ${{ env.PRECOMMIT_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-precommit-${{ env.PRECOMMIT_VERSION }}

- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "cicd(python): update precommit to ${{ env.PRECOMMIT_VERSION }}" \
--body "Automatically update the pre-commit version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
Expand Down Expand Up @@ -142,19 +150,23 @@ jobs:
run: |
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

- name: Create new branch for changes
run: |
git checkout -b update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}

- name: Commit and push changes
- name: Create new branch, commit, and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update pre-commit-hooks version to ${{ env.PRECOMMIT_HOOKS_VERSION }}" || exit 0 # Exit gracefully if no changes
if git diff --quiet; then
echo "new_commits=false" >> $GITHUB_ENV
exit 0
else
git checkout -b update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
git add ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
git commit -m "Update pre-commit-hooks version to ${{ env.PRECOMMIT_HOOKS_VERSION }}"
echo "new_commits=true" >> $GITHUB_ENV
fi;
git push --set-upstream origin update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}

- name: Create pull request
if: env.new_commits == 'true'
run: |
gh pr create --title "cicd(python): update pre-commit-hooks to ${{ env.PRECOMMIT_HOOKS_VERSION }}" \
--body "Automatically update the pre-commit-hooks version in \`.pre-commit-config.yaml\`." \
Expand Down
5 changes: 4 additions & 1 deletion python/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ dynamic = ["version"]

[project.optional-dependencies]
tests = ["pytest", "pytest-cov"]
dev = ["pre-commit>=3.7.1", "ruff==0.8.6"]
dev = [
"pre-commit>=3.7.1",
"ruff==0.8.6",
]
{% if cookiecutter.add_docs %}
docs = [
"sphinx==6.1.3",
Expand Down
Loading