-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scheduled workflow for cruft updates
- Loading branch information
1 parent
c2504ec
commit 8083301
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
{{cookiecutter.repostory_name}}/.github/workflows/cruft.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Update repository with Cruft | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
on: | ||
schedule: | ||
- cron: "0 2 * * 1" # Every Monday at 2am | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | ||
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install Cruft | ||
run: pip3 install cruft | ||
|
||
- 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 "Cruft Updater" | ||
cruft update --skip-apply-ask --refresh-private-variables | ||
git restore --staged . | ||
- name: Check for .rej files | ||
if: steps.check.outputs.has_changes == '1' | ||
id: check_rej | ||
run: | | ||
REJ_FILES=$(find . -name "*.rej") | ||
if [ -n "$REJ_FILES" ]; then | ||
echo "has_rej_files=1" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "has_rej_files=0" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Create pull request | ||
if: steps.check.outputs.has_changes == '1' | ||
id: create_pr | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
add-paths: . | ||
commit-message: "Apply new Cruft update" | ||
branch: cruft/update | ||
delete-branch: true | ||
title: Cruft cookiecutter update | ||
body: | | ||
This is an autogenerated PR. | ||
${{ steps.check_rej.outputs.has_rej_files == '1' && 'IMPORTANT: One or more `.rej` files have been detected, which means that some changes could not be applied automatically. Please RESOLVE them manually' || 'No conflicts detected' }} | ||
- name: Post to a Slack channel | ||
if: steps.create_pr.outputs.pull-request-number && env.SLACK_BOT_TOKEN | ||
uses: slackapi/[email protected] | ||
with: | ||
method: chat.postMessage | ||
token: ${{ env.SLACK_BOT_TOKEN }} | ||
payload: | | ||
channel: ${{ env.SLACK_CHANNEL_ID }} | ||
text: | | ||
<!here> cruft updates for `${{ github.repository }}`: | ||
${{ steps.create_pr.outputs.pull-request-url }} |