Pre-commit auto-update #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pre-commit auto-update | |
on: | |
schedule: | |
# Cron syntax: | |
# 1. Entry: Minute when the process will be started [0-60] | |
# 2. Entry: Hour when the process will be started [0-23] | |
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31] | |
# 4. Entry: Month of the year when the process will be started [1-12] | |
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday] | |
- cron: '0 8 * * 3' | |
# Allow manual triggering of the workflow | |
workflow_dispatch: | |
env: | |
UP_TO_DATE: false | |
PYTHON_VERSION: "3.13" | |
REVIEWERS: "altheaden,xylar,andrewdnolan" | |
jobs: | |
auto-update: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Set up Conda Environment | |
uses: mamba-org/setup-micromamba@v2 | |
with: | |
environment-name: pre_commit_dev | |
init-shell: bash | |
condarc: | | |
channel_priority: strict | |
channels: | |
- conda-forge | |
create-args: >- | |
python=${{ env.PYTHON_VERSION }} | |
- name: Install pre-commit and gh | |
run: | | |
eval "$(micromamba shell hook --shell bash)" | |
micromamba activate pre_commit_dev | |
# permissions issue with gh 2.76.0 | |
conda install -y pre-commit "gh !=2.76.0" | |
gh --version | |
- name: Apply and commit updates | |
run: | | |
eval "$(micromamba shell hook --shell bash)" | |
micromamba activate pre_commit_dev | |
git clone https://github.com/MPAS-Dev/MPAS-Tools.git update-pre-commit-deps | |
cd update-pre-commit-deps | |
# Configure git using GitHub Actions credentials. | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git checkout -b update-pre-commit-deps | |
pre-commit autoupdate | |
git add . | |
# The second command will fail if no changes were present, so we ignore it | |
git commit -m "Update pre-commit dependencies" || ( echo "UP_TO_DATE=true" >> "$GITHUB_ENV") | |
- name: Push Changes | |
if: ${{ env.UP_TO_DATE == 'false' }} | |
uses: ad-m/github-push-action@master | |
with: | |
branch: update-pre-commit-deps | |
directory: update-pre-commit-deps | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
force: true | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Make PR and add reviewers and labels | |
if: ${{ env.UP_TO_DATE == 'false' }} | |
run: | | |
cd update-pre-commit-deps | |
# Close any existing PR and replace with most up-to-date changes | |
gh pr close update-pre-commit-deps \ | |
--comment "This PR was closed to create a new, updated PR." || \ | |
echo "No existing PR to close and replace." | |
gh pr create \ | |
--title "Update pre-commit and its dependencies" \ | |
--body "This PR was auto-generated to update pre-commit and its dependencies." \ | |
--head update-pre-commit-deps \ | |
--reviewer ${{ env.REVIEWERS }} \ | |
--label ci | |
env: | |
GH_TOKEN: ${{ github.token }} | |