|
| 1 | +name: Plugin Publish Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + publish: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Checkout code |
| 12 | + uses: actions/checkout@v3 |
| 13 | + |
| 14 | + - name: Download CLI tool |
| 15 | + run: | |
| 16 | + mkdir -p $RUNNER_TEMP/bin |
| 17 | + cd $RUNNER_TEMP/bin |
| 18 | +
|
| 19 | + wget https://github.com/langgenius/dify-plugin-daemon/releases/download/0.0.6/dify-plugin-linux-amd64 |
| 20 | + chmod +x dify-plugin-linux-amd64 |
| 21 | +
|
| 22 | + echo "CLI tool location:" |
| 23 | + pwd |
| 24 | + ls -la dify-plugin-linux-amd64 |
| 25 | +
|
| 26 | + - name: Get basic info from manifest |
| 27 | + id: get_basic_info |
| 28 | + run: | |
| 29 | + PLUGIN_NAME=$(grep "^name:" manifest.yaml | cut -d' ' -f2) |
| 30 | + echo "Plugin name: $PLUGIN_NAME" |
| 31 | + echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + VERSION=$(grep "^version:" manifest.yaml | cut -d' ' -f2) |
| 34 | + echo "Plugin version: $VERSION" |
| 35 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + # If the author's name is not your github username, you can change the author here |
| 38 | + AUTHOR=$(grep "^author:" manifest.yaml | cut -d' ' -f2) |
| 39 | + echo "Plugin author: $AUTHOR" |
| 40 | + echo "author=$AUTHOR" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Package Plugin |
| 43 | + id: package |
| 44 | + run: | |
| 45 | + cd $GITHUB_WORKSPACE |
| 46 | + PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg" |
| 47 | + $RUNNER_TEMP/bin/dify-plugin-linux-amd64 plugin package . -o "$PACKAGE_NAME" |
| 48 | +
|
| 49 | + echo "Package result:" |
| 50 | + ls -la "$PACKAGE_NAME" |
| 51 | + echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + echo "\nFull file path:" |
| 54 | + pwd |
| 55 | + echo "\nDirectory structure:" |
| 56 | + tree || ls -R |
| 57 | +
|
| 58 | + - name: Checkout target repo |
| 59 | + uses: actions/checkout@v3 |
| 60 | + with: |
| 61 | + repository: ${{steps.get_basic_info.outputs.author}}/dify-plugins |
| 62 | + path: dify-plugins |
| 63 | + token: ${{ secrets.PLUGIN_ACTION }} |
| 64 | + fetch-depth: 1 |
| 65 | + persist-credentials: true |
| 66 | + |
| 67 | + - name: Prepare and create PR |
| 68 | + run: | |
| 69 | + PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg" |
| 70 | + mkdir -p dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }} |
| 71 | + mv "$PACKAGE_NAME" dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}/ |
| 72 | +
|
| 73 | + cd dify-plugins |
| 74 | +
|
| 75 | + git config user.name "GitHub Actions" |
| 76 | + git config user.email "[email protected]" |
| 77 | +
|
| 78 | + git fetch origin main |
| 79 | + git checkout main |
| 80 | + git pull origin main |
| 81 | +
|
| 82 | + BRANCH_NAME="bump-${{ steps.get_basic_info.outputs.plugin_name }}-plugin-${{ steps.get_basic_info.outputs.version }}" |
| 83 | + git checkout -b "$BRANCH_NAME" |
| 84 | +
|
| 85 | + git add . |
| 86 | + git commit -m "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" |
| 87 | +
|
| 88 | + git push -u origin "$BRANCH_NAME" --force |
| 89 | +
|
| 90 | + git branch -a |
| 91 | + echo "Waiting for branch to sync..." |
| 92 | + sleep 10 # Wait 10 seconds for branch sync |
| 93 | +
|
| 94 | + - name: Create PR via GitHub API |
| 95 | + env: |
| 96 | + # How to config the token: |
| 97 | + # 1. Profile -> Settings -> Developer settings -> Personal access tokens -> Generate new token (with repo scope) -> Copy the token |
| 98 | + # 2. Go to the target repository -> Settings -> Secrets and variables -> Actions -> New repository secret -> Add the token as PLUGIN_ACTION |
| 99 | + GH_TOKEN: ${{ secrets.PLUGIN_ACTION }} |
| 100 | + run: | |
| 101 | + gh pr create \ |
| 102 | + --repo langgenius/dify-plugins \ |
| 103 | + --head "${{ steps.get_basic_info.outputs.author }}:${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}" \ |
| 104 | + --base main \ |
| 105 | + --title "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" \ |
| 106 | + --body "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin package to version ${{ steps.get_basic_info.outputs.version }} |
| 107 | +
|
| 108 | + Changes: |
| 109 | + - Updated plugin package file" || echo "PR already exists or creation skipped." # Handle cases where PR already exists |
0 commit comments