-
-
Notifications
You must be signed in to change notification settings - Fork 537
60 lines (47 loc) · 1.71 KB
/
ok-to-preview.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
name: 🆗 Ok to preview
on:
pull_request_target:
types: [labeled]
jobs:
ok-to-preview:
if: ${{ github.event.label.name == 'ok-to-preview' }}
runs-on: ubuntu-latest
steps:
- name: Get changed files
#uses: lots0logs/[email protected]
uses: Mineflash07/gh-action-get-changed-files@feature/support-pr-target-event # Remove as soon as PR is merged
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get comment message
id: get-comment-message
run: |
import os, json, textwrap
all_files_path = os.path.join(os.environ["HOME"], "files.json")
event_json_path = os.environ["GITHUB_EVENT_PATH"]
with open(all_files_path) as f:
all_files = json.load(f)
with open(event_json_path) as f:
event_data = json.load(f)
links = [
"https://strawberry.rocks/docs/pr/{pr_number}/{path}".format(
pr_number=event_data["number"],
path=file.replace(".md", "").replace("docs/", "")
)
for file in all_files
if file.startswith("docs/") and file.endswith(".md")
]
message = textwrap.dedent(
"""
Hi 👋 You can find a preview of the docs here:
{links}
"""
).format(links="\n".join(links))
message = message.replace("%", "%25").replace("\n", "%0A").replace("\r", "%0D")
output = "::set-output name=message::{}".format(message)
print(output)
shell: python
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-message.outputs.message }}