2024-10-28 16:14:19 +00:00
|
|
|
name: 发布wordpress文章
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
generate_changelog:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: 🛒 检出代码
|
|
|
|
uses: https://git.aoun.ltd/actions/checkout@v4
|
|
|
|
|
|
|
|
- name: 设置时区
|
|
|
|
env:
|
|
|
|
TZ: Asia/Shanghai
|
2024-10-28 16:18:08 +00:00
|
|
|
run: date
|
2024-10-28 16:14:19 +00:00
|
|
|
|
2024-10-28 16:22:14 +00:00
|
|
|
# 1. 读取 README.md 内容
|
2024-10-28 16:14:19 +00:00
|
|
|
- name: 读取 README.md 内容
|
|
|
|
id: read_wp
|
|
|
|
run: |
|
2024-10-28 16:22:14 +00:00
|
|
|
CONTENT=$(<README.md)
|
|
|
|
# JSON 转义并保存到环境变量
|
2024-10-28 16:14:19 +00:00
|
|
|
echo "wp_content<<EOF" >> $GITHUB_ENV
|
2024-10-28 16:22:14 +00:00
|
|
|
echo "$CONTENT" | jq -Rs . >> $GITHUB_ENV
|
2024-10-28 16:14:19 +00:00
|
|
|
echo "EOF" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
# 2. 读取固件版本 DISTRIB_REVISION.txt
|
|
|
|
- name: 读取 DISTRIB_REVISION.txt 中的固件版本
|
|
|
|
id: read_firmware
|
|
|
|
run: |
|
|
|
|
if [ -f DISTRIB_REVISION.txt ]; then
|
|
|
|
FIRMWARE_VERSION=$(sed -n '2p' DISTRIB_REVISION.txt | xargs)
|
|
|
|
echo "firmware_version=$FIRMWARE_VERSION" >> $GITHUB_ENV
|
|
|
|
else
|
|
|
|
echo "固件版本文件不存在,设置默认值" >&2
|
|
|
|
echo "firmware_version=Unknown" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 3. 更新 WordPress 文章
|
|
|
|
- name: 更新 WordPress 文章
|
|
|
|
env:
|
|
|
|
WORDPRESS_URL: ${{ secrets.WORDPRESS_URL }}
|
|
|
|
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
|
|
|
|
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
|
2024-10-28 16:18:08 +00:00
|
|
|
POST_ID: 829
|
|
|
|
POST_STATUS: "draft"
|
2024-10-28 16:14:19 +00:00
|
|
|
run: |
|
|
|
|
FORMATTED_TIME=$(TZ='Asia/Shanghai' date "+%Y年%m月%d日")
|
2024-10-28 16:22:14 +00:00
|
|
|
|
|
|
|
# 创建 JSON 数据内容,保持 README 内容的原始格式
|
|
|
|
JSON_PAYLOAD=$(cat <<EOF
|
|
|
|
{
|
|
|
|
"title": "${FORMATTED_TIME}最新每天更新OpenWRT&LEDE x86/64 软路由精品稳定版固件下载含插件",
|
|
|
|
"description": ${{ env.wp_content }},
|
|
|
|
"post_status": "$POST_STATUS",
|
|
|
|
"custom_fields": [
|
|
|
|
{"key": "wb_dl_firmware_version", "value": "${{ env.firmware_version }}"},
|
|
|
|
{"key": "wb_dl_kernel_version", "value": "6.X"},
|
|
|
|
{"key": "wb_dl_file_size", "value": "1024MB"},
|
|
|
|
{"key": "wb_dl_update_time", "value": "$FORMATTED_TIME"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
2024-10-28 16:14:19 +00:00
|
|
|
)
|
|
|
|
|
2024-10-28 16:22:14 +00:00
|
|
|
# 更新 WordPress 文章
|
2024-10-28 16:14:19 +00:00
|
|
|
RESPONSE=$(curl -s -X POST "$WORDPRESS_URL" \
|
|
|
|
--header "Content-Type: application/json" \
|
|
|
|
--user "$WORDPRESS_USERNAME:$WORDPRESS_PASSWORD" \
|
|
|
|
--data "$JSON_PAYLOAD")
|
|
|
|
|
2024-10-28 16:22:14 +00:00
|
|
|
# 检查响应状态
|
2024-10-28 16:18:08 +00:00
|
|
|
echo "$RESPONSE" | jq . || echo "更新失败"
|