Skip to content

Commit b66770a

Browse files
committed
Add initial action
1 parent 48f2a6c commit b66770a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python: 3
2+
3+
RUN pip install requests
4+
5+
COPY publish.py /publish.py
6+
7+
#TODO: unsure if additional logic should be handled in entrypoint.sh or if we should just do everything inside of python
8+
COPY entrypoint.sh /entrypoint.sh
9+
10+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'Publish Dev.to Article'
2+
description: 'Publish article to Dev.to blogging platform'
3+
runs:
4+
using: 'docker'
5+
image: 'Dockerfile'

publish.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import required libraries
2+
import requests, re, os, sys
3+
4+
API_ENDPOINT = "https://dev.to/api/articles"
5+
6+
PR = os.getenv('PR_LIST_FILE')
7+
API_KEY = os.getenv('DEV_TO_TOKEN')
8+
STATUS=0
9+
10+
with open(PR, 'r') as files:
11+
for line in files.readlines():
12+
if re.search("^.*.md$", line):
13+
with open(line.strip(),'r') as file:
14+
data = file.read().replace('\n', '\\n')
15+
json = '{"article":{"body_markdown": "' + data + '"}}'
16+
headers = {'content-type': 'application/json; charset=utf-8', 'api-key': API_KEY}
17+
r = requests.post(url = API_ENDPOINT, data = json.encode('utf-8'), headers = headers)
18+
if r.status_code != 201:
19+
print("Unable to publish: " + line.strip())
20+
STATUS=1
21+
else:
22+
print("Published: " + line.strip())
23+
24+
if STATUS != 0:
25+
print("There were issues publishing one or more files. Please see logs above for more details")
26+
sys.exit(1)

0 commit comments

Comments
 (0)