Update pre-commit
hooks
#232
Workflow file for this run
This file contains 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: CI - Check for updates to `requirements.txt` | |
on: | |
schedule: | |
# At 7:30 every Monday (6:30 UTC) | |
- cron: "30 6 * * 1" | |
workflow_dispatch: | |
push: | |
branches: | |
- "ci/update-dependencies" | |
env: | |
CHECKOUT_BRANCH: ci/dependabot-updates | |
GIT_USER_NAME: "TEAM 4.0[bot]" | |
GIT_USER_EMAIL: "[email protected]" | |
jobs: | |
update-requirements: | |
name: Update `requirements.txt` | |
if: github.repository_owner == 'EMMC-ASBL' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine checkout branch | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
echo "Push event detected." | |
echo "Changing CHECKOUT_BRANCH to: ${{ github.ref_name }}" | |
echo "CHECKOUT_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV | |
else | |
echo "Non-push event detected." | |
echo "Keeping default value for CHECKOUT_BRANCH: ${{ env.CHECKOUT_BRANCH }}" | |
fi | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.CHECKOUT_BRANCH }} | |
fetch-depth: 0 | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.9" | |
- name: Set up git config | |
run: | | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
- name: Install immediate requirements | |
run: | | |
python -m pip install -U pip | |
pip install -U setuptools wheel | |
pip install --no-cache-dir --upgrade-strategy=eager -U -r .github/utils/direct_requirements.txt | |
- name: Run `pip freeze` and update current `requirements.txt` | |
run: | | |
pip freeze > requirements_new.txt | |
if [ "$(diff requirements.txt requirements_new.txt)" ]; then | |
# There are updates ! | |
mv -f requirements_new.txt requirements.txt | |
echo -e "requirements.txt has been updated. Diff:\n$(git diff requirements.txt)" | |
echo "UPDATE_DEPS=true" >> $GITHUB_ENV | |
# Possibly also update the 'direct_requirements.txt' file for minimum versions. | |
while IFS= read -r line_direct; do | |
echo "line direct: ${line_direct}" | |
if [[ "${line_direct}" =~ ^([a-zA-Z_-]+)\>=.*$ ]]; then | |
package="${BASH_REMATCH[1]}" | |
echo "package: ${package}" | |
while IFS= read -r line_full; do | |
echo "line full: ${line_full}" | |
if [[ "${line_full}" =~ ^"${package}"==(.*)$ ]]; then | |
version="${BASH_REMATCH[1]}" | |
echo "version: ${version}" | |
sed -i "s|${package}>=.*|${package}>=${version}|" ".github/utils/direct_requirements.txt" | |
break | |
fi | |
done < requirements.txt | |
fi | |
done < .github/utils/direct_requirements.txt | |
git add requirements.txt | |
if [ -n "$(git status --porcelain .github/utils/direct_requirements.txt)" ]; then | |
git add .github/utils/direct_requirements.txt | |
fi | |
git commit -m "Update \`requirements.txt\`" | |
else | |
# No changes | |
echo "No changes found for requirements.txt." | |
echo "UPDATE_DEPS=false" >> $GITHUB_ENV | |
fi | |
- name: Fetch PR body | |
if: env.UPDATE_DEPS == 'true' | |
id: pr_body | |
uses: chuhlomin/[email protected] | |
with: | |
template: .github/utils/requirements_update_pr_body.txt | |
- name: Create PR | |
if: env.UPDATE_DEPS == 'true' | |
id: cpr | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.RELEASE_PAT }} | |
commit-message: "Update `requirements.txt`" | |
committer: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" | |
author: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" | |
branch: ci/update-requirements | |
delete-branch: true | |
title: "[Auto-generated] Update `requirements.txt`" | |
body: ${{ steps.pr_body.outputs.result }} | |
labels: CI/CD | |
- name: Information | |
if: env.UPDATE_DEPS == 'true' | |
run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"' |