plugin-publish.yml 4.3 KB

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