Update repository with Cruft #60
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: Update repository with Cruft | |
permissions: | |
contents: write | |
pull-requests: write | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 2 * * 1" # Every Monday at 2am | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
include: | |
- add-paths: . | |
body: Use this to merge the changes to this repository. | |
branch: cruft/update | |
commit-message: "chore: accept new Cruft update" | |
title: New updates detected with Cruft | |
- add-paths: .cruft.json | |
body: Use this to reject the changes in this repository. | |
branch: cruft/reject${{ github.run_id }} | |
commit-message: "chore: reject new Cruft update" | |
title: Reject new updates detected with Cruft | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.12" | |
- name: Install Cruft | |
run: pip3 install -r requirements-dev.txt | |
- name: Check if update is available | |
continue-on-error: false | |
id: check | |
run: | | |
CHANGES=0 | |
if [ -f .cruft.json ]; then | |
if ! cruft check; then | |
CHANGES=1 | |
fi | |
else | |
echo "No .cruft.json file" | |
fi | |
echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" | |
- name: Run update if available | |
if: steps.check.outputs.has_changes == '1' | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub" | |
cruft update --skip-apply-ask --refresh-private-variables | |
git restore --staged . | |
- name: Create pull request | |
if: steps.check.outputs.has_changes == '1' | |
run: | | |
echo "::set-output name=branch::${{ matrix.branch }}" | |
echo "::set-output name=commit-message::${{ matrix.commit-message }}" | |
git checkout -b "${{ matrix.branch }}" | |
git add ${{ matrix.add-paths }} | |
git commit -m "${{ matrix.commit-message }}" | |
git push origin "${{ matrix.branch }}" |