Skip to content

Update release notes from feishu #22

Update release notes from feishu

Update release notes from feishu #22

name: Update release notes from feishu
on:
schedule:
# 每天凌晨 1 点(北京时间)运行
- cron: "0 17 * * *"
# 添加 workflow_dispatch 以允许手动触发
workflow_dispatch:
jobs:
update-release-notes:
runs-on: ubuntu-latest
steps:
# Step 1: 检出仓库代码
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
ref: master
# Step 2: 给 feishu2md、jq、ossutil 可执行文件权限
# feishu2md 是用于获取飞书文档并转换为 markdown 文档的工具
# jq 是用于处理 json 数据的工具
# ossutil 是用于上传图片到阿里云 oss 服务器的工具
- name: Make feishu2md and jq and ossutil executable
run: |
chmod +x ./bin/feishu2md
chmod +x ./bin/jq
chmod +x ./bin/ossutil
# Step 3: 配置 feishu2md
- name: Configure feishu2md
run: |
# 生成 feishu2md 配置文件
./bin/feishu2md config --appId ${{ secrets.FEISHU_APP_ID }} --appSecret ${{ secrets.FEISHU_APP_SECRET }}
# 设置 feishu2md 配置文件中的 title_as_filename 为 true
FEISHU2MD_CONF_FILE="$HOME/.config/feishu2md/config.json"
./bin/jq '.output.title_as_filename = true' "$FEISHU2MD_CONF_FILE" > tmp.$$.json && mv tmp.$$.json "$FEISHU2MD_CONF_FILE"
# 查看最新的配置文件内容
cat "$FEISHU2MD_CONF_FILE"
# Step 4: 运行 feishu2md 获取飞书文档(含文档中的图片)并转换为 markdown 文档
- name: Run feishu2md to fetch feishu docs
run: |
mkdir -p ./feishu2md_output
cd feishu2md_output
../bin/feishu2md download --batch ${{ secrets.FEISHU_RELEASE_NOTES_FOLDER_URL }}
ls -al
cd ..
# Step 5: 使用仓库内的 ossutil 将刚才获取的图片上传到阿里云 oss 服务器
- name: Upload images in docs to Aliyun OSS
run: |
if [ -d "./feishu2md_output/static/" ]; then
./bin/ossutil config -e ${{ secrets.ALIYUN_OSS_ENDPOINT }} \
-i ${{ secrets.ALIYUN_OSS_ACCESS_KEY_ID }} \
-k ${{ secrets.ALIYUN_OSS_ACCESS_KEY_SECRET }}
./bin/ossutil cp -r ./feishu2md_output/static/ oss://${{ secrets.ALIYUN_OSS_BUCKET_COME_WITH_STATIC_PATH }} --exclude ".*" -u
else
echo "Directory ./feishu2md_output/static/ does not exist. Skipping upload."
fi
# Step 6: 处理 markdown 文件
- name: Process downloaded markdown docs
run: |
NEW_STATIC_PATH="${{ secrets.ALIYUN_OSS_STATIC_PUBLIC_PATH }}"
for file in ./feishu2md_output/*.md; do
if [ -f "$file" ]; then
# 去除文档内容的前两行(feishu 那边的发版文档已经约定好了格式)
sed -i '1,2d' "$file"
# 删除“## 内部信息”行及其后的所有内容(feishu 那边的发版文档已经约定好了格式)
sed -i '/^## 内部信息$/,$d' "$file"
# 替换图片地址为新的阿里云 oss 图片地址
sed -i -E "s|\!\[(.*?)\]\(static/(.*?)\)|\!\[\1\]($NEW_STATIC_PATH\2)|g" "$file"
echo "Updated $file."
else
echo "$file is not a regular file."
fi
done
# Step 7: 使用 feishu2md_output 中的 markdown 文件替换 release_notes 目录中的文件
- name: Replace release_notes with feishu markdown files
run: |
# 检查 release_notes 目录是否存在,存在则清空目录,不存在则创建目录
if [ -d "./release_notes/" ]; then
rm -rf ./release_notes/*
else
mkdir -p ./release_notes
fi
# 检查 feishu2md_output 目录中是否有 markdown 文件,有则全部复制到 release_notes 目录
if ls ./feishu2md_output/*.md > /dev/null 2>&1; then
cp ./feishu2md_output/*.md ./release_notes/
else
echo "There are no markdown files in feishu2md_output directory."
fi
ls -al ./release_notes
# Step 8: 设置 Python 环境
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: ">=3.10"
# Step 9: 安装 semver 依赖,用于接下来对 release notes 按版本号进行排序
- name: Install semver using pip
run: |
pip install semver
# Step 10: 根据 release_notes 目录中的 markdown 文件列表更新 toc
- name: Update toc with release notes
run: |
python scripts/update_toc_with_release_notes.py
# Step 11: 生成分支名,用于发起 pull request
- name: Generate branch name
run: |
BRANCH_NAME=update-release-notes-with-toc-$(date +%Y%m%d%H%M%S)
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
# Step 12: 就 release_notes 和 toc 的改动发起 pull request
- name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
commit-message: "Update release notes with markdown docs from feishu"
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
branch: ${{ env.BRANCH_NAME }}
base: master
title: "Auto update release notes from feishu"
body: "This PR contains updated release notes from feishu."
delete-branch: true
add-paths: |
release_notes/*.md
TOC.md
labels: |
release_notes_with_toc
auto_merge