Skip to content

Update Python template version pins #25

Update Python template version pins

Update Python template version pins #25

name: Update Python template version pins
on:
schedule:
- cron: '0 0 1 1,7 *'
env:
PYTHON_TEMPLATE_LOCATION: "python/{{cookiecutter.project_slug}}"
MIN_PYTHON_VERSION: "3.11" # use minimum supported python version
permissions:
contents: write
pull-requests: write
jobs:
update_ruff:
name: Update Python Ruff version pins
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Install latest Ruff
run: python3 -m pip install ruff
- name: Get latest ruff version
id: ruff-version
run: |
echo "RUFF_VERSION=$(pip show ruff | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
- name: Update Ruff Version in pyproject.toml
run: |
sed -i "s/\"ruff==.*\"/\"ruff==${{ env.RUFF_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
- name: Update Ruff version in .pre-commit-config.yaml
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
run: |
git config --local user.email "[email protected]"
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
git push --set-upstream origin update-ruff-${{ env.RUFF_VERSION }}
- name: Create pull request
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\`." \
--base main \
--head update-ruff-${{ env.RUFF_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_precommit:
name: Update Python pre-commit version pins
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Install latest pre-commit
run: python3 -m pip install pre-commit
- name: Get latest pre-commit version
id: precommit-version
run: |
echo "PRECOMMIT_VERSION=$(pip show pre-commit | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
- 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
- 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
run: |
git config --local user.email "[email protected]"
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
git push --set-upstream origin update-precommit-${{ env.PRECOMMIT_VERSION }}
- name: Create pull request
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\`." \
--base main \
--head update-precommit-${{ env.PRECOMMIT_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_precommit_hooks:
name: Update Python pre-commit-hooks version pins
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Get latest pre-commit-hooks version
run: |
latest_tag=$(curl -s https://api.github.com/repos/pre-commit/pre-commit-hooks/releases | jq -r '.[0].tag_name')
echo "PRECOMMIT_HOOKS_VERSION=$latest_tag" >> $GITHUB_ENV
- name: Update pre-commit-hooks version in .pre-commit-config.yaml
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
run: |
git config --local user.email "[email protected]"
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
git push --set-upstream origin update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }}
- name: Create pull request
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\`." \
--base main \
--head update-precommit-hooks-${{ env.PRECOMMIT_HOOKS_VERSION }} \
--reviewer "jsstevenson,korikuzma" \
--label "priority:low"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}