-
Notifications
You must be signed in to change notification settings - Fork 13
161 lines (135 loc) · 5.55 KB
/
update-cookbook-gallery.yaml
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
name: Update Cookbook Gallery
on:
issues:
types:
- opened
- edited
jobs:
validate-user-submission:
if: github.repository == 'ProjectPythia/cookbook-gallery' && github.event.issue.title == 'Update Gallery with new Cookbook'
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: Thank you for your contribution
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
Thank you for your contribution 🎉, @${{ github.actor }}!
We're currently running [validation checks](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) to make sure the contents of your submission are okay. An update will be posted here shortly once the validation checks are passing.
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
Thank you for your contribution 🎉, @${{ github.actor }}!
We're currently running [validation checks](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) to make sure the contents of your submission are okay. An update will be posted here shortly once the validation checks are passing.
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install pip --upgrade
python -m pip install python-frontmatter markdown-it-py pydantic[email]
- name: Validate input
run: |
python .github/workflows/collect-user-submission.py
- uses: actions/upload-artifact@v4
with:
name: submission
path: cookbook-submission-input.txt
create-pull-request:
needs: validate-user-submission
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- uses: actions/download-artifact@v4
with:
name: submission
- name: Display structure of downloaded artifacts
run: |
ls -R
- name: Install dependencies
run: |
python -m pip install pip --upgrade
python -m pip install ruamel.yaml pre-commit
- name: Update cookbook gallery
shell: python
run: |
from ruamel.yaml import YAML
yaml = YAML()
submission_file = 'cookbook-submission-input.txt'
cookbook_gallery_file = 'site/cookbook_gallery.txt'
with open(submission_file) as f:
repo = f.read().strip()
with open(cookbook_gallery_file) as f:
cookbook_gallery = f.readlines()
with open(cookbook_gallery_file, 'w') as f:
cookbook_gallery.append(repo)
f.writelines(cookbook_gallery)
- name: Run pre-commit hooks
run: |
python -m pre_commit run --all-files
exit 0
- uses: tibdex/github-app-token@v2
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@v6
with:
commit-message: 'Update cookbook gallery'
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
base: main
title: 'Update cookbook gallery per #${{ github.event.issue.number }}'
body: |
Update cookbook gallery as requested in #${{ github.event.issue.number }}. Closes #${{ github.event.issue.number }}.
token: ${{ steps.generate-token.outputs.token }}
branch: cookbook-gallery-${{ github.event.issue.number }}
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.issue.number }}
comment-author: 'github-actions[bot]'
body-includes: We've created a pull request on your behalf
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
@${{ github.actor }}, your submission looks great! We've created a pull request on your behalf using the information you provided.
The pull request can be accessed from this url: ${{ steps.cpr.outputs.pull-request-url }}.
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
@${{ github.actor }}, your submission looks great! We've created a pull request on your behalf using the information you provided.
The pull request can be accessed from this url: ${{ steps.cpr.outputs.pull-request-url }}.