-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (75 loc) · 3.3 KB
/
create-article-pr.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Generate article from Qiita with hexiita
on:
repository_dispatch:
types: [create_article_pr]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
id-token: write
pages: write
pull-requests: write
jobs:
create-article-pr:
runs-on: ubuntu-latest
env:
TZ: Asia/Tokyo
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Python tool
run: pip install matter-edit@git+https://github.com/yknz/matter-edit.git
- name: Install Go tool
run: |
mkdir ~/bin
export GOBIN=~/bin
go install github.com/ma91n/hexiita@latest
- name: Add Mask
run: |
echo -n '::add-mask::' > cmd.txt
jq < ${GITHUB_EVENT_PATH} -r .client_payload.article_url >> cmd.txt
echo -n '::add-mask::' >> cmd.txt
jq < ${GITHUB_EVENT_PATH} -r .client_payload.thumbnail_url >> cmd.txt
cat cmd.txt
rm cmd.txt
- name: Generate article
run: |
mkdir -p ~/tech-blog/source/_posts ~/tech-blog/source/images
cd ~/tech-blog
~/bin/hexiita ${{ github.event.client_payload.article_url }}
cd ${{ github.workspace }}
cp -rT ~/tech-blog .
- name: Update author
run: ls -rt source/_posts | tail -n 1 | xargs -I {} python3 -m matteredit update source/_posts/{} --params author=${{ github.event.client_payload.author }}
- name: Download & Update thumbnail
if: ${{ github.event.client_payload.thumbnail_url != '' }}
run: |
articlefilepath=`ls -rt source/_posts | tail -n 1 | xargs -I {} echo source/_posts/{}`
thumbnailpath=`python3 -m matteredit show $articlefilepath --param thumbnail | sed -e 's/^/\source/g'`
filename=`curl -JLO -w '%{filename_effective}' "${{ github.event.client_payload.thumbnail_url }}" | grep filename | sed "s/^.*'\(.*\)'.*$/\1/"`
rm $thumbnailpath
newthumbnailpath="${thumbnailpath%.*}.${filename##*.}"
mv $filename $newthumbnailpath
echo $newthumbnailpath | sed -e 's/source//g' | xargs -I {} python3 -m matteredit update $articlefilepath --params thumbnail={}
- name: Get article title
id: get-article-title
run: |
title=`curl -s "${{ github.event.client_payload.article_url }}" | grep -oP '(?<=<title>).*(?=\s\#.*</title>)'`
echo "title=$title" >> $GITHUB_OUTPUT
- name: Commit and push article to new branch
id: commit-and-push
run: |
branch=actions/run_id/${{ github.run_id }}
echo branch=$branch >> $GITHUB_OUTPUT
git config --local user.name "${{ github.actor }}"
git config --local user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
git checkout -b $branch
git add .
git commit -m "Add article: ${{ steps.get-article-title.outputs.title }}"
git push -u origin $branch
- name: Open pull request
run: |
gh pr create --base main --head ${{ steps.commit-and-push.outputs.branch }} --fill --body "This PR is created by GitHub Actions workflow."