-
Notifications
You must be signed in to change notification settings - Fork 10
159 lines (138 loc) · 5.93 KB
/
pre-check-plugin.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Pre Check Plugin
on:
pull_request:
types: [opened, synchronize, ready_for_review, review_requested, edited]
branches:
- main
- dev
paths-ignore:
- ".github/**"
- ".gitignore"
- "unpacked_plugin/**"
- "README.md"
- "LICENSE"
env:
REPO_NAME: langgenius/dify-plugins
jobs:
pre-check-plugin:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Plugin Daemon
env:
GH_TOKEN: ${{ secrets.ORG_SCOPE_GITHUB_TOKEN }}
run: |
gh release download -R langgenius/dify-plugin-daemon --pattern "dify-plugin-linux-amd64" --dir .scripts
chmod +x .scripts/dify-plugin-linux-amd64
- name: Clone Marketplace Toolkit
env:
GH_TOKEN: ${{ secrets.ORG_SCOPE_GITHUB_TOKEN }}
run: |
gh repo clone https://github.com/langgenius/dify-marketplace-backend -- -b deploy/dev
cp -r dify-marketplace-backend/toolkit/* .scripts/
rm -rf dify-marketplace-backend
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12.7
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: yq - portable yaml processor
uses: mikefarah/yq@v4.44.5
- name: Get PR Path
env:
GH_TOKEN: ${{ secrets.ORG_SCOPE_GITHUB_TOKEN }}
run: |
export PR_FILES=$(gh pr view -R ${{ env.REPO_NAME }} ${{ github.event.pull_request.number }} --json files --jq .files)
if PLUGIN_PATH=$(python3 .scripts/validator/check-pkg-paths.py); then
echo $PLUGIN_PATH
echo "PLUGIN_PATH=$PLUGIN_PATH" >> $GITHUB_ENV
else
echo "Only one .difypkg file change is allowed in a single PR."
exit 1
fi
- name: Unpack File
run: |
mv ${{ env.PLUGIN_PATH }} ${{ env.PLUGIN_PATH }}.zip
mkdir -p unpacked_plugin
unzip ${{ env.PLUGIN_PATH }}.zip -d unpacked_plugin
echo "PLUGIN_PATH=unpacked_plugin" >> $GITHUB_ENV
- name: Check Plugin Manifest
env:
GH_TOKEN: ${{ secrets.ORG_SCOPE_GITHUB_TOKEN }}
run: |
# manifest.yaml author must not be langgenius
if yq '.author' ${{ env.PLUGIN_PATH }}/manifest.yaml | grep -q "langgenius"; then
echo "!!! Plugin manifest.yaml author must not be 'langgenius'"
exit 1
fi
# author must equal to the pr author (lowercase)
if [ "$(yq '.author' ${{ env.PLUGIN_PATH }}/manifest.yaml)" != "$(gh pr view -R ${{ env.REPO_NAME }} ${{ github.event.pull_request.number }} --json author --jq .author.login | tr '[:upper:]' '[:lower:]')" ]; then
echo "!!! Plugin manifest.yaml author should be lowercase and must be the same as the PR author"
exit 1
fi
- name: Check If Version Exists
run: |
# get version, author, name
VERSION=$(yq '.version' ${{ env.PLUGIN_PATH }}/manifest.yaml)
AUTHOR=$(yq '.author' ${{ env.PLUGIN_PATH }}/manifest.yaml)
NAME=$(yq '.name' ${{ env.PLUGIN_PATH }}/manifest.yaml)
echo "Checking plugin version: $VERSION"
# Check if the version already exists
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" "${{ secrets.MARKETPLACE_BASE_URL }}/api/v1/plugins/$AUTHOR/$NAME/$VERSION")
if [ "$RESPONSE_CODE" = "200" ]; then
RESPONSE=$(curl -s "${{ secrets.MARKETPLACE_BASE_URL }}/api/v1/plugins/$AUTHOR/$NAME/$VERSION")
if [ "$(echo "$RESPONSE" | jq -r '.code')" = "0" ]; then
echo "!!! Plugin version $VERSION already exists, please update the version number in manifest.yaml"
exit 1
fi
fi
- name: Check Plugin Deps
run: |
if [ -f ${{ env.PLUGIN_PATH }}/requirements.txt ]; then
echo "Trying to install plugin dependencies..."
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r ${{ env.PLUGIN_PATH }}/requirements.txt
deactivate
fi
- name: Check Plugin Install
run: |
if [ -f ${{ env.PLUGIN_PATH }}/requirements.txt ]; then
source .venv/bin/activate
fi
export INSTALL_METHOD=aws_lambda
python3 .scripts/validator/test-plugin-install.py -d ${{ env.PLUGIN_PATH }}
- name: Check Packaging
run: |
python3 .scripts/uploader/upload-package.py -d ${{ env.PLUGIN_PATH }} -t ${{ secrets.MARKETPLACE_TOKEN }} --plugin-daemon-path .scripts/dify-plugin-linux-amd64 -u ${{ secrets.MARKETPLACE_BASE_URL }} -f --test
- name: Comment on failure
if: failure()
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = context.payload.pull_request;
const runId = process.env.GITHUB_RUN_ID;
const repoUrl = `https://github.com/${{ github.repository }}/actions/runs/${runId}`;
github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ❌ Failed \n The pre-check plugin workflow failed. Please check the logs for more details \n [View Logs](${repoUrl})`
})
- name: Comment on success
if: success()
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## ✅ Success \n The pre-check plugin workflow passed. Please wait for maintainer to review your PR.'
})