-
-
Notifications
You must be signed in to change notification settings - Fork 33
150 lines (131 loc) · 5.65 KB
/
Copy pathscript-submission.yml
File metadata and controls
150 lines (131 loc) · 5.65 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
name: Script Submission — Create PR
on:
issues:
types: [labeled]
permissions:
contents: write
pull-requests: write
issues: write
jobs:
create-pr:
# Only run when a maintainer applies one of the two approval labels
if: |
github.event.label.name == 'add-to-gallery' ||
github.event.label.name == 'update-in-gallery'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v9.0.0
with:
enable-cache: false
- name: Write issue body to file
env:
ISSUE_BODY: ${{ github.event.issue.body }}
run: printf '%s' "$ISSUE_BODY" > /tmp/issue_body.txt
- name: Determine parser mode
id: mode
run: |
if [ "${{ github.event.label.name }}" = "add-to-gallery" ]; then
echo "value=insert" >> "$GITHUB_OUTPUT"
else
echo "value=patch" >> "$GITHUB_OUTPUT"
fi
- name: Parse issue and update scripts.json
id: parser
run: |
uv run tools/issue_to_scripts.py \
--issue-body /tmp/issue_body.txt \
--scripts-json scripts.json \
--mode ${{ steps.mode.outputs.value }}
- name: Validate scripts.json
run: uv run tools/validate_scripts.py --scripts-json scripts.json
- name: Sync issue template tags/categories
run: uv run tools/sync_issue_template_options.py --write
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create branch and commit
id: commit
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
MODE: ${{ steps.mode.outputs.value }}
run: |
BRANCH="add-script/${ISSUE_NUMBER}"
git checkout -b "$BRANCH"
git add scripts.json scripts.schema.json \
.github/ISSUE_TEMPLATE/add-script.yml \
.github/ISSUE_TEMPLATE/update-script.yml
VERB="Add"
if [ "$MODE" = "patch" ]; then VERB="Update"; fi
CLEAN_TITLE=$(echo "$ISSUE_TITLE" | sed -E 's/^\[Lua App (Submission|Update)\] *//')
git commit -m "feat(scripts): ${VERB} script from issue #${ISSUE_NUMBER}
${CLEAN_TITLE}
Closes #${ISSUE_NUMBER}"
git push origin "$BRANCH"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
- name: Open draft PR
uses: actions/github-script@v9
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
BRANCH: ${{ steps.commit.outputs.branch }}
MODE: ${{ steps.mode.outputs.value }}
with:
script: |
const issueNumber = parseInt(process.env.ISSUE_NUMBER);
const issueTitle = process.env.ISSUE_TITLE;
const branch = process.env.BRANCH;
const mode = process.env.MODE;
const verb = mode === "insert" ? "Add" : "Update";
const cleanTitle = issueTitle.replace(/^\[Lua App (?:Submission|Update)\]\s*/, "");
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `feat(scripts): ${verb} ${cleanTitle}`,
head: branch,
base: "main",
draft: true,
body: [
`Automated PR for script submission from issue #${issueNumber}.`,
"",
"### Checklist before merging",
"- [ ] Verify the `scripts.json` diff looks correct",
"- [ ] If any images are still external URLs, add the `localize-images` label to this PR to pull them into `ASSETS/` and update `scripts.json` automatically (or run `uv run tools/download_external_images.py` locally, using `--dry-run` to preview first)",
"- [ ] Remove draft status when ready to merge",
"",
`Closes #${issueNumber}`
].join("\n")
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `A draft PR has been created: ${pr.data.html_url}\n\nA maintainer will review before merging.`
});
- name: Post failure comment
if: always()
uses: actions/github-script@v9
with:
script: |
if ('${{ job.status }}' !== 'failure') return;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: [
"Automated PR creation failed. The submission could not be processed.",
"",
"Common reasons:",
"- A script with this name already exists in `scripts.json` (insert mode)",
"- The script name was not found in `scripts.json` (update mode)",
"- A required field was left blank",
"- No Category was selected and no New Category was provided",
"- The Info URL is missing or does not start with `http://` or `https://`",
"",
"Please check the [workflow run](" +
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions` +
") for details, then remove and re-apply the approval label after fixing the issue."
].join("\n")
});