-
Notifications
You must be signed in to change notification settings - Fork 5
159 lines (145 loc) · 5.64 KB
/
Copy pathupdate-copier.yml
File metadata and controls
159 lines (145 loc) · 5.64 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Update repo with copier
on:
schedule:
- cron: "0 2 * * 1" # Every Monday at 2am
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"