Update release notes from feishu #466
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: Download binaries | |
| run: | | |
| mkdir -p ./bin | |
| wget -P ./bin ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}bin/feishu2md | |
| wget -P ./bin ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}bin/jq | |
| wget -P ./bin ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}bin/ossutil | |
| # Step 3: 给 feishu2md、jq、ossutil 可执行权限 | |
| - name: Make feishu2md and jq and ossutil executable | |
| run: | | |
| chmod +x ./bin/feishu2md | |
| chmod +x ./bin/jq | |
| chmod +x ./bin/ossutil | |
| # Step 4: 配置 feishu2md | |
| - name: Configure feishu2md | |
| run: | | |
| # 查看 feishu2md 版本 | |
| ./bin/feishu2md --version | |
| # 生成 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 5: 运行 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 | |
| # 去除 markdown 文档文件名中开头和结尾的空白字符 | |
| echo "Trimming markdown file names" | |
| for file in *.md; do | |
| if [[ -f "$file" ]]; then | |
| new_name=$(echo "$file" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+\.md$/.md/') | |
| if [[ "$file" != "$new_name" ]]; then | |
| # 重命名,如果有重名文件,那就直接覆盖了 | |
| echo "→ Renaming '$file' to '$new_name'" | |
| mv "$file" "$new_name" | |
| fi | |
| fi | |
| done | |
| ls -al | |
| cd .. | |
| # Step 6: 使用仓库内的 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 7: 处理 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 8: 使用 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 9: 设置 Python 环境 | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ">=3.10" | |
| # Step 10: 安装 semver 依赖,用于接下来对 release notes 按版本号进行排序 | |
| - name: Install semver using pip | |
| run: | | |
| pip install semver | |
| # Step 11: 根据 release_notes 目录中的 markdown 文件列表更新 toc | |
| - name: Update toc with release notes | |
| run: | | |
| python scripts/update_toc_with_release_notes.py | |
| # Step 12: 生成分支名,用于发起 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 13: 就 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 | |
| notify-feishu-on-failure: | |
| runs-on: ubuntu-latest | |
| needs: update-release-notes | |
| if: failure() | |
| steps: | |
| - name: Send notification to Feishu on failure | |
| run: | | |
| curl -X POST ${{ secrets.FEISHU_CI_BOT_WEBHOOK_URL }} \ | |
| -H 'Content-Type: application/json' \ | |
| -d '{ | |
| "msg_type": "text", | |
| "content": { | |
| "text": "🚨 GitHub Action 失败通知:从飞书更新 Release Notes 并发起 PR 时失败!\n- 仓库: ${{ github.repository }}\n- 分支: ${{ github.ref }}\n- 工作流: ${{ github.workflow }}\n- 触发人: ${{ github.actor }}\n- 查看日志: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| } | |
| }' |