-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (34 loc) · 1.25 KB
/
generate_post_from_pr.yaml
File metadata and controls
41 lines (34 loc) · 1.25 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
name: Generate post from PR
description: When a PR that has label `post` is merged, this action will generate a new post from the PR's body.
on:
pull_request:
types:
- closed
jobs:
generate_post:
if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'post') }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create post file
id: create_post
run: |
PR_TITLE=${{ github.event.pull_request.title }}
DRAFT_TITLE=${PR_TITLE#post/}
# Remove the draft item
git rm drafts/${DRAFT_TITLE}
DATE=$(date +'%Y-%m-%d')
POST_FILE="posts/${DATE}-${DRAFT_TITLE}.md"
echo "Target: ${POST_FILE}"
cat >$POST_FILE <<EOL
${{ github.event.pull_request.body }}
EOL
echo "Done creating post"
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add posts/
git commit -m "Create post: ${{ github.event.pull_request.title }}"
git push origin main