-
Notifications
You must be signed in to change notification settings - Fork 3
69 lines (56 loc) · 2.49 KB
/
Copy pathmain.yml
File metadata and controls
69 lines (56 loc) · 2.49 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
66
67
68
69
name: Package Issues to JSON
on:
issues:
types: [opened, edited, closed, reopened, deleted]
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
package_issues:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Fetch only OPEN issues from GitHub API
run: |
curl -X GET 'https://api.github.com/repos/${{ github.repository }}/issues?state=open&labels=%E5%8F%8B%E9%93%BE%E7%94%B3%E8%AF%B7&per_page=100' \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-o issues.json
echo "Fetched issues:"
cat issues.json
- name: Parse issues to JSON array with ID
run: |
mkdir -p out
jq -r '.[] | select(.body != null and .body != "") | @base64' issues.json | while read issue; do
_jq() {
echo "${issue}" | base64 --decode | jq -r "${1}"
}
id=$(_jq '.number')
# 重点:把 \n 转换为换行
_jq '.body' | sed 's/\\n/\n/g' > tmp_body.txt
cat tmp_body.txt
title=$(awk '/### 📝 网站名称/{getline; while($0 ~ /^ *$/){getline}; print; exit}' tmp_body.txt)
brief=$(awk '/### 💬 站点介绍/{getline; while($0 ~ /^ *$/){getline}; print; exit}' tmp_body.txt)
url=$(awk '/### 🔗 网站链接/{getline; while($0 ~ /^ *$/){getline}; print; exit}' tmp_body.txt)
icon=$(awk '/### 🖼️ 网站图标链接/{getline; while($0 ~ /^ *$/){getline}; print; exit}' tmp_body.txt)
printf '{\n "id": %s,\n "title": "%s",\n "brief": "%s",\n "url": "%s",\n "icon": "%s"\n}\n' \
"$id" "$title" "$brief" "$url" "$icon" > out/$id.json
done
if [ "$(ls out | wc -l)" -eq 0 ]; then
echo '[]' > issues.json
else
jq -s '.' out/*.json > issues.json
fi
echo "Parsed JSON array:"
cat issues.json
- name: Upload to Cloudflare R2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }}
run: |
pip install awscli
aws s3 cp issues.json s3://blog/data/json/issues.json \
--endpoint-url https://05b69c2cf1cc6b7312bd86130ff3d5f3.r2.cloudflarestorage.com \
--region auto \
--acl public-read