Skip to content

Update repo with copier #19

Update repo with copier

Update repo with copier #19

Workflow file for this run

name: Update repo with copier
on:
schedule:
- cron: "0 6 * * 1" # Every Monday at 6am
workflow_dispatch:
inputs:
automerge:
description: "enable automerge"
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
env:
COPIER_OPTIONS: "--trust -A -r main -c 3"
AUTOMERGE: "false"
jobs:
update:
name: Update template
runs-on: ubuntu-latest
environment:
name: pull-request
strategy:
fail-fast: true
matrix:
include:
- add-paths: .
body: Use this to merge the changes to this repository.
branch: copier/update
commit-message: "chore(template): accept new copier update"
title: "chore(template): accept new copier update"
# - add-paths: .copier-answers.yml
# body: Use this to reject the changes to this repository.
# branch: copier/reject
# commit-message: "chore(template): reject new copier update"
# title: "chore(template): reject new copier update"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- uses: ./.github/actions/setup-cached-uv-and-python
with:
python-version-file: ".python-version"
cache-dependency-path: requirements/lock/uvx-tools.txt
- name: Install copier
run:
uv tool install -crequirements/lock/uvx-tools.txt --with
copier-template-extensions copier
- name: Copier update
continue-on-error: false
id: check
env:
commit_message_in: ${{ matrix.commit-message }}
run: |
changed='false'
conflict_message=''
commit_message="$commit_message_in"
automergeable='true'
if [ -f .copier-answers.yml ]; then
copier update ${{ env.COPIER_OPTIONS }}
if ! git diff --quiet -- .copier-answers.yml; then
changed='true'
fi
else
echo "No .copier-answers.yml file"
exit 1
fi
# determine if have any merge conflicts
if [ "$changed" = "true" ]; then
if ! git merge --no-commit --no-ff; then
automergeable='false'
conflict_message="Resolve conflicts."
commit_message="$commit_message [skip ci]"
# check for new untracked files
elif git status --porcelain | grep -q '^??'; then
automergeable='false'
fi
fi
echo "automergeable=$automergeable" >> "$GITHUB_OUTPUT"
echo "changed=$changed" >> "$GITHUB_OUTPUT"
echo "conflict_message=$conflict_message" >> "$GITHUB_OUTPUT"
echo "commit_message=$commit_message" >> "$GITHUB_OUTPUT"
echo "files_changed<<EOF" >> "$GITHUB_OUTPUT"
git status --short | sort >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
# git config
if [ "$changed" = "true" ]; then
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git restore --staged .
fi
shell: bash -eux {0}
- name: Create pull request
if: steps.check.outputs.changed == 'true'
id: cpr
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
token: ${{ secrets.PAT }}
add-paths: ${{ matrix.add-paths }}
commit-message: ${{ steps.check.outputs.commit_message }}
title: ${{ matrix.title }}
labels: |
internal
template_update
branch: ${{ matrix.branch }}
delete-branch: true
# branch-suffix: timestamp # If want commit per run (instead of per workflow)
body: |
This is an autogenerated PR. ${{ matrix.body }} ${{ steps.check.outputs.conflict_message }}
Files changed (`git status --short`):
${{ steps.check.outputs.files_changed }}
[copier](https://github.com/copier-org/copier) has detected updates from the Cookiecutter repository.
- name: Pull request info
if: ${{ steps.cpr.outputs.pull-request-number }}
env:
NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
URL: ${{ steps.cpr.outputs.pull-request-url }}
OPERATION: ${{ steps.cpr.outputs.pull-request-operation }}
SHA: ${{ steps.cpr.outputs.pull-request-sha }}
BRANCH: ${{ steps.cpr.outputs.pull-request-branch }}
VERIFIED: ${{ steps.cpr.outputs.pull-request-commits-verified }}
run: |
echo "Pull Request Number - $NUMBER"
echo "Pull Request URL - $URL"
echo "Pull Request Operation - $OPERATION"
echo "Pull Request SHA - $SHA"
echo "Pull Request BRANCH - $BRANCH"
echo "Pull Request VERIFIED - $VERIFIED"
- name: automerge
if:
${{ (inputs.automerge || env.AUTOMERGE == 'true') &&
steps.cpr.outputs.pull-request-number &&
steps.check.outputs.conflict_message == '' &&
steps.check.outputs.automergeable == 'true' }}
env:
NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
# Need PAT if want to start other actions. Use GITHUB_TOKEN if not.
GH_TOKEN: ${{ secrets.PAT }}
run: |
gh pr merge -m --auto "$NUMBER"