Repository navigation
331 lines (294 loc) · 13.3 KB
/
Copy pathmove-to-main-repo.yaml
File metadata and controls
331 lines (294 loc) · 13.3 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
name: Move new Scripts to Main Repository
on:
workflow_dispatch:
issues:
types:
- labeled
permissions:
contents: write
issues: write
pull-requests: write
jobs:
move-to-main-repo:
runs-on: ubuntu-latest
if: >-
(github.event_name == 'workflow_dispatch' || github.event.label.name == 'Migration To ProxmoxVE') &&
github.repository == 'community-scripts/DevScripts'
steps:
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.GHAPP_SYNC_ID }}
private-key: ${{ secrets.GHAPP_SYNC_PRIVATE_KEY }}
owner: community-scripts
repositories: |
ProxmoxVE
DevScripts
- name: Checkout DevScripts (Source Repo)
uses: actions/checkout@v5
with:
ref: main
repository: community-scripts/DevScripts
token: ${{ secrets.GH_CROSS_REPO_TOKEN }}
- name: List Issues and Extract Script Type
id: list_issues
env:
GH_TOKEN: ${{ github.token }}
ISSUE_JSON: ${{ toJson(github.event.issue) }}
run: |
echo "Resolving issue with label Migration To ProxmoxVE"
if [[ "${{ github.event_name }}" == "issues" ]]; then
# For labeled issue events, use the exact issue from event payload.
filtered_issue="$ISSUE_JSON"
else
# Fallback for workflow_dispatch: query explicitly by label and raise limit.
raw_output=$(gh issue list \
--label "Migration To ProxmoxVE" \
--state open \
--limit 500 \
--json title,labels,number,body)
filtered_issue=$(echo "$raw_output" | jq -c '.[0]')
fi
if [[ "$filtered_issue" == "null" ]] || [[ -z "$filtered_issue" ]]; then
echo "No issues found with label 'Migration To ProxmoxVE'."
exit 1
fi
issue_title=$(echo "$filtered_issue" | jq -r '.title')
issue_nr=$(echo "$filtered_issue" | jq -r '.number')
issue_body=$(echo "$filtered_issue" | jq -r '.body')
# script_name (slug): from the "Name of the Script" field in the issue body,
# normalized to the repo's lowercase + spaces->dashes convention
# (e.g. "Alpine Cinny" -> "alpine-cinny"). Falls back to the title if absent.
name_raw=$(printf '%s\n' "$issue_body" \
| sed -n '/^###[[:space:]]*Name of the Script/,/^###/p' \
| sed '1d;/^###/d;/^[[:space:]]*$/d' | head -n1)
if [ -z "$name_raw" ]; then
name_raw="$issue_title"
fi
script_name=$(echo "$name_raw" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | sed 's/[[:space:]]\+/-/g')
if [[ ! "$script_name" =~ ^[a-z0-9][a-z0-9._-]*$ ]]; then
echo "::error::'Name of the Script' does not give a valid slug."
exit 1
fi
echo "Script Name: $script_name"
echo "Issue Title: $issue_title"
echo "Issue Number: $issue_nr"
# Detect script type from issue body
if echo "$issue_body" | grep -qi "CT (LXC Container)"; then
script_type="ct"
elif echo "$issue_body" | grep -qi "VM (Virtual Machine)"; then
script_type="vm"
elif echo "$issue_body" | grep -qi "Addon (tools/addon)"; then
script_type="addon"
elif echo "$issue_body" | grep -qi "PVE Tool (tools/pve)"; then
script_type="pve"
else
# Fallback detection by filename pattern
if [[ "$script_name" == *"-vm"* ]]; then
script_type="vm"
else
script_type="ct"
fi
fi
echo "Script Type: $script_type"
echo "script_name=$script_name" >> $GITHUB_OUTPUT
echo "issue_nr=$issue_nr" >> $GITHUB_OUTPUT
echo "script_type=$script_type" >> $GITHUB_OUTPUT
echo "issue_title=$issue_title" >> $GITHUB_OUTPUT
# A fixed delimiter could be closed from inside the issue body.
delim="EOF_$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')"
{
echo "issue_body<<$delim"
echo "$issue_body"
echo "$delim"
} >> $GITHUB_OUTPUT
- name: Check if script files exist
id: check_files
env:
script_name: ${{ steps.list_issues.outputs.script_name }}
script_type: ${{ steps.list_issues.outputs.script_type }}
run: |
files_found="true"
missing_files=""
# Check files based on script type
case "$script_type" in
ct)
if [[ ! -f "ct/${script_name}.sh" ]]; then
echo "ct file not found: ct/${script_name}.sh"
files_found="false"
missing_files+="ct/${script_name}.sh "
fi
if [[ ! -f "install/${script_name}-install.sh" ]]; then
echo "install file not found: install/${script_name}-install.sh"
files_found="false"
missing_files+="install/${script_name}-install.sh "
fi
;;
vm)
if [[ ! -f "vm/${script_name}.sh" ]]; then
echo "vm file not found: vm/${script_name}.sh"
files_found="false"
missing_files+="vm/${script_name}.sh "
fi
;;
addon)
if [[ ! -f "tools/addon/${script_name}.sh" ]]; then
echo "addon file not found: tools/addon/${script_name}.sh"
files_found="false"
missing_files+="tools/addon/${script_name}.sh "
fi
;;
pve)
if [[ ! -f "tools/pve/${script_name}.sh" ]]; then
echo "pve tool file not found: tools/pve/${script_name}.sh"
files_found="false"
missing_files+="tools/pve/${script_name}.sh "
fi
;;
esac
echo "files_found=$files_found" >> $GITHUB_OUTPUT
echo "missing=$missing_files" >> $GITHUB_OUTPUT
- name: Comment if not all Files found
if: steps.check_files.outputs.files_found == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
script_name: ${{ steps.list_issues.outputs.script_name }}
script_type: ${{ steps.list_issues.outputs.script_type }}
issue_nr: ${{ steps.list_issues.outputs.issue_nr }}
missing: ${{ steps.check_files.outputs.missing }}
run: |
gh issue comment "$issue_nr" --body "Not all required files were found for **$script_name** (type: $script_type). Please check the files and try again. Missing: $missing"
exit 1
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure Git User
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Prepare branch name
env:
script_name: ${{ steps.list_issues.outputs.script_name }}
run: |
timestamp=$(date +%s)
branch_name="add-script-${script_name//[^a-zA-Z0-9_-]/}-${timestamp}"
echo "Using branch: $branch_name"
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Clone ProxmoxVE and Copy Files
env:
script_name: ${{ steps.list_issues.outputs.script_name }}
script_type: ${{ steps.list_issues.outputs.script_type }}
issue_nr: ${{ steps.list_issues.outputs.issue_nr }}
APP_TOKEN: ${{ steps.app-token.outputs.token }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git clone "https://x-access-token:${APP_TOKEN}@github.com/community-scripts/ProxmoxVE.git" ProxmoxVE
cd ProxmoxVE
# Check if branch already exists remotely and delete it
if git ls-remote --exit-code --heads origin "$branch_name" >/dev/null 2>&1; then
echo "Branch $branch_name already exists remotely, deleting it..."
git push origin --delete "$branch_name" || true
fi
already_there() {
gh issue comment "$issue_nr" --repo community-scripts/DevScripts \
--body "Migration stopped: \`$1\` already exists in ProxmoxVE. Remove the \`Migration To ProxmoxVE\` label and move the changes over by hand."
exit 1
}
case "$script_type" in
ct)
[[ -f "ct/${script_name}.sh" ]] && already_there "ct/${script_name}.sh"
[[ -f "install/${script_name}-install.sh" ]] && already_there "install/${script_name}-install.sh"
;;
vm)
[[ -f "vm/${script_name}.sh" ]] && already_there "vm/${script_name}.sh"
;;
addon)
[[ -f "tools/addon/${script_name}.sh" ]] && already_there "tools/addon/${script_name}.sh"
;;
pve)
[[ -f "tools/pve/${script_name}.sh" ]] && already_there "tools/pve/${script_name}.sh"
;;
esac
git checkout -b "$branch_name"
# Copy files based on script type
case "$script_type" in
ct)
cp ../ct/${script_name}.sh ct/
cp ../install/${script_name}-install.sh install/
# var_testurl points at the testing issue in DevScripts. A script
# arriving here has finished testing, so the request goes away
# with it. This has to happen BEFORE the DevScripts -> ProxmoxVE
# rewrite below, which would otherwise turn the link into an
# issue number that does not exist in this repository.
sed -i '/^[[:space:]]*var_testurl=/d' ct/${script_name}.sh
# ProxmoxVE is the engine's default scripts base, so the pin goes.
sed -i '/^_CS_DEFAULT_URL=/d' ct/${script_name}.sh
# Update URLs in ct script
sed -i -E "s#community-scripts/(DevScripts|ProxmoxVED)#community-scripts/ProxmoxVE#g" ct/${script_name}.sh
sed -i -E "s#community-scripts/(DevScripts|ProxmoxVED)#community-scripts/ProxmoxVE#g" install/${script_name}-install.sh
;;
vm)
cp ../vm/${script_name}.sh vm/
# Update URLs in vm script
sed -i -E "s#community-scripts/(DevScripts|ProxmoxVED)#community-scripts/ProxmoxVE#g" vm/${script_name}.sh
;;
addon)
mkdir -p tools/addon
cp ../tools/addon/${script_name}.sh tools/addon/
# Update URLs in addon script
sed -i -E "s#community-scripts/(DevScripts|ProxmoxVED)#community-scripts/ProxmoxVE#g" tools/addon/${script_name}.sh
;;
pve)
mkdir -p tools/pve
cp ../tools/pve/${script_name}.sh tools/pve/
# Update URLs in pve script
sed -i -E "s#community-scripts/(DevScripts|ProxmoxVED)#community-scripts/ProxmoxVE#g" tools/pve/${script_name}.sh
;;
esac
git add . > /dev/null 2>&1
if git diff --cached --exit-code; then
echo "No changes detected, skipping commit."
exit 0
fi
git commit -m "Add ${script_name} (${script_type})"
- name: Push to ProxmoxVE
run: |
cd ProxmoxVE
git push --no-thin origin "$branch_name"
- name: Create Pull Request in ProxmoxVE
id: create_pull_request
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
ISSUE_TITLE: ${{ steps.list_issues.outputs.issue_title }}
ISSUE_BODY: ${{ steps.list_issues.outputs.issue_body }}
ISSUE_NR: ${{ steps.list_issues.outputs.issue_nr }}
run: |
# PR body = original issue content + automated-migration footer
printf '%s\n' "$ISSUE_BODY" > pr_body.md
{
echo ""
echo "---"
echo "Automated migration from DevScripts (community-scripts/DevScripts#${ISSUE_NR})."
} >> pr_body.md
gh pr create \
--repo community-scripts/ProxmoxVE \
--head "$branch_name" \
--base main \
--title "$ISSUE_TITLE" \
--body-file pr_body.md
PR_NUMBER=$(gh pr list --repo community-scripts/ProxmoxVE --head "$branch_name" --json number --jq '.[].number')
echo "PR_NUMBER=$PR_NUMBER"
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Comment on Issue
if: steps.create_pull_request.outputs.pr_number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
script_name: ${{ steps.list_issues.outputs.script_name }}
issue_nr: ${{ steps.list_issues.outputs.issue_nr }}
pr_number: ${{ steps.create_pull_request.outputs.pr_number }}
run: |
gh issue comment "$issue_nr" --body "A PR has been created for ${script_name}: community-scripts/ProxmoxVE#${pr_number}"
gh issue edit "$issue_nr" --remove-label "Migration To ProxmoxVE" --add-label "Started Migration To ProxmoxVE"