Skip to content

posts/make-new-post-via-github-pull-request #5

posts/make-new-post-via-github-pull-request

posts/make-new-post-via-github-pull-request #5

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: [labeled, closed]
jobs:
generate_post:
if: ${{ (github.event.pull_request.merged == true && github.event.label.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_TITLE="${DATE}-${DRAFT_TITLE}"
PR_BODY=${{ github.event.pull_request.body }}
POST_FILE="posts/${POST_TITLE}.md"
echo "${PR_BODY}" >> $POST_FILE
- 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