Plugin Auto Publish PR¶
Note: ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考英文原版。
背景¶
更新其他人正在使用的插件可能很繁琐。传统方式需要修改代码、更新版本、推送更改、创建分支、打包文件并手动提交 PR——这是一个重复性的流程,会拖慢开发进度。
因此,我们创建了 Plugin Auto-PR,这是一个 GitHub Actions 工作流,可以自动化整个流程。现在你只需一个操作就能完成打包、推送和创建 PR,专注于构建优秀的插件。
概念¶
GitHub Actions¶
GitHub Actions 可以在 GitHub 中自动化你的开发任务。
工作原理:当触发时(例如,通过代码推送),它会在基于云的虚拟机中运行你的工作流,自动处理从构建到部署的所有事项。

限制:
- 公开仓库:无限制
- 私有仓库:每月 2000 分钟
Plugin Auto-PR¶
工作原理:
- 当你将代码推送到插件源代码仓库的主分支时,工作流会被触发
- 工作流从
manifest.yaml文件读取插件信息 - 自动将插件打包为
.difypkg文件 - 将打包后的文件推送到你 fork 的
flexai-plugins仓库 - 创建新分支并提交更改
- 自动创建 PR 以合并到上游仓库
前提条件¶
仓库¶
- 你已经有自己的插件源代码仓库(例如,
your-name/plugin-source) - 你已经有自己 fork 的插件仓库(例如,
your-name/flexai-plugins) - 你 fork 的仓库已经有插件目录结构:
权限¶
此工作流需要适当的权限才能运行:
- 你需要创建一个具有足够权限的 GitHub 个人访问令牌(PAT)
- PAT 必须有权限将代码推送到你 fork 的仓库
- PAT 必须有权限向上游仓库创建 PR
参数和配置¶
设置要求¶
要开始自动发布,你需要两个关键组件:
manifest.yaml 文件:此文件驱动自动化流程:
name:你的插件名称(影响包和分支名称)version:语义版本号(每次发布时递增)author:你的 GitHub 用户名(决定仓库路径)
PLUGIN_ACTION Secret:你需要将此 secret 添加到你的插件源代码仓库:
- 值:必须是具有足够权限的个人访问令牌(PAT)
- 权限:能够将分支推送到你 fork 的仓库并向上游仓库创建 PR
自动生成的参数¶
设置完成后,工作流会自动处理这些参数:
- GitHub 用户名:从
manifest.yaml中的author字段读取 - 作者文件夹名称:与
author字段一致 - 插件名称:从
manifest.yaml中的name字段读取 - 分支名称:
bump-{plugin-name}-plugin-{version} - 包文件名:
{plugin-name}-{version}.difypkg - PR 标题和内容:根据插件名称和版本自动生成
分步指南¶
准备仓库¶
确保你已经 fork 了官方的 `flexai-plugins` 仓库,并且有自己的插件源代码仓库。
配置 Secret¶
导航到你的插件源代码仓库,点击 **Settings > Secrets and variables > Actions > New repository secret**,然后创建一个 GitHub Secret:
* 名称:`PLUGIN_ACTION`
* 值:具有目标仓库(`your-name/flexai-plugins`)写入权限的 GitHub 个人访问令牌(PAT)
<img src="https://assets-docs.flexai.com.tr/2025/04/8abd72b677dd24752910c304c76f1c26.png" alt="Create Secrets" />
创建工作流文件¶
在你的仓库中创建 `.github/workflows/` 目录,在此目录中创建名为 `plugin-publish.yml` 的文件,并将以下内容复制到文件中:
```yaml
# .github/workflows/auto-pr.yml
name: Auto Create PR on Main Push
on:
push:
branches: [ main ] # Trigger on push to main
jobs:
create_pr: # Renamed job for clarity
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Print working directory # Kept for debugging
run: |
pwd
ls -la
- name: Download CLI tool
run: |
# Create bin directory in runner temp
mkdir -p $RUNNER_TEMP/bin
cd $RUNNER_TEMP/bin
# Download CLI tool
wget https://github.com/flexai/flexai-plugin-daemon/releases/latest/download/flexai-plugin-linux-amd64
chmod +x flexai-plugin-linux-amd64
# Show download location and file
echo "CLI tool location:"
pwd
ls -la flexai-plugin-linux-amd64
- name: Get basic info from manifest # Changed step name and content
id: get_basic_info
run: |
PLUGIN_NAME=$(grep "^name:" manifest.yaml | cut -d' ' -f2)
echo "Plugin name: $PLUGIN_NAME"
echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT
VERSION=$(grep "^version:" manifest.yaml | cut -d' ' -f2)
echo "Plugin version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# If the author's name is not your github username, you can change the author here
AUTHOR=$(grep "^author:" manifest.yaml | cut -d' ' -f2)
echo "Plugin author: $AUTHOR"
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
- name: Package Plugin
id: package
run: |
# Use the downloaded CLI tool to package
cd $GITHUB_WORKSPACE
# Use variables for package name
PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg"
# Use CLI from runner temp
$RUNNER_TEMP/bin/flexai-plugin-linux-amd64 plugin package . -o "$PACKAGE_NAME"
# Show packaging result
echo "Package result:"
ls -la "$PACKAGE_NAME"
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
# Show full file path and directory structure (kept for debugging)
echo "\\nFull file path:"
pwd
echo "\\nDirectory structure:"
tree || ls -R
- name: Checkout target repo
uses: actions/checkout@v3
with:
# Use author variable for repository
repository: ${{steps.get_basic_info.outputs.author}}/flexai-plugins
path: flexai-plugins
token: ${{ secrets.PLUGIN_ACTION }}
fetch-depth: 1 # Fetch only the last commit to speed up checkout
persist-credentials: true # Persist credentials for subsequent git operations
- name: Prepare and create PR
run: |
# Debug info (kept)
echo "Debug: Current directory $(pwd)"
# Use variable for package name
PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg"
echo "Debug: Package name: $PACKAGE_NAME"
ls -la
# Move the packaged file to the target directory using variables
mkdir -p flexai-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}
mv "$PACKAGE_NAME" flexai-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}/
# Enter the target repository directory
cd flexai-plugins
# Configure git
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
# Ensure we are on the latest main branch
git fetch origin main
git checkout main
git pull origin main
# Create and switch to a new branch using variables and new naming convention
BRANCH_NAME="bump-${{ steps.get_basic_info.outputs.plugin_name }}-plugin-${{ steps.get_basic_info.outputs.version }}"
git checkout -b "$BRANCH_NAME"
# Add and commit changes (using git add .)
git add .
git status # for debugging
# Use variables in commit message
git commit -m "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}"
# Push to remote (use force just in case the branch existed before from a failed run)
git push -u origin "$BRANCH_NAME" --force
# Confirm branch has been pushed and wait for sync (GitHub API might need a moment)
git branch -a
echo "Waiting for branch to sync..."
sleep 10 # Wait 10 seconds for branch sync
- name: Create PR via GitHub API
env:
GH_TOKEN: ${{ secrets.PLUGIN_ACTION }} # Use the provided token for authentication
run: |
gh pr create \
--repo flexai/flexai-plugins \
--head "${{ steps.get_basic_info.outputs.author }}:${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}" \
--base main \
--title "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" \
--body "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin package to version ${{ steps.get_basic_info.outputs.version }}
Changes:
- Updated plugin package file" || echo "PR already exists or creation skipped." # Handle cases where PR already exists
- name: Print environment info # Kept for debugging
run: |
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
echo "Current directory contents:"
ls -R
```
更新 manifest.yaml¶
确保以下字段正确设置:
```yaml
version: 0.0.x # Version number
author: your-github-username # GitHub username/Author name
name: your-plugin-name # Plugin name
```
使用指南¶
首次设置¶
首次设置自动发布工作流时,请完成以下步骤:
- 确保你已经 fork 了官方的
flexai-plugins仓库 - 确保你的插件源代码仓库结构正确
- 在你的插件源代码仓库中设置
PLUGIN_ACTION Secret - 创建工作流文件
.github/workflows/plugin-publish.yml - 确保
manifest.yaml文件中的name和author字段配置正确
后续更新¶
设置完成后,发布新版本:
- 修改代码
- 更新
manifest.yaml中的version字段

- 将所有更改推送到主分支
- 等待 GitHub Actions 完成打包、分支创建和 PR 提交
结果¶
当你将代码推送到插件源代码仓库的主分支时,GitHub Actions 将自动执行发布流程:
- 以
{plugin-name}-{version}.difypkg格式打包插件 - 将打包后的文件推送到目标仓库
- 创建 PR 以合并到 fork 仓库

示例仓库¶
查看示例仓库以了解配置和最佳实践。
{/ Contributing Section DO NOT edit this section! It will be automatically generated by the script. /}