forked from langgenius/dify-official-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (133 loc) · 4.93 KB
/
plugin-e2e-test.yaml
File metadata and controls
153 lines (133 loc) · 4.93 KB
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
name: Plugin E2E Test
on:
push:
branches: [ main ]
paths:
- '**/manifest.yaml'
- '**/provider/**'
- '**/models/**'
- '**/tools/**'
- '**/endpoints/**'
- '**/tests/**'
pull_request:
branches: [ main ]
paths:
- '**/manifest.yaml'
- '**/provider/**'
- '**/models/**'
- '**/tools/**'
- '**/endpoints/**'
- '**/tests/**'
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
plugins: ${{ steps.filter.outputs.plugins }}
has_changes: ${{ steps.filter.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: filter
name: Detect changed plugins
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
CHANGED_FILES=$(gh pr view -R ${{ github.repository }} ${{ github.event.pull_request.number }} --json files --jq '.files[].path')
else
if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then
BASE_SHA="HEAD~1"
else
BASE_SHA="${{ github.event.before }}"
fi
CHANGED_FILES=$(git diff --name-only $BASE_SHA HEAD)
fi
# Find all manifest.yaml files
MANIFESTS=$(find . -name "manifest.yaml" -not -path "*/.*")
VALID_PLUGINS=()
for m in $MANIFESTS; do
PLUGIN_PATH=$(dirname "$m" | sed 's|^\./||')
# If any changed file starts with this plugin path
if echo "$CHANGED_FILES" | grep -q "^$PLUGIN_PATH/"; then
VALID_PLUGINS+=("$PLUGIN_PATH")
fi
done
if [ ${#VALID_PLUGINS[@]} -eq 0 ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "plugins=[]" >> $GITHUB_OUTPUT
else
JSON=$(printf '%s\n' "${VALID_PLUGINS[@]}" | jq -R . | jq -s -c .)
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "plugins=$JSON" >> $GITHUB_OUTPUT
echo "Detected plugins: $JSON"
fi
test:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
plugin_path: ${{ fromJson(needs.detect-changes.outputs.plugins) }}
fail-fast: false
# Using the full plugin path as the environment name
environment: ${{ matrix.plugin_path }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install Homebrew and Dify CLI
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "/home/linuxbrew/.linuxbrew/bin" >> $GITHUB_PATH
echo "/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
/home/linuxbrew/.linuxbrew/bin/brew tap langgenius/dify
/home/linuxbrew/.linuxbrew/bin/brew install dify
- name: Export All Secrets to Environment
uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}
exclude: GITHUB_TOKEN
- name: Package plugin
run: |
SAFE_NAME=$(echo "${{ matrix.plugin_path }}" | tr '/' '-')
PKG_NAME="test-${SAFE_NAME}-package.difypkg"
EXTRACT_DIR="test-${SAFE_NAME}-unpacked"
echo "SAFE_NAME=$SAFE_NAME" >> $GITHUB_ENV
echo "PKG_NAME=$PKG_NAME" >> $GITHUB_ENV
echo "EXTRACT_DIR=$EXTRACT_DIR" >> $GITHUB_ENV
echo "### Packaging plugin at: ${{ matrix.plugin_path }} ###"
dify plugin package ${{ matrix.plugin_path }} --output_path "$PKG_NAME"
echo "### Extracting package ###"
unzip -q "$PKG_NAME" -d "$EXTRACT_DIR"
- name: Check for tests directory
id: check_tests
run: |
if [ -d "${{ env.EXTRACT_DIR }}/tests" ]; then
echo "has_tests=true" >> $GITHUB_OUTPUT
else
echo "has_tests=false" >> $GITHUB_OUTPUT
echo "No tests directory found in plugin"
fi
- name: Install dependencies
if: steps.check_tests.outputs.has_tests == 'true'
working-directory: ${{ env.EXTRACT_DIR }}
run: |
if [ -f "pyproject.toml" ]; then
uv sync --all-groups --python 3.12
elif [ -f "requirements.txt" ]; then
uv venv --python 3.12
uv pip install -r requirements.txt
else
echo "Error: No pyproject.toml or requirements.txt found"
exit 1
fi
- name: Run tests
if: steps.check_tests.outputs.has_tests == 'true'
working-directory: ${{ env.EXTRACT_DIR }}
run: |
PLUGIN_FILE_PATH="$(realpath ../${{ env.PKG_NAME }})" uv run --with pytest pytest