1028.yml
All checks were successful
发布wordpress文章 / generate_changelog (push) Successful in 6s

This commit is contained in:
298977887 2024-10-29 00:42:05 +08:00
parent 39f45b9e58
commit a90e0b0508
2 changed files with 9 additions and 49 deletions

View File

@ -17,55 +17,15 @@ jobs:
TZ: Asia/Shanghai
run: date
# 1. 读取固件版本 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
#- name: 配置 apt 源为清华源并安装依赖
# run: |
# sudo sed -i 's@http://.*.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@' /etc/apt/sources.list
# sudo apt-get update -y
# sudo apt-get install -y python3 python3-pip
# 2. 更新 WordPress 文章
- name: 更新 WordPress 文章
- name: 📦 更新文章内容到wordpress
env:
WORDPRESS_URL: ${{ secrets.WORDPRESS_URL }}
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
POST_ID: 829
POST_STATUS: "draft"
firmware_version: ${{ env.firmware_version }}
run: |
FORMATTED_TIME=$(TZ='Asia/Shanghai' date "+%Y年%m月%d日")
# 创建 JSON 数据内容,保持 README 内容的原始格式
JSON_PAYLOAD=$(jq -n \
--arg title "${FORMATTED_TIME}最新每天更新OpenWRT&LEDE x86/64 软路由精品稳定版固件下载含插件" \
--arg post_status "$POST_STATUS" \
--arg firmware_version "$firmware_version" \
--arg formatted_time "$FORMATTED_TIME" \
--rawfile description README.md \
'{
title: $title,
description: $description,
post_status: $post_status,
custom_fields: [
{key: "wb_dl_firmware_version", value: $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}
]
}'
)
# 更新 WordPress 文章
RESPONSE=$(curl -s -X POST "$WORDPRESS_URL" \
--header "Content-Type: application/json" \
--user "$WORDPRESS_USERNAME:$WORDPRESS_PASSWORD" \
--data "$JSON_PAYLOAD")
# 检查响应状态
echo "$RESPONSE" | jq . || echo "更新失败"
run: python 发布文章.py

View File

@ -10,7 +10,7 @@ wp_username = os.environ['WORDPRESS_USERNAME']
wp_password = os.environ['WORDPRESS_PASSWORD']
# 设置要更新的文章的ID
post_id = 785 # 替换为实际的文章ID
post_id = 829 # 替换为实际的文章ID
# 创建一个客户端实例
client = xmlrpc.client.ServerProxy(wp_url)
@ -19,7 +19,7 @@ client = xmlrpc.client.ServerProxy(wp_url)
post = client.metaWeblog.getPost(post_id, wp_username, wp_password)
# 从文件中读取新的文章内容
with open('WP.txt', 'r', encoding='utf-8') as file:
with open('README.md', 'r', encoding='utf-8') as file:
new_content = file.read()
# 从 DISTRIB_REVISION.txt 文件中读取固件版本