Repository navigation
Expand file tree
/
Copy pathsyncweaver-host-contribute-patch.yml
More file actions
191 lines (172 loc) · 7.4 KB
/
Copy pathsyncweaver-host-contribute-patch.yml
File metadata and controls
191 lines (172 loc) · 7.4 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: syncweaver-contribute-patch
on:
workflow_dispatch:
inputs:
source_path:
description: Optional tracked source path override; if omitted, source_path is resolved from lockfile.
required: false
type: string
repo_url:
description: Optional source repository identifier (URL or OWNER/REPO) used to resolve source_path from lockfile.
required: false
type: string
source_repository:
description: Optional source repository in OWNER/REPO format; if omitted, derives from lockfile repo_url.
required: false
type: string
lockfile:
description: Path to the syncweaver lockfile.
required: false
default: .syncweaver-lock.json
type: string
patch_path:
description: Optional patch path override; if omitted, uses source entry patch value from lockfile.
required: false
type: string
source_base_ref:
description: Optional source repository base branch for PR; if omitted, uses source entry ref from lockfile.
required: false
type: string
syncweaver-version:
description: syncweaver version/ref to install (e.g. version tag, branch name, or commit SHA). Will use docker image if available.
required: false
type: string
default: main
permissions:
contents: read
jobs:
resolve-patch-metadata:
runs-on: ubuntu-latest
outputs:
source_path: ${{ steps.resolve.outputs.source_path }}
repo_url: ${{ steps.resolve.outputs.repo_url }}
source_repository: ${{ steps.resolve.outputs.source_repository }}
patch_path: ${{ steps.resolve.outputs.patch_path }}
source_base_ref: ${{ steps.resolve.outputs.source_base_ref }}
lockfile: ${{ env.LOCKFILE }}
env:
SOURCE_PATH: ${{ github.event.inputs.source_path || '' }}
REPO_URL: ${{ github.event.inputs.repo_url || '' }}
SOURCE_REPOSITORY: ${{ github.event.inputs.source_repository || '' }}
LOCKFILE: ${{ github.event.inputs.lockfile || '.syncweaver-lock.json' }}
PATCH_PATH: ${{ github.event.inputs.patch_path || '' }}
SOURCE_BASE_REF: ${{ github.event.inputs.source_base_ref || '' }}
SYNCWEAVER_VERSION: ${{ github.event.inputs['syncweaver-version'] || github.event.client_payload['syncweaver-version'] || 'main' }}
steps:
- name: Checkout host repository
uses: actions/checkout@v6
- name: Setup syncweaver
uses: CCBR/syncweaver/actions/setup-syncweaver@main
with:
syncweaver-version: ${{ env.SYNCWEAVER_VERSION }}
- name: Resolve source and patch metadata
id: resolve
shell: bash
env:
SOURCE_PATH_INPUT: ${{ env.SOURCE_PATH }}
REPO_URL_INPUT: ${{ env.REPO_URL }}
SOURCE_REPOSITORY_INPUT: ${{ env.SOURCE_REPOSITORY }}
LOCKFILE_PATH: ${{ env.LOCKFILE }}
PATCH_PATH_INPUT: ${{ env.PATCH_PATH }}
SOURCE_BASE_REF_INPUT: ${{ env.SOURCE_BASE_REF }}
SYNCWEAVER_HOST_CWD: ${{ github.workspace }}
run: |
set -euo pipefail
syncweaver-python -m syncweaver.contribute_patch
- name: Print resolved metadata
shell: bash
run: |
set -euo pipefail
echo "source_path=${{ steps.resolve.outputs.source_path }}"
echo "repo_url=${{ steps.resolve.outputs.repo_url }}"
echo "source_repository=${{ steps.resolve.outputs.source_repository }}"
echo "patch_path=${{ steps.resolve.outputs.patch_path }}"
echo "source_base_ref=${{ steps.resolve.outputs.source_base_ref }}"
contribute-patch:
runs-on: ubuntu-latest
needs: resolve-patch-metadata
permissions:
contents: read
env:
SOURCE_PATH: ${{ needs.resolve-patch-metadata.outputs.source_path }}
REPO_URL: ${{ needs.resolve-patch-metadata.outputs.repo_url }}
SOURCE_REPOSITORY: ${{ needs.resolve-patch-metadata.outputs.source_repository }}
PATCH_PATH: ${{ needs.resolve-patch-metadata.outputs.patch_path }}
SOURCE_BASE_REF: ${{ needs.resolve-patch-metadata.outputs.source_base_ref }}
LOCKFILE: ${{ needs.resolve-patch-metadata.outputs.lockfile }}
steps:
- name: Generate CCBR-bot token
id: ccbr_bot
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CCBR_BOT_APP_ID }}
private-key: ${{ secrets.CCBR_BOT_PRIVATE_KEY }}
- name: Checkout host repository
uses: actions/checkout@v6
with:
path: host
- name: Checkout source repository
uses: actions/checkout@v6
with:
repository: ${{ env.SOURCE_REPOSITORY }}
ref: ${{ env.SOURCE_BASE_REF }}
token: ${{ steps.ccbr_bot.outputs.token }}
path: source
- name: Apply patch to source repository
id: apply_patch
shell: bash
run: |
set -euo pipefail
patch_file="$GITHUB_WORKSPACE/host/${PATCH_PATH}"
if [[ ! -f "$patch_file" ]]; then
echo "Error: patch file not found in host repository: ${PATCH_PATH}" >&2
exit 1
fi
branch_stub=$(printf '%s' "$SOURCE_PATH" | tr '/ ' '--' | tr -cd '[:alnum:]._-')
if [[ -z "$branch_stub" ]]; then
branch_stub="patch"
fi
branch_name="syncweaver/contribute-patch/${branch_stub}-${GITHUB_RUN_ID}"
cd "$GITHUB_WORKSPACE/source"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$branch_name"
if ! git apply --3way --whitespace=nowarn "$patch_file"; then
echo "Error: patch failed to apply cleanly to ${SOURCE_REPOSITORY}@${SOURCE_BASE_REF}" >&2
exit 1
fi
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
echo "branch_name=$branch_name" >> "$GITHUB_OUTPUT"
- name: Open pull request in source repository
if: steps.apply_patch.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.ccbr_bot.outputs.token }}
path: source
base: ${{ env.SOURCE_BASE_REF }}
branch: ${{ steps.apply_patch.outputs.branch_name }}
delete-branch: true
commit-message: "chore(syncweaver): apply host patch for ${{ env.SOURCE_PATH }}"
title: "chore(syncweaver): apply host patch for ${{ env.SOURCE_PATH }}"
body: |
Automated patch contribution from host repository workflow dispatch.
Inputs used:
- source_path: ${{ env.SOURCE_PATH }}
- repo_url: ${{ env.REPO_URL }}
- source_repository: ${{ env.SOURCE_REPOSITORY }}
- source_base_ref: ${{ env.SOURCE_BASE_REF }}
- patch_path: ${{ env.PATCH_PATH }}
- lockfile: ${{ env.LOCKFILE }}
Trigger context:
- host_repository: ${{ github.repository }}
- workflow_run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Print no-op summary
if: steps.apply_patch.outputs.has_changes == 'false'
shell: bash
run: |
set -euo pipefail
echo "Patch applied cleanly but introduced no source changes. No PR created."