This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (123 loc) · 5.27 KB
/
build-blog.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
150
---
name: "Build the blog"
on: # yamllint disable-line rule:truthy
# feature branches
pull_request:
# releases
push:
branches:
- main
# nightly build to automatically activate new blog posts. Slightly after midnight CET/CEST as it is UTC here.
schedule:
- cron: "22 2 * * *"
jobs:
build-the-blog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Build blog
run: |
cd src/
# remove the CDN dependency
LAYOUT_DIR=$(bundle show minimal-mistakes)
cp "$LAYOUT_DIR/_includes/head.html" "$LAYOUT_DIR/_includes/head.html.old"
sed '/fontawesome/d' "$LAYOUT_DIR/_includes/head.html.old" > "$LAYOUT_DIR/_includes/head.html"
JEKYLL_ENV=production bundle exec jekyll build
- uses: actions/setup-node@v4
with:
node-version: 19.x
- name: Install Fontawesome and comment system dependencies
run: |
npm install
mkdir -p target/assets/fontawesome/css
cp node_modules/@fortawesome/fontawesome-free/css/all.min.css target/assets/fontawesome/css/
cp -pr node_modules/@fortawesome/fontawesome-free/webfonts target/assets/fontawesome/
mkdir -p target/assets/js
cp node_modules/dayjs/plugin/relativeTime.js target/assets/js/
cp node_modules/dompurify/dist/purify.min.js target/assets/js/
cp node_modules/marked/marked.min.js target/assets/js/
cp node_modules/dayjs/dayjs.min.js target/assets/js/
- id: get-changed-files
if: github.event_name != 'schedule'
uses: jitterbit/get-changed-files@v1
with:
format: json
- name: Create Github issue for new posts
if: github.ref != 'refs/heads/main' && github.event_name != 'schedule'
run: |
echo "Changed files: ${{ steps.get-changed-files.outputs.added }}"
new_post=$(echo '${{ steps.get-changed-files.outputs.added }}' | jq -r .[] | grep src/_posts || true)
if [ -n "$new_post" ]; then
echo "New post found: $new_post"
title=$(sed -n -e 's/^.*title: //p' "$new_post" | tr -d '"')
issue_id=$(sed -n -e 's/^.*comments_id: //p' "$new_post" | grep -Eo '[0-9]+' || true)
echo "Title: $title"
echo "Issue ID: $issue_id"
if [ -z "$issue_id" ]; then
issue_response=$(curl -X "POST" "https://api.github.com/repos/kayman-mk/blog-tech-at-work/issues" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: text/plain; charset=utf-8" \
-d "{
\"title\": \"$title\",
\"body\": \"The comments added to this issue are shown in the blog automatically.\",
\"labels\": [
\"blog-comment\",
\"not-published\"
]
}")
issue_id=$(echo "$issue_response" | jq -r .number)
echo "Created GitHub issue: $issue_id"
sed -i "2i comments_id: $issue_id" "$new_post"
fi
fi
- id: commit-changes
uses: stefanzweifel/git-auto-commit-action@v5
if: github.ref != 'refs/heads/main' && github.event_name != 'schedule'
with:
commit_message: "Add comments_id to new post"
file_pattern: src/_posts
- name: Activate GitHub issue for comments
if: github.ref == 'refs/heads/main' && github.event_name != 'schedule'
run: |
echo "Changed files: ${{ steps.get-changed-files.outputs.added }}"
new_post=$(echo '${{ steps.get-changed-files.outputs.added }}' | jq -r .[] | grep src/_posts || true)
if [ -n "$new_post" ]; then
echo "New post found: $new_post"
issue_id=$(sed -n -e 's/^.*comments_id: //p' "$new_post" | grep -Eo '[0-9]+')
curl -X "PATCH" "https://api.github.com/repos/kayman-mk/blog-tech-at-work/issues/$issue_id" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: text/plain; charset=utf-8" \
-d "{
\"state\": \"closed\",
\"labels\": [
\"blog-comment\"
]
}"
fi
- name: Replace secrets
if: github.ref == 'refs/heads/main'
run: |
find . -type f -print0 | \
xargs -0 sed -i "s/__GH_API_TOKEN_COMMENT_SYSTEM__REPLACE_ME__/${{ secrets.GH_API_TOKEN_COMMENT_SYSTEM }}/g"
- name: Deploy
if: github.ref == 'refs/heads/main'
uses: SamKirkland/[email protected]
with:
server: af93d.netcup.net
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
protocol: ftps
security: strict
local-dir: target/
server-dir: blog.matthiaskay.de/