-
Notifications
You must be signed in to change notification settings - Fork 82
133 lines (114 loc) · 5.19 KB
/
create-theme-submission.yml
File metadata and controls
133 lines (114 loc) · 5.19 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: Create Theme Submission PR
on:
issues:
types: [opened, edited, reopened]
workflow_dispatch:
inputs:
issue_number:
description: Issue number to process
required: true
type: number
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: theme-submission-${{ github.event.issue.number || inputs.issue_number }}
cancel-in-progress: true
jobs:
candidate_pull_request:
if: ${{ github.event_name == 'workflow_dispatch' || (!github.event.issue.pull_request && contains(github.event.issue.body, '### Theme title') && contains(github.event.issue.body, '### Original repository')) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- run: npm ci
- name: Load issue data
id: issue
env:
GH_TOKEN: ${{ github.token }}
EVENT_ISSUE_NUMBER: ${{ github.event.issue.number }}
INPUT_ISSUE_NUMBER: ${{ inputs.issue_number }}
shell: bash
run: |
issue_number="${EVENT_ISSUE_NUMBER:-$INPUT_ISSUE_NUMBER}"
if [ -z "$issue_number" ]; then
echo "::error::No issue number was provided."
exit 1
fi
gh issue view "$issue_number" --json title,body,author --jq .title > issue-title.txt
gh issue view "$issue_number" --json title,body,author --jq .body > issue-body.md
gh issue view "$issue_number" --json title,body,author --jq .author.login > issue-author.txt
{
echo "number=$issue_number"
echo "title<<EOF"
cat issue-title.txt
echo "EOF"
echo "author=$(cat issue-author.txt)"
} >> "$GITHUB_OUTPUT"
- name: Generate candidate entry
env:
ISSUE_NUMBER: ${{ steps.issue.outputs.number }}
ISSUE_TITLE: ${{ steps.issue.outputs.title }}
ISSUE_AUTHOR: ${{ steps.issue.outputs.author }}
ISSUE_BODY_FILE: issue-body.md
GITHUB_TOKEN: ${{ github.token }}
run: node scripts/create-theme-submission-from-issue.mjs
- run: npm test
- run: npm run build
- name: Open or update candidate PR
env:
GH_TOKEN: ${{ secrets.SUBMISSION_PR_TOKEN || github.token }}
ISSUE_NUMBER: ${{ steps.issue.outputs.number }}
ISSUE_AUTHOR: ${{ steps.issue.outputs.author }}
SUBMISSION_REVIEWERS: ${{ vars.SUBMISSION_REVIEWERS || 'Neikon' }}
shell: bash
run: |
branch="submissions/theme-${ISSUE_NUMBER}"
reviewers="${SUBMISSION_REVIEWERS:-Neikon}"
if [ -z "$(git status --porcelain -- src/content/themes public/assets/img/themes)" ]; then
echo "No theme submission changes were generated."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$branch"
git add src/content/themes public/assets/img/themes
git commit -m "feat: add candidate theme from issue #${ISSUE_NUMBER}"
git fetch --no-tags --depth=1 origin "$branch:refs/remotes/origin/$branch" || true
git push --force-with-lease origin "$branch"
manual_url="https://github.com/${GITHUB_REPOSITORY}/pull/new/${branch}"
title="Add candidate theme from issue #${ISSUE_NUMBER}"
open_pr_url="$(gh pr list --head "$branch" --state open --json url --jq '.[0].url // empty')"
if [ -n "$open_pr_url" ]; then
gh pr edit "$open_pr_url" \
--title "$title" \
--body-file theme-submission-pr.md
gh pr edit "$open_pr_url" --add-reviewer "$reviewers" || true
pr_url="$open_pr_url"
echo "Updated theme submission PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
else
if pr_url="$(gh pr create \
--base main \
--head "$branch" \
--title "$title" \
--body-file theme-submission-pr.md 2>pr-create-error.txt)"; then
gh pr edit "$branch" --add-reviewer "$reviewers" || true
echo "Created theme submission PR: ${pr_url}" >> "$GITHUB_STEP_SUMMARY"
else
echo "::warning::The submission branch was pushed, but GitHub refused to create the PR automatically."
cat pr-create-error.txt
{
echo "Theme submission changes were pushed to \`${branch}\`, but the workflow token could not create the PR automatically."
echo ""
echo "Open it manually: ${manual_url}"
echo ""
echo "To allow automatic PR creation, enable **Settings > Actions > General > Workflow permissions > Allow GitHub Actions to create and approve pull requests**, or add a \`SUBMISSION_PR_TOKEN\` secret with permission to create pull requests."
} >> "$GITHUB_STEP_SUMMARY"
pr_url="$manual_url"
fi
fi
gh issue comment "$ISSUE_NUMBER" --body "Thanks @${ISSUE_AUTHOR}. I generated a candidate submission PR for review: ${pr_url}"