-
Notifications
You must be signed in to change notification settings - Fork 38
134 lines (114 loc) · 4.04 KB
/
create-article-from-issue.yml
File metadata and controls
134 lines (114 loc) · 4.04 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Create Article from Issue
on:
issues:
types: [opened, edited]
permissions:
contents: write
pull-requests: write
issues: write
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: Create gitbash alias
run: sudo ln -s /bin/bash /bin/gitbash
- name: uv install
run: |
pip install uv
uv sync
- name: npm install
run: |
(cd previews && \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install)
- name: Extract information from Issue
id: extract
env:
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
echo "$ISSUE_BODY" > issue_body.txt
echo "Extracted issue body:"
cat issue_body.txt
echo "------------------------"
while IFS= read -r line; do
KEY=$(echo "$line" | cut -d':' -f1 | xargs)
VALUE=$(echo "$line" | cut -d':' -f2- | xargs)
if [ "$KEY" = "Title" ]; then
TITLE="$VALUE"
elif [ "$KEY" = "Google doc" ]; then
FILEID="$VALUE"
elif [ "$KEY" = "Profile" ]; then
AUTHOR="$VALUE"
elif [ "$KEY" = "Tags" ]; then
TAGS="$VALUE"
fi
done < issue_body.txt
echo "Extracted values:"
echo "Title: $TITLE"
echo "File ID: $FILEID"
echo "Author: $AUTHOR"
echo "Tags: $TAGS"
echo "------------------------"
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
echo "fileid=$FILEID" >> "$GITHUB_OUTPUT"
echo "author=$AUTHOR" >> "$GITHUB_OUTPUT"
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
rm issue_body.txt
- name: Run the article generation script
env:
FILEID: ${{ steps.extract.outputs.fileid }}
AUTHOR: ${{ steps.extract.outputs.author }}
TAGS: ${{ steps.extract.outputs.tags }}
run: |
uv run python scripts/pandoc_google_doc.py \
--fileid "$FILEID" \
--author "$AUTHOR" \
--tags "$TAGS"
- name: Commit and push generated article
env:
FILEID: ${{ steps.extract.outputs.fileid }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
BRANCH="articles/$FILEID"
git checkout -b "$BRANCH"
git add .
git commit -m "Generated article from Google Doc ID: $FILEID"
git push origin "$BRANCH"
- name: Create Pull Request
id: create_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTICLE_TITLE: ${{ steps.extract.outputs.title }}
FILEID: ${{ steps.extract.outputs.fileid }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
gh pr create \
--title "Article draft: $ARTICLE_TITLE" \
--body "This PR was automatically generated from issue #$ISSUE_NUMBER. Closes #$ISSUE_NUMBER" \
--head "articles/$FILEID" \
--base main
- 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!
Thank you for your contribution! 🚀