1+ # .github/workflows/auto-pr.yml
2+ name : Auto Create PR on Main Push
3+
4+ on :
5+ push :
6+ branches : [ main ] # Trigger on push to main
7+
8+ jobs :
9+ create_pr : # Renamed job for clarity
10+ runs-on : ubuntu-latest
11+ steps :
12+ - name : Checkout code
13+ uses : actions/checkout@v3
14+
15+ - name : Print working directory # Kept for debugging
16+ run : |
17+ pwd
18+ ls -la
19+
20+ - name : Download CLI tool
21+ run : |
22+ # Create bin directory in runner temp
23+ mkdir -p $RUNNER_TEMP/bin
24+ cd $RUNNER_TEMP/bin
25+
26+ # Download CLI tool
27+ wget https://github.com/langgenius/dify-plugin-daemon/releases/download/0.0.6/dify-plugin-linux-amd64
28+ chmod +x dify-plugin-linux-amd64
29+
30+ # Show download location and file
31+ echo "CLI tool location:"
32+ pwd
33+ ls -la dify-plugin-linux-amd64
34+
35+ - name : Get basic info from manifest # Changed step name and content
36+ id : get_basic_info
37+ run : |
38+ PLUGIN_NAME=$(grep "^name:" manifest.yaml | cut -d' ' -f2)
39+ echo "Plugin name: $PLUGIN_NAME"
40+ echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT
41+
42+ VERSION=$(grep "^version:" manifest.yaml | cut -d' ' -f2)
43+ echo "Plugin version: $VERSION"
44+ echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
46+ # If the author's name is not your github username, you can change the author here
47+ AUTHOR=$(grep "^author:" manifest.yaml | cut -d' ' -f2)
48+ echo "Plugin author: $AUTHOR"
49+ echo "author=$AUTHOR" >> $GITHUB_OUTPUT
50+
51+ - name : Package Plugin
52+ id : package
53+ run : |
54+ # Use the downloaded CLI tool to package
55+ cd $GITHUB_WORKSPACE
56+ # Use variables for package name
57+ PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg"
58+ # Use CLI from runner temp
59+ $RUNNER_TEMP/bin/dify-plugin-linux-amd64 plugin package . -o "$PACKAGE_NAME"
60+
61+ # Show packaging result
62+ echo "Package result:"
63+ ls -la "$PACKAGE_NAME"
64+ echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
65+
66+ # Show full file path and directory structure (kept for debugging)
67+ echo "\\nFull file path:"
68+ pwd
69+ echo "\\nDirectory structure:"
70+ tree || ls -R
71+
72+ - name : Checkout target repo
73+ uses : actions/checkout@v3
74+ with :
75+ # Use author variable for repository
76+ repository : ${{steps.get_basic_info.outputs.author}}/dify-plugins
77+ path : dify-plugins
78+ token : ${{ secrets.PLUGIN_ACTION }}
79+ fetch-depth : 1 # Fetch only the last commit to speed up checkout
80+ persist-credentials : true # Persist credentials for subsequent git operations
81+
82+ - name : Prepare and create PR
83+ run : |
84+ # Debug info (kept)
85+ echo "Debug: Current directory $(pwd)"
86+ # Use variable for package name
87+ PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg"
88+ echo "Debug: Package name: $PACKAGE_NAME"
89+ ls -la
90+
91+ # Move the packaged file to the target directory using variables
92+ mkdir -p dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}
93+ mv "$PACKAGE_NAME" dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}/
94+
95+ # Enter the target repository directory
96+ cd dify-plugins
97+
98+ # Configure git
99+ git config user.name "GitHub Actions"
100+ git config user.email "actions@github.com"
101+
102+ # Ensure we are on the latest main branch
103+ git fetch origin main
104+ git checkout main
105+ git pull origin main
106+
107+ # Create and switch to a new branch using variables and new naming convention
108+ BRANCH_NAME="bump-${{ steps.get_basic_info.outputs.plugin_name }}-plugin-${{ steps.get_basic_info.outputs.version }}"
109+ git checkout -b "$BRANCH_NAME"
110+
111+ # Add and commit changes (using git add .)
112+ git add .
113+ git status # for debugging
114+ # Use variables in commit message
115+ git commit -m "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}"
116+
117+ # Push to remote (use force just in case the branch existed before from a failed run)
118+ git push -u origin "$BRANCH_NAME" --force
119+
120+ # Confirm branch has been pushed and wait for sync (GitHub API might need a moment)
121+ git branch -a
122+ echo "Waiting for branch to sync..."
123+ sleep 10 # Wait 10 seconds for branch sync
124+
125+ - name : Create PR via GitHub API
126+ env :
127+ GH_TOKEN : ${{ secrets.PLUGIN_ACTION }} # Use the provided token for authentication
128+ run : |
129+ gh pr create \
130+ --repo langgenius/dify-plugins \
131+ --head "${{ steps.get_basic_info.outputs.author }}:${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}" \
132+ --base main \
133+ --title "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" \
134+ --body "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin package to version ${{ steps.get_basic_info.outputs.version }}
135+
136+ Changes:
137+ - Updated plugin package file" || echo "PR already exists or creation skipped." # Handle cases where PR already exists
138+
139+ - name : Print environment info # Kept for debugging
140+ run : |
141+ echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
142+ echo "Current directory contents:"
143+ ls -R
0 commit comments