forked from adoptium/adoptium.net
-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (72 loc) · 3.96 KB
/
blog-post-helper.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
name: Blog Post Helper
on:
issues:
types: [opened, labeled]
jobs:
comment:
if: contains(github.event.issue.labels.*.name, 'draft-blog-post')
runs-on: ubuntu-latest
steps:
- name: Add comment
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: |
Thanks for starting a draft blog post! 🎉
You can use this issue to collaborate with others on your post. When you're ready to publish, remove the `draft-blog-post` label and add the `blog-post-ready` label.
stage:
if: contains(github.event.issue.labels.*.name, 'blog-post-ready')
runs-on: ubuntu-latest
steps:
- name: Extract issue body and title
id: extract
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const body = context.payload.issue.body;
const title = context.payload.issue.title;
return { body, title };
console.log(`Issue Title: ${title}`);
console.log(`Issue Body: ${body}`);
core.setOutput('body', body);
core.setOutput('title', title);
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Add markdown file to content/blog/${slug}/index.md
run: |
# generate slug from title
slug=$(echo "${{ steps.extract.outputs.title }}" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)
# create markdown file
mkdir content/blog/${slug}
echo "---" > content/blog/${slug}/index.md
echo "title: ${{ steps.extract.outputs.title }}" >> content/blog/${slug}/index.md
echo "date: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> content/blog/${slug}/index.md
echo "author: ${{ github.actor }}" >> content/blog/${slug}/index.md]
echo "description: set description here" >> content/blog/${slug}/index.md
echo "tags: []" >> content/blog/${slug}/index.md
echo "---" >> content/blog/${slug}/index.md
echo "" >> content/blog/${slug}/index.md
echo "${{ steps.extract.outputs.body }}" >> content/blog/${slug}/index.md
- name: Commit and push changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Add blog post: ${{ steps.extract.outputs.title }}"
git push
- name: Create pull request
uses: peter-evans/create-pull-request@284f54f989303d2699d373481a0cfa13ad5a6666 # v5.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Add blog post: ${{ steps.extract.outputs.title }}"
title: "Add blog post: ${{ steps.extract.outputs.title }}"
body: |
This pull request was automatically generated by the Blog Post Helper action.
closes: https://github.com/adoptium/adoptium.net/issues/${{ github.event.issue.number }}
- name: Add comment
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: |
Your blog post has been converted to a pull request. 🎉
See the pull request here: ${{ steps.create-pull-request.outputs.pull-request-url }}