-
Notifications
You must be signed in to change notification settings - Fork 38
94 lines (77 loc) · 3.18 KB
/
create-article-from-issue.yml
File metadata and controls
94 lines (77 loc) · 3.18 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
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
86
87
88
89
90
91
92
93
94
name: Create Article from Issue
on:
issues:
types: [opened, edited]
jobs:
create-article:
runs-on: ubuntu-latest
if: contains(github.event.issue.title, 'New article')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: install chromium
run: |
sudo apt-get update
sudo apt-get install -y chromium-browser libxss1 \
fonts-ipafont-gothic fonts-wqy-zenhei \
fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
--no-install-recommends
- run: chromium-browser --version
- name: Install pandoc
run: |
sudo apt-get install -y pandoc
- name: pipenv install
run: |
pip install pipenv
pipenv install
- name: npm install
run: |
(cd previews && \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install)
- name: Extract information from Issue
id: extract
run: |
echo "${{ github.event.issue.body }}" > issue_body.txt
FILEID=$(grep -oP '(?<=\*\*Google doc\*\*: ).*' issue_body.txt | sed 's|.*\/d/||' | sed 's|/.*||')
AUTHOR=$(grep -oP '(?<=\*\*Profile\*\*: ).*' issue_body.txt)
TAGS=$(grep -oP '(?<=\*\*Tags\*\*: ).*' issue_body.txt)
echo "fileid=$FILEID" >> "$GITHUB_OUTPUT"
echo "author=$AUTHOR" >> "$GITHUB_OUTPUT"
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Run the article generation script
run: |
pipenv run python scripts/pandoc_google_doc.py \
--fileid "${{ steps.extract.outputs.fileid }}" \
--author "${{ steps.extract.outputs.author }}" \
--tags "${{ steps.extract.outputs.tags }}"
- name: Commit and push generated article
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
BRANCH="articles/${{ steps.extract.outputs.fileid }}"
git checkout -b "$BRANCH"
git add .
git commit -m "Generated article from Google Doc ID: ${{ steps.extract.outputs.fileid }}"
git push origin "$BRANCH"
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v5
with:
title: "Article draft: ${{ steps.extract.outputs.fileid }}"
body: |
This PR was automatically generated from issue #${{ github.event.issue.number }}.
Closes #${{ github.event.issue.number }}
head: articles/${{ steps.extract.outputs.fileid }}
base: main
draft: true
- name: Comment on the original Issue
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
A pull request has been created to draft your article: [#${{ steps.create_pr.outputs.pull-request-number }}](https://github.com/${{ github.repository }}/pull/${{ steps.create_pr.outputs.pull-request-number }}).
Thank you for your contribution! 🚀