|
| 1 | +# This template is taken from the cruft example code, for further information please see: |
| 2 | +# https://cruft.github.io/cruft/#automating-updates-with-github-actions |
| 3 | +name: Automatic Update from package template |
| 4 | +permissions: |
| 5 | + contents: write |
| 6 | + pull-requests: write |
| 7 | + |
| 8 | +on: |
| 9 | + # Allow manual runs through the web UI |
| 10 | + workflow_dispatch: |
| 11 | + schedule: |
| 12 | + # ┌───────── minute (0 - 59) |
| 13 | + # │ ┌───────── hour (0 - 23) |
| 14 | + # │ │ ┌───────── day of the month (1 - 31) |
| 15 | + # │ │ │ ┌───────── month (1 - 12 or JAN-DEC) |
| 16 | + # │ │ │ │ ┌───────── day of the week (0 - 6 or SUN-SAT) |
| 17 | + - cron: '0 7 * * 1' # Every Monday at 7am UTC |
| 18 | + |
| 19 | +jobs: |
| 20 | + update: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + strategy: |
| 23 | + fail-fast: true |
| 24 | + matrix: |
| 25 | + include: |
| 26 | + - add-paths: . |
| 27 | + body: apply the changes to this repo. |
| 28 | + branch: cruft/update |
| 29 | + commit-message: "Automatic package template update" |
| 30 | + title: Updates from the package template |
| 31 | + - add-paths: .cruft.json |
| 32 | + body: reject these changes for this repo. |
| 33 | + branch: cruft/reject |
| 34 | + commit-message: "Reject this package template update" |
| 35 | + title: Reject new updates from package template |
| 36 | + |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: "3.11" |
| 43 | + |
| 44 | + - name: Install Cruft |
| 45 | + run: python -m pip install cruft |
| 46 | + |
| 47 | + - name: Check if update is available |
| 48 | + continue-on-error: false |
| 49 | + id: check |
| 50 | + run: | |
| 51 | + CHANGES=0 |
| 52 | + if [ -f .cruft.json ]; then |
| 53 | + if ! cruft check; then |
| 54 | + CHANGES=1 |
| 55 | + fi |
| 56 | + else |
| 57 | + echo "No .cruft.json file" |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" |
| 61 | +
|
| 62 | + - name: Run update if available |
| 63 | + if: steps.check.outputs.has_changes == '1' |
| 64 | + run: | |
| 65 | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" |
| 66 | + git config --global user.name "${{ github.actor }}" |
| 67 | +
|
| 68 | + cruft update --skip-apply-ask --refresh-private-variables |
| 69 | + git restore --staged . |
| 70 | +
|
| 71 | + - name: Create pull request |
| 72 | + if: steps.check.outputs.has_changes == '1' |
| 73 | + uses: peter-evans/create-pull-request@v6 |
| 74 | + with: |
| 75 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + add-paths: ${{ matrix.add-paths }} |
| 77 | + commit-message: ${{ matrix.commit-message }} |
| 78 | + branch: ${{ matrix.branch }} |
| 79 | + delete-branch: true |
| 80 | + branch-suffix: timestamp |
| 81 | + title: ${{ matrix.title }} |
| 82 | + body: | |
| 83 | + This is an autogenerated PR, which will ${{ matrix.body }}. |
| 84 | + [Cruft](https://cruft.github.io/cruft/) has detected updates from the Package Template |
0 commit comments