Skip to content

Commit 17cdef1

Browse files
feat: ✨ add update-from-template workflow (#134)
# Description This PR adds the `update-from-template` workflows. Closes #108 This PR needs a quick review. ## Checklist - [x] Added or updated tests - [x] Updated documentation - [] Ran `just run-all` -- will fail because it depends on the latest version of `copier.yaml` --------- Co-authored-by: Luke W. Johnston <[email protected]>
1 parent f5cfa42 commit 17cdef1

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Update from template
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Every day at 3:30 at night.
7+
- cron: '30 3 * * *'
8+
9+
# Limit token permissions for security
10+
permissions: read-all
11+
12+
jobs:
13+
update-from-template:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
pull-requests: write
17+
steps:
18+
- name: Harden the runner (Audit all outbound calls)
19+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
20+
with:
21+
egress-policy: audit
22+
23+
- name: Check out repository
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
26+
- name: Install Python
27+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
28+
with:
29+
python-version: "3.13"
30+
31+
- name: Install dependencies
32+
run: |
33+
sudo apt install pipx
34+
pipx ensurepath
35+
pipx install uv rust-just copier
36+
37+
- name: Set User
38+
run: |
39+
git config user.name "github-actions[bot]"
40+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
41+
42+
- name: Pull request with updates from template
43+
run: |
44+
just update-from-template
45+
any_changes=$(git status --porcelain=v1 2>/dev/null | wc -l)
46+
if [ "$any_changes" -eq 0 ]; then
47+
echo "No updates from the template detected, and no changes found. Stopping and exiting."
48+
exit 0
49+
fi
50+
git checkout -b chore/update-from-template
51+
git add .
52+
git commit -m "chore(sync): :hammer: update changes from template"
53+
gh pr create \
54+
--title "chore(sync): :hammer: update changes from template" \
55+
--body "This PR is automatically generated by the 'update-from-template' workflow. It syncs the latest changes from the template repository with this repository."

template/justfile.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ build-contributors:
116116

117117
# Check for and apply updates from the template
118118
update-from-template:
119-
uvx copier update --trust --defaults
119+
# Do not update existing source files
120+
uvx copier update --trust --defaults $(find src/{{ github_repo_snake_case }} -type f -printf "--exclude %p ")
120121

121122
# Reset repo changes to match the template
122123
reset-from-template:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
2-
{{ dict(_copier_answers, copyright_year=copyright_year) | to_nice_yaml -}}
2+
{{ dict(_copier_answers, github_repo=github_repo, copyright_year=copyright_year) | to_nice_yaml -}}

0 commit comments

Comments
 (0)