-
Notifications
You must be signed in to change notification settings - Fork 9
/
action.yml
149 lines (117 loc) · 4.45 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: 'md2zhihu'
description: >
Convert markdown to a single-file by uploading local assets.
branding:
icon: upload-cloud
color: green
inputs:
pattern:
description: 'file pattern to convert'
required: true
default: '**/*.md'
output_dir:
description: |-
dir to store converted markdown.
required: true
default: '_md2zhihu'
asset_repo:
description: |-
Specify the git repo for asset storage.
The converted markdown will reference images in this repo. Supported providers include `github.com` and `gitee.com`.
When this option is absent, assets are pushed to the current repo `https://github.com/{{ github.repository }}.git`.
To push assets to `gitee.com`:
1. On gitee.com, create a access token at https://gitee.com/personal_access_tokens, to enable pushing assets to gitee.com;
The token must enable `projects` privileges.
2. Add a secret to the GitHub markdown repository that contains your gitee.com username and token (e.g., `GITEE_AUTH=drdrxp:abcd...xyz`) at `https://github.com/<username>/<repo>/settings/secrets/actions`.
3. Set `asset_repo` to the gitee.com repo push URL with the auth token, such as:
`asset_repo: https://[dollar]{{ secrets.GITEE_AUTH }}@gitee.com/drdrxp/bed.git`
required: false
default: 'https://github.com/${{ github.repository }}.git'
asset_branch:
description: |-
The branch in which assets are stored.
The converted markdown references images at this location.
This branch must NOT be removed otherwise the assets will not be accessed.
required: true
default: '${{ github.ref_name }}-md2zhihu-asset'
target_platform:
description: |-
The platform that the converted markdown should be compatible to.
Currently supported platforms are zhihu, wechat, weibo, simple.
`simple` converts almost everything to images and removes most text styles.
E.g. inline code block is converted to normal text.
required: true
default: 'zhihu'
output_branch:
description: |-
Commit and push the "output_dir" to a branch of this repo.
Set this to "" to disable push, in which case, user commit and push it manually.
required: true
default: '${{ github.ref_name }}-md2zhihu'
outputs:
converted_branch:
description: "The url of the branch of converted markdowns"
value: ${{ steps.convert.outputs.converted_branch }}
runs:
using: "composite"
steps:
- name: Add npm bin into PATH
shell: bash
run: |
echo "add node module path: $GITHUB_WORKSPACE/node_modules/.bin/"
echo "$GITHUB_WORKSPACE/node_modules/.bin/" >> $GITHUB_PATH
- name: Install mermaid
shell: bash
run: |
npm install --verbose @mermaid-js/[email protected]
echo "locate npm, mmdc and mmdc --version"
which npm
which mmdc
mmdc --version
- name: Install pandoc
shell: bash
run: |
sudo apt-get install pandoc
pandoc --version
- name: Install graphviz
shell: bash
run: |
sudo apt-get install graphviz
dot -V
- name: Install python dep in requirements.txt
shell: bash
run: |
pip3 install setuptools wheel
pip3 install -r ${{ github.action_path }}/requirements.txt
- name: convert
id: convert
run: |
cp -R ${{ github.action_path }} md2zhihu
echo 'asset_repo: ${{ inputs.asset_repo }}'
echo "which mmdc"
which mmdc
mmdc --version
python3 -m md2zhihu \
--repo '${{ inputs.asset_repo }}@${{ inputs.asset_branch }}' \
--code-width 600 \
--platform ${{ inputs.target_platform }} \
--md-output ${{ inputs.output_dir }}/ \
${{ inputs.pattern }}
rm -rf ./md2zhihu
if [ ".${{ inputs.output_branch }}" == "." ]; then
echo "output branch is empty, skip push"
else
git add ${{ inputs.output_dir }}
if git diff-index --quiet HEAD --; then
echo "Nothing to commit"
else
git \
-c "user.name=drmingdrmer" \
-c "[email protected]" \
commit \
-m "md2zhihu built"
fi
git push -f origin HEAD:refs/heads/${{ inputs.output_branch }}
echo "::set-output name=converted_branch::https://github.com/${{ github.repository }}/tree/${{ inputs.output_branch }}"
fi
shell: bash