-
Notifications
You must be signed in to change notification settings - Fork 284
267 lines (229 loc) · 9.71 KB
/
project-page-pull-request.yml
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
name: Project Page Pull Request Creation
on:
issues:
types: [ labeled ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
if: github.event.label.name == 'project:create'
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Fetch the project issue info
id: project_issue
env:
GH_TOKEN: ${{ github.token }}
run: |
title=$(gh issue view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json title --jq '.title')
echo "title [$title]"
# If any, remove"Project:" prefix
title=$(echo "$title" | sed 's/^Project:\s*//')
echo "title [$title]"
echo "title=$title" >> $GITHUB_OUTPUT
- name: Find project issue comment
uses: peter-evans/find-comment@v2.4.0
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: Project Page Pull Request Creation
- name: Create or update comment ⌛
id: couc
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
body: |
## Project Page Pull Request Creation
:hourglass: **IN PROGRESS**: ![Project Page Pull Request Creation](${{ github.server_url }}/${{ github.repository }}/actions/workflows/project-page-pull-request.yml/badge.svg)
edit-mode: replace
- name: Extract event info
id: event_info
run: |
# TODO: Extract event name from "event:NAME" label
event_name="PW41_2024_MIT"
echo "name=$event_name" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- name: Generate project directory name
id: project_directory
run: |
title=$(echo ${{ steps.project_issue.outputs.title }})
echo "title [$title]"
# Convert to title case
title_cased=$(echo "$title" | sed 's/.*/\L&/; s/[a-z]*/\u&/g')
echo "title_cased [$title_cased]"
# Sanitize string to use as a directory name
directory_name=$(echo "$title_cased" | tr -cs '[:alnum:]' '_' | sed 's/_//g')
echo "directory_name [$directory_name]"
echo "name=$directory_name" >> $GITHUB_OUTPUT
- name: Check if project already exists
id: check_project_exists
run: |
event_name=${{ steps.event_info.outputs.name }}
project_directory=${{ steps.event_info.outputs.name }}/Projects/${{ steps.project_directory.outputs.name }}
if [ -d "$project_directory" ]; then
echo "::error::Project already exist"
exit 1
fi
- name: Create or update comment 🛑
if: ${{ failure() && steps.check_project_exists.outcome == 'failure' }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.couc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
body: |
## Project Page Pull Request Creation
:stop_sign: **STOPPED**: Project already exists
edit-mode: replace
- name: Create project directory
run: |
event_name=${{ steps.event_info.outputs.name }}
directory_name=${{ steps.project_directory.outputs.name }}
mkdir $event_name/Projects/$directory_name
- name: Bulk issue body
id: bulk
env:
GH_TOKEN: ${{ github.token }}
run: |
body=$(gh issue view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json body --jq '.body')
echo "$body" > ${{ runner.temp }}/bulk.txt
- name: Display bulk.txt
run: |
cat ${{ runner.temp }}/bulk.txt
- name: Split bulk
run: |
csplit ${{ runner.temp }}/bulk.txt \
'/^### Project Description/' \
'/^### Objective/' \
'/^### Approach and Plan/' \
'/^### Progress and Next Steps/' \
'/^### Illustrations/' \
'/^### Background and References/' \
-f ${{ runner.temp }}/project_pull_request_part_ -b "%02d.md"
- name: Cleanup files
run: |
cat ${{ runner.temp }}/project_pull_request_part_01.md | sed "1 d" > ${{ runner.temp }}/description.md
cat ${{ runner.temp }}/project_pull_request_part_02.md | sed "1 d" > ${{ runner.temp }}/objective.md
cat ${{ runner.temp }}/project_pull_request_part_03.md | sed "1 d" > ${{ runner.temp }}/approach.md
cat ${{ runner.temp }}/project_pull_request_part_04.md | sed "1 d" > ${{ runner.temp }}/progress.md
cat ${{ runner.temp }}/project_pull_request_part_05.md | sed "1 d" > ${{ runner.temp }}/illustrations.md
cat ${{ runner.temp }}/project_pull_request_part_06.md | sed "1 d" > ${{ runner.temp }}/background.md
- name: Display clean files
run: |
echo "Description:"
cat ${{ runner.temp }}/description.md
echo "Objective:"
cat ${{ runner.temp }}/objective.md
echo "Approach:"
cat ${{ runner.temp }}/approach.md
echo "Progress:"
cat ${{ runner.temp }}/progress.md
echo "Illustrations:"
cat ${{ runner.temp }}/illustrations.md
echo "Background:"
cat ${{ runner.temp }}/background.md
- name: Issue Forms Body Parser
id: parse
uses: zentered/issue-forms-body-parser@v2.0.0
- name: Extract issue fields
id: extract
run: |
echo ${{ toJSON(steps.parse.outputs.data) }} | \
jq --arg title "${{ steps.project_issue.outputs.title }}" \
--rawfile description "${{ runner.temp }}/description.md" \
--rawfile objective "${{ runner.temp }}/objective.md" \
--rawfile illustrations "${{ runner.temp }}/illustrations.md" \
--rawfile approach "${{ runner.temp }}/approach.md" \
--rawfile progress "${{ runner.temp }}/progress.md" \
--rawfile background "${{ runner.temp }}/background.md" '{
"title": $title,
"category": .category.text,
"presenter_location": .["presenter-location"].text,
"description": $description,
"objective": $objective,
"approach": $approach,
"progress": $progress,
"illustrations": $illustrations,
"background": $background,
"investigators": [.["key-investigators"].list[].text |
capture("(?<name>[^\\s]+(?:\\s[^\\s]+)*?)\\s*\\((?<affiliation>[^,]*)(?:,\\s*(?<country>[^)]*))?\\)") |
{name, affiliation: (.affiliation // ""), country: (.country // "")}],
}' > ${{ runner.temp }}/template-data.json
- name: Display template-data.json
run: |
cat ${{ runner.temp }}/template-data.json
- uses: actions/setup-python@v4.6.0
with:
python-version: "3.x"
- name: Install jinja2
run: |
python -m pip install jinja2
# Provide the cli interface
python -m pip install jinja2_cli
# Install the package providing the "to_yaml" and "regex_replace" filters.
python -m pip install jinja2-ansible-filters
- name: Generate Project README.md
run: |
jinja2 \
${{ steps.event_info.outputs.name }}/Projects/Template/README.md.j2 \
${{ runner.temp }}/template-data.json \
--format json \
-e "jinja2_ansible_filters.AnsibleCoreFiltersExtension" \
-o ${{ steps.event_info.outputs.name }}/Projects/${{ steps.project_directory.outputs.name }}/README.md
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.generate-token.outputs.token }}
commit-message: |
${{ steps.event_info.outputs.name }}: Add project ${{ steps.project_directory.outputs.name }}
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: ${{ steps.event_info.outputs.name }}/${{ steps.project_directory.outputs.name }}
delete-branch: true
title: Add project "${{ steps.project_issue.outputs.title }}" to "${{ steps.event_info.outputs.name }}"
body: |
Fixes #${{ github.event.issue.number }}
labels: |
project
event:${{ steps.event_info.outputs.name }}
- name: Create or update comment ❌
if: ${{ failure() && steps.check_project_exists.outcome == 'success' }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.couc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
body: |
## Project Page Pull Request Creation
:x: **FAILED**: See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace
- name: Create or update comment ✅
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.couc.outputs.comment-id }}
issue-number: ${{ github.event.issue.number }}
body: |
## Project Page Pull Request Creation
:white_check_mark: **COMPLETED**: See ${{ steps.cpr.outputs.pull-request-url }}
edit-mode: replace
- name: Remove "project:create" label
if: ${{ always() }}
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.payload.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["project:create"]
})