Repository navigation
133 lines (120 loc) · 5.34 KB
/
Copy pathtrigger-template-update.yml
File metadata and controls
133 lines (120 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Update Child Repository Template
on:
release:
types: [published, released]
push:
tags:
- "v*"
workflow_dispatch:
inputs:
target_repository:
description: "Target repository to update (default: mjun0812/python-project-template)"
required: false
default: "mjun0812/python-project-template"
jobs:
update-child-template:
runs-on: ubuntu-latest
steps:
- name: Checkout child repository
uses: actions/checkout@v7
with:
repository: ${{ github.event.inputs.target_repository || 'mjun0812/python-project-template' }}
token: ${{ secrets.CHILD_REPO_TOKEN }}
path: child-repo
- name: Install uv
uses: astral-sh/setup-uv@v10.3.0
- name: Resolve template version
id: version
env:
# The Release workflow creates the release with GITHUB_TOKEN, and
# GitHub does not start workflow runs from events raised by that
# token, so the release trigger only fires for a release published by
# hand. A tag push has no release context and must name itself.
RELEASE_TAG: ${{ github.event.release.tag_name }}
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
RUN_NUMBER: ${{ github.run_number }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
run: |
if [ -n "${RELEASE_TAG}" ]; then
version="${RELEASE_TAG}"
elif [ "${REF_TYPE}" = "tag" ]; then
version="${REF_NAME}"
else
version="latest"
fi
echo "value=${version}" >> "$GITHUB_OUTPUT"
# A manual run has no version to name its branch after, so fall back
# to the run number to keep branches from colliding, and link no
# release notes because there is no release to point at.
if [ "${version}" = "latest" ]; then
echo "slug=${RUN_NUMBER}" >> "$GITHUB_OUTPUT"
else
echo "slug=${version}" >> "$GITHUB_OUTPUT"
echo "release_url=${SERVER_URL}/${REPOSITORY}/releases/tag/${version}" >> "$GITHUB_OUTPUT"
fi
- name: Update template in child repository
id: update
working-directory: child-repo
run: |
# Update from template. --defaults answers prompts added since the
# child repository was last updated; without it Copier would try to
# ask interactively and fail.
uvx copier update -A --defaults --trust
# Copier writes conflicting files with inline markers and leaves them
# unmerged in the index, which stops the pull request action from
# creating its branch. Stage them so the pull request is still opened,
# and describe them so the markers are resolved before it is merged.
conflicts="$(git diff --name-only --diff-filter=U)"
if [ -n "${conflicts}" ]; then
echo "conflicts=true" >> "$GITHUB_OUTPUT"
{
echo "conflict_note<<CONFLICT_NOTE_EOF"
echo "### Conflicts to resolve"
echo
echo "Copier could not merge these files. They are committed with conflict markers"
echo '(`<<<<<<<`, `=======`, `>>>>>>>`); resolve every marker before merging.'
echo
echo "${conflicts}" | sed 's/^/- `/; s/$/`/'
echo "CONFLICT_NOTE_EOF"
} >> "$GITHUB_OUTPUT"
echo "${conflicts}" | sed 's/^/::warning::Conflict left for manual resolution in /'
git add -A
else
echo "conflicts=false" >> "$GITHUB_OUTPUT"
fi
- name: Check for changes
id: changes
working-directory: child-repo
run: |
# git diff alone would miss an update that only adds files, because
# those stay untracked until the pull request action commits them.
if [ -z "$(git status --porcelain)" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.CHILD_REPO_TOKEN }}
path: child-repo
commit-message: |
Update template to version ${{ steps.version.outputs.value }}
title: "Update template to version ${{ steps.version.outputs.value }}${{ steps.update.outputs.conflicts == 'true' && ' (resolve conflicts)' || '' }}"
body: |
## Template Update
This PR updates the project template to version `${{ steps.version.outputs.value }}`.
### Changes
- Updated from template: ${{ github.repository }}
- Template version: ${{ steps.version.outputs.value }}
${{ steps.version.outputs.release_url && format('- Release notes: {0}', steps.version.outputs.release_url) || '' }}
${{ steps.update.outputs.conflict_note }}
### Testing
Please review the changes and test the updated template before merging.
---
*This PR was automatically created by the template update workflow.*
branch: template-update-${{ steps.version.outputs.slug }}
delete-branch: true