Skip to content

Commit f5bcd09

Browse files
committed
ci: implement difypkg release job
1 parent 5ddc40d commit f5bcd09

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

.github/workflows/release.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# This workflow builds the difypkg and uploads it to the current pre-release.
2+
3+
name: Release Dify Package
4+
5+
on:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/[email protected]
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Get the latest tag
21+
id: get_tag
22+
run: |
23+
echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
24+
25+
- name: Check for pre-release
26+
id: check_prerelease
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
tag=${{ steps.get_tag.outputs.tag }}
31+
owner=${{ github.repository_owner }}
32+
repo_name=$(basename `git rev-parse --show-toplevel`)
33+
release=$(curl -X GET -H "Accept: application/vnd.github.v3+json" \
34+
-H "Authorization: token $GITHUB_TOKEN" \
35+
https://api.github.com/repos/$owner/$repo_name/releases/tags/$tag)
36+
37+
if [[ $(echo "$release" | jq -r '.prerelease') != "true" ]]; then
38+
echo "Pre-release not found for tag $tag. Exiting."
39+
exit 1
40+
fi
41+
42+
# Store the release URL for uploading assets later
43+
echo "release_url=$(echo "$release" | jq -r '.upload_url')" >> $GITHUB_OUTPUT
44+
45+
- name: Check for existing difypkg file
46+
run: |
47+
tag=${{ steps.get_tag.outputs.tag }}
48+
repo_name=$(basename `git rev-parse --show-toplevel`)
49+
if [ -f "$repo_name-$tag.difypkg" ]; then
50+
echo "File $repo_name-$tag.difypkg already exists. Exiting."
51+
exit 0
52+
fi
53+
54+
- name: Get latest release
55+
id: latest_release
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
60+
https://api.github.com/repos/langgenius/dify-plugin-daemon/releases/latest)
61+
62+
# Extract browser_download_url which is directly downloadable
63+
download_url=$(echo $response | jq -r '.assets[] | select(.name == "dify-plugin-linux-amd64") | .browser_download_url')
64+
echo "download_url=$download_url" >> $GITHUB_OUTPUT
65+
66+
# Optional: Extract the version for reference
67+
echo "version=$(echo $response | jq -r '.tag_name')" >> $GITHUB_OUTPUT
68+
69+
- name: Download Dify Plugin
70+
run: |
71+
if [ -z "${{ steps.latest_release.outputs.download_url }}" ]; then
72+
echo "Asset not found in the latest release. Exiting."
73+
exit 1
74+
fi
75+
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o dify "${{ steps.latest_release.outputs.download_url }}"
76+
chmod +x dify
77+
78+
- name: Run Dify Plugin Package
79+
run: |
80+
PLUGIN_DIR=$(pwd)
81+
./dify plugin package $PLUGIN_DIR
82+
83+
- name: Set package filename
84+
id: set_package_file
85+
run: |
86+
repo_name=$(basename `git rev-parse --show-toplevel`)
87+
tag=${{ steps.get_tag.outputs.tag }}
88+
echo "package_file=$repo_name.difypkg" >> $GITHUB_OUTPUT
89+
90+
- name: Upload package to GitHub Release
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
uses: actions/upload-release-asset@v1
94+
with:
95+
upload_url: ${{ steps.check_prerelease.outputs.release_url }}
96+
asset_path: ./${{ steps.set_package_file.outputs.package_file }}
97+
asset_name: ${{ steps.set_package_file.outputs.package_file }}
98+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)