-
Notifications
You must be signed in to change notification settings - Fork 5
/
action.yml
67 lines (66 loc) · 2.22 KB
/
action.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
# https://www.freecodecamp.org/news/publishing-github-event-data-with-github-actions-and-pages/
# https://stackoverflow.com/questions/58597010/how-to-access-a-github-issue-comment-body-using-github-actions
# This is a basic workflow to help you get started with Actions
# https://github.com/maguowei/iaas/blob/d48834c18b66ae0f3ae32e5e62a6811dfddadcb2/.github/workflows/iaas.yml
# replace invalid characters in filename https://stackoverflow.com/a/50876753/1553656
name: issue2post
description: "Turn issues into markdown file"
branding:
icon: "archive"
color: "green"
inputs:
branch:
description: "Target branch name to push the markdownfile"
required: true
default: "master"
dir:
description: "the posts dir"
required: true
default: "_posts"
GITHUB_TOKEN:
description: "secrets.GITHUB_TOKEN"
required: true
created_at:
description: "github.event.issue.created_at"
required: true
title:
description: "github.event.issue.title"
required: true
body:
description: "github.event.issue.body"
required: true
actor:
description: "github.actor"
required: true
runs:
using: "composite"
steps:
- id: generate-markdown-file
name: Turn comment into file
shell: bash
run: |
DATE="${{ inputs.created_at }}"
mkdir -p ${{ inputs.dir }}
# useing '' to wrap the title to escapse backticks
# and quates to wrap title in post body is to escapse backticks in jekyll building
POST_TITLE=$(sed -E 's/[[:space:]|[:punct:]]/_/g' <<<'${{ inputs.title }}')
cat <<'EOF' > _posts/"${DATE:0:10}-${POST_TITLE}".md
---
layout: post
title: "${{ inputs.title }}"
date: ${{ inputs.created_at }}
---
${{ inputs.body }}
EOF
- name: Push changes to repo
shell: bash
run: |
REMOTE=https://${{ inputs.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git config user.email "${{ inputs.actor }}@users.noreply.github.com"
git config user.name "${{ inputs.actor }}"
git pull ${REMOTE}
git checkout ${{ inputs.branch }}
git add .
git status
git commit -am "Add new comment"
git push ${REMOTE} ${{ inputs.branch }}