-
Notifications
You must be signed in to change notification settings - Fork 2
65 lines (52 loc) · 2.03 KB
/
deploy-hashnode.yml
File metadata and controls
65 lines (52 loc) · 2.03 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
name: Deploy to Hashnode
on:
schedule:
- cron: "0 * * * *" # каждый час
workflow_dispatch:
concurrency:
group: "blog-deploy"
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests markdown markdown2
- name: Fetch published_posts.json from gh-hashnode (or init)
run: |
if git ls-remote --exit-code origin gh-hashnode; then
echo "Branch gh-hashnode exists, fetching published_posts.json..."
git fetch origin gh-hashnode
git checkout origin/gh-hashnode -- published_posts.json
else
echo "Branch gh-hashnode does not exist, creating initial JSON..."
echo "{}" > published_posts.json
fi
- name: Publish to Hashnode
run: python scripts/publish_to_hashnode.py
env:
HASHNODE_TOKEN: ${{ secrets.HASHNODE_TOKEN }}
HASHNODE_PUBLICATION_ID: ${{ secrets.HASHNODE_PUBLICATION_ID }}
JSON_FILE: published_posts.json
- name: Push updated published_posts.json to gh-hashnode
run: |
TMP_DIR=$(mktemp -d)
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git "$TMP_DIR"
cd "$TMP_DIR"
if git show-ref --quiet refs/heads/gh-hashnode; then
git checkout gh-hashnode
else
git checkout --orphan gh-hashnode
git rm -rf .
fi
cp $GITHUB_WORKSPACE/published_posts.json ./published_posts.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add published_posts.json
git commit -m "Update published_posts.json" --quiet || echo "No changes to commit"
git push origin gh-hashnode --force --quiet