Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 54 additions & 45 deletions .github/workflows/publish-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,56 @@ concurrency:
group: publish-cli-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: write

jobs:
build:
runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
runs-on: ${{ matrix.goarch == 'arm64' && 'arm64_runner' || 'ubuntu-latest' }}
if: github.repository == 'langgenius/dify-plugin-daemon'
strategy:
matrix:
include:
- platform: linux/amd64
- platform: linux/arm64
- goarch: amd64
- goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Transform platform
run: |
GOARCH=$(echo "${{ matrix.platform }}" | cut -d '/' -f 2)
echo "GOARCH=$GOARCH" >> $GITHUB_ENV

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Build CLI
- name: Build Linux archive
run: |
make package-cli GOOS=linux GOARCH=${{ matrix.goarch }} VERSION=v${{ github.event.release.tag_name }}

- name: Build Windows archive
run: |
go mod tidy
CGO_ENABLED=0 GOOS=windows GOARCH=${{ env.GOARCH }} go build -ldflags "-X 'main.VersionX=v${{ github.event.release.tag_name }}'" -o dify-plugin-windows-${{ env.GOARCH }}.exe ./cmd/commandline
CGO_ENABLED=0 GOOS=darwin GOARCH=${{ env.GOARCH }} go build -ldflags "-X 'main.VersionX=v${{ github.event.release.tag_name }}'" -o dify-plugin-darwin-${{ env.GOARCH }} ./cmd/commandline
CGO_ENABLED=0 GOOS=linux GOARCH=${{ env.GOARCH }} go build -ldflags "-X 'main.VersionX=v${{ github.event.release.tag_name }}'" -o dify-plugin-linux-${{ env.GOARCH }} ./cmd/commandline
make package-cli GOOS=windows GOARCH=${{ matrix.goarch }} VERSION=v${{ github.event.release.tag_name }}

- name: Upload Artifacts
- name: Build Darwin binary for signing
run: |
make build-cli GOOS=darwin GOARCH=${{ matrix.goarch }} VERSION=v${{ github.event.release.tag_name }}

- name: Upload Darwin build artifact
uses: actions/upload-artifact@v4
with:
name: builds-${{ env.GOARCH }}
path: |
dify-plugin-darwin-${{ env.GOARCH }}
name: cli-darwin-${{ matrix.goarch }}
path: dist/build/cli/darwin-${{ matrix.goarch }}

- name: Upload windows/linux binaries to release
- name: Upload Linux and Windows archives to release
if: github.event_name == 'release'
run: |
gh release upload ${{ github.event.release.tag_name }} dify-plugin-windows-${{ env.GOARCH }}.exe --clobber
gh release upload ${{ github.event.release.tag_name }} dify-plugin-linux-${{ env.GOARCH }} --clobber
gh release upload ${{ github.event.release.tag_name }} \
dist/assets/dify-plugin-linux-${{ matrix.goarch }}.tar.gz \
dist/assets/dify-plugin-windows-${{ matrix.goarch }}.zip \
--clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sign-macos-binary-and-upload:
sign-macos-archive-and-upload:
needs: build
runs-on: macos-latest
if: github.repository == 'langgenius/dify-plugin-daemon'
Expand All @@ -70,57 +74,62 @@ jobs:
security import certificate.p12 -k build.keychain -P "${{ secrets.MACOS_CERT_PASSWORD }}" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k "" build.keychain

- name: Download arm64 binary
- name: Download arm64 build artifact
uses: actions/download-artifact@v4
with:
name: builds-arm64
name: cli-darwin-arm64
path: dist/build/cli/darwin-arm64

- name: Download amd64 binary
- name: Download amd64 build artifact
uses: actions/download-artifact@v4
with:
name: builds-amd64
name: cli-darwin-amd64
path: dist/build/cli/darwin-amd64

- name: Sign binaries
run: |
codesign --timestamp --options=runtime --sign "${{ secrets.MACOS_CERT_NAME }}" ./dify-plugin-darwin-arm64
codesign --timestamp --options=runtime --sign "${{ secrets.MACOS_CERT_NAME }}" ./dify-plugin-darwin-amd64
codesign --timestamp --options=runtime --sign "${{ secrets.MACOS_CERT_NAME }}" ./dist/build/cli/darwin-arm64/dify-plugin-darwin-arm64/dify-plugin
codesign --timestamp --options=runtime --sign "${{ secrets.MACOS_CERT_NAME }}" ./dist/build/cli/darwin-amd64/dify-plugin-darwin-amd64/dify-plugin

- name: Create zip for notarization
- name: Create notarization bundles
run: |
zip -r dify-plugin-darwin-arm64.zip ./dify-plugin-darwin-arm64
zip -r dify-plugin-darwin-amd64.zip ./dify-plugin-darwin-amd64
mkdir -p dist/notary
(
cd dist/build/cli/darwin-arm64
zip -rq "$GITHUB_WORKSPACE/dist/notary/dify-plugin-darwin-arm64.zip" dify-plugin-darwin-arm64
)
(
cd dist/build/cli/darwin-amd64
zip -rq "$GITHUB_WORKSPACE/dist/notary/dify-plugin-darwin-amd64.zip" dify-plugin-darwin-amd64
)

- name: Notarize binaries
run: |
xcrun notarytool submit dify-plugin-darwin-arm64.zip \
xcrun notarytool submit dist/notary/dify-plugin-darwin-arm64.zip \
--apple-id "${{ secrets.AC_USERNAME }}" \
--password "${{ secrets.AC_PASSWORD }}" \
--team-id "${{ secrets.TEAM_ID }}" \
--wait &

xcrun notarytool submit dify-plugin-darwin-amd64.zip \
xcrun notarytool submit dist/notary/dify-plugin-darwin-amd64.zip \
--apple-id "${{ secrets.AC_USERNAME }}" \
--password "${{ secrets.AC_PASSWORD }}" \
--team-id "${{ secrets.TEAM_ID }}" \
--wait &

wait

# Staple is not needed for CLI
# - name: Staple notarization ticket to binaries
# run: |
# xcrun stapler staple ./dify-plugin-darwin-arm64
# xcrun stapler staple ./dify-plugin-darwin-amd64

# - name: Verify signatures
# run: |
# spctl --assess --type exec --verbose=4 ./dify-plugin-darwin-arm64
# spctl --assess --type exec --verbose=4 ./dify-plugin-darwin-amd64
- name: Package signed Darwin archives
run: |
make archive-cli GOOS=darwin GOARCH=arm64
make archive-cli GOOS=darwin GOARCH=amd64

- name: Upload signed binaries
- name: Upload signed Darwin archives
if: github.event_name == 'release'
run: |
gh release upload ${{ github.event.release.tag_name }} dify-plugin-darwin-arm64 --clobber
gh release upload ${{ github.event.release.tag_name }} dify-plugin-darwin-amd64 --clobber
gh release upload ${{ github.event.release.tag_name }} \
dist/assets/dify-plugin-darwin-arm64.tar.gz \
dist/assets/dify-plugin-darwin-amd64.tar.gz \
--clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59 changes: 59 additions & 0 deletions .github/workflows/publish-slim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and Publish Slim

on:
release:
types: [published]

concurrency:
group: publish-slim-${{ github.event.release.id }}
cancel-in-progress: false

permissions:
contents: write

jobs:
build-and-upload:
if: github.repository == 'langgenius/dify-plugin-daemon'
runs-on: ${{ matrix.goarch == 'arm64' && 'arm64_runner' || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
archive_ext: tar.gz
- goos: linux
goarch: arm64
archive_ext: tar.gz
- goos: darwin
goarch: amd64
archive_ext: tar.gz
- goos: darwin
goarch: arm64
archive_ext: tar.gz
- goos: windows
goarch: amd64
archive_ext: zip
- goos: windows
goarch: arm64
archive_ext: zip

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Build and package slim
run: make package-slim GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}

- name: Upload package to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${{ github.event.release.tag_name }}" \
"dist/assets/dify-plugin-slim-${{ matrix.goos }}-${{ matrix.goarch }}.${{ matrix.archive_ext }}" \
--clobber
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
release/
dist/
logs/
.vscode/
.idea/
Expand All @@ -14,4 +15,4 @@ working
cwd/
bin/
.venv/
integration_test_cwd/
integration_test_cwd/
33 changes: 21 additions & 12 deletions .script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ if [ "$OS" != "darwin" ] && [ "$OS" != "linux" ]; then
exit 1
fi

# Define download URL and binary name
BINARY_NAME="dify-plugin-$OS-$ARCH"
DOWNLOAD_URL="https://github.com/langgenius/dify-plugin-daemon/releases/download/$VERSION/$BINARY_NAME"
# Define download URL and archive layout
PACKAGE_NAME="dify-plugin-$OS-$ARCH"
ARCHIVE_NAME="$PACKAGE_NAME.tar.gz"
DOWNLOAD_URL="https://github.com/langgenius/dify-plugin-daemon/releases/download/$VERSION/$ARCHIVE_NAME"
Comment thread
crazywoola marked this conversation as resolved.

# Set installation directory based on OS
if [ "$OS" = "darwin" ]; then
Expand All @@ -46,28 +47,36 @@ fi
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || exit 1

# Download the binary
echo "Downloading $BINARY_NAME..."
# Download and extract the archive
echo "Downloading $ARCHIVE_NAME..."
if command -v curl >/dev/null 2>&1; then
curl -L -o "dify-plugin-daemon" "$DOWNLOAD_URL"
curl -L -o "$ARCHIVE_NAME" "$DOWNLOAD_URL"
elif command -v wget >/dev/null 2>&1; then
wget -O "dify-plugin-daemon" "$DOWNLOAD_URL"
wget -O "$ARCHIVE_NAME" "$DOWNLOAD_URL"
else
echo "Error: Neither curl nor wget is installed"
rm -rf "$TMP_DIR"
exit 1
fi

# Make binary executable
chmod +x "dify-plugin-daemon"
tar -xzf "$ARCHIVE_NAME"

EXTRACTED_BINARY="$PACKAGE_NAME/dify-plugin"
if [ ! -f "$EXTRACTED_BINARY" ]; then
echo "Error: Expected binary not found at $EXTRACTED_BINARY"
rm -rf "$TMP_DIR"
exit 1
fi

chmod +x "$EXTRACTED_BINARY"

# Install the binary with the new name
if [ "$NEED_SUDO" = true ]; then
echo "Installing to $INSTALL_DIR (requires sudo)..."
sudo mv "dify-plugin-daemon" "$INSTALL_DIR/dify-plugin"
sudo mv "$EXTRACTED_BINARY" "$INSTALL_DIR/dify-plugin"
else
echo "Installing to $INSTALL_DIR..."
mv "dify-plugin-daemon" "$INSTALL_DIR/dify-plugin"
mv "$EXTRACTED_BINARY" "$INSTALL_DIR/dify-plugin"
fi

# Clean up
Expand Down Expand Up @@ -96,4 +105,4 @@ if [ "$OS" = "darwin" ]; then
fi
fi

echo "Installation completed! The dify plugin daemon has been installed to $INSTALL_DIR/dify-plugin"
echo "Installation completed! The dify plugin daemon has been installed to $INSTALL_DIR/dify-plugin"
89 changes: 89 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
SHELL := /bin/bash

DIST_DIR := dist
BUILD_DIR := $(DIST_DIR)/build
ASSETS_DIR := $(DIST_DIR)/assets

VERSION ?= dev
GO_BUILD_FLAGS := -trimpath

CLI_TARGET := ./cmd/commandline
SLIM_TARGET := ./cmd/slim

.PHONY: clean build-cli archive-cli package-cli build-slim archive-slim package-slim

clean:
rm -rf $(DIST_DIR)

build-cli:
@test -n "$(GOOS)" || (echo "GOOS is required" >&2; exit 1)
@test -n "$(GOARCH)" || (echo "GOARCH is required" >&2; exit 1)
@binary_name="dify-plugin"; \
package_name="dify-plugin-$(GOOS)-$(GOARCH)"; \
stage_dir="$(BUILD_DIR)/cli/$(GOOS)-$(GOARCH)/$$package_name"; \
if [[ "$(GOOS)" == "windows" ]]; then \
binary_name="$$binary_name.exe"; \
fi; \
rm -rf "$$stage_dir"; \
mkdir -p "$$stage_dir"; \
CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" \
go build $(GO_BUILD_FLAGS) -ldflags "-X main.VersionX=$(VERSION)" \
-o "$$stage_dir/$$binary_name" $(CLI_TARGET); \
cp LICENSE "$$stage_dir/LICENSE"

archive-cli:
Comment thread
crazywoola marked this conversation as resolved.
@test -n "$(GOOS)" || (echo "GOOS is required" >&2; exit 1)
@test -n "$(GOARCH)" || (echo "GOARCH is required" >&2; exit 1)
@package_name="dify-plugin-$(GOOS)-$(GOARCH)"; \
stage_root="$(BUILD_DIR)/cli/$(GOOS)-$(GOARCH)"; \
stage_dir="$$stage_root/$$package_name"; \
asset_root="$$(pwd)/$(ASSETS_DIR)"; \
test -d "$$stage_dir" || (echo "missing build directory: $$stage_dir" >&2; exit 1); \
mkdir -p "$$asset_root"; \
if [[ "$(GOOS)" == "windows" ]]; then \
asset_path="$$asset_root/$$package_name.zip"; \
rm -f "$$asset_path"; \
(cd "$$stage_root" && zip -rq "$$asset_path" "$$package_name"); \
else \
asset_path="$$asset_root/$$package_name.tar.gz"; \
rm -f "$$asset_path"; \
tar -C "$$stage_root" -czf "$$asset_path" "$$package_name"; \
fi

package-cli: build-cli archive-cli
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

By making package-cli depend only on archive-cli (which in turn depends on build-cli), you avoid potential race conditions during parallel builds (e.g., make -j) where the archiver might start before the compiler finishes.

package-cli: archive-cli


build-slim:
@test -n "$(GOOS)" || (echo "GOOS is required" >&2; exit 1)
@test -n "$(GOARCH)" || (echo "GOARCH is required" >&2; exit 1)
@binary_name="dify-plugin-slim"; \
package_name="dify-plugin-slim-$(GOOS)-$(GOARCH)"; \
stage_dir="$(BUILD_DIR)/slim/$(GOOS)-$(GOARCH)/$$package_name"; \
if [[ "$(GOOS)" == "windows" ]]; then \
binary_name="$$binary_name.exe"; \
fi; \
rm -rf "$$stage_dir"; \
mkdir -p "$$stage_dir"; \
CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" \
go build $(GO_BUILD_FLAGS) -o "$$stage_dir/$$binary_name" $(SLIM_TARGET); \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The build-slim target is missing the version injection via -ldflags, which is present in the build-cli target. This ensures that the binary reports the correct version when queried, maintaining consistency across all distributed binaries.

		CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" \
			go build $(GO_BUILD_FLAGS) -ldflags "-X main.VersionX=$(VERSION)" \
			-o "$$stage_dir/$$binary_name" $(SLIM_TARGET); \

cp LICENSE "$$stage_dir/LICENSE"

archive-slim:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The archive-slim target depends on the output of build-slim. Adding an explicit dependency ensures that the build step always runs before archiving.

archive-slim: build-slim

@test -n "$(GOOS)" || (echo "GOOS is required" >&2; exit 1)
@test -n "$(GOARCH)" || (echo "GOARCH is required" >&2; exit 1)
@package_name="dify-plugin-slim-$(GOOS)-$(GOARCH)"; \
stage_root="$(BUILD_DIR)/slim/$(GOOS)-$(GOARCH)"; \
stage_dir="$$stage_root/$$package_name"; \
asset_root="$$(pwd)/$(ASSETS_DIR)"; \
test -d "$$stage_dir" || (echo "missing build directory: $$stage_dir" >&2; exit 1); \
mkdir -p "$$asset_root"; \
if [[ "$(GOOS)" == "windows" ]]; then \
asset_path="$$asset_root/$$package_name.zip"; \
rm -f "$$asset_path"; \
(cd "$$stage_root" && zip -rq "$$asset_path" "$$package_name"); \
else \
asset_path="$$asset_root/$$package_name.tar.gz"; \
rm -f "$$asset_path"; \
tar -C "$$stage_root" -czf "$$asset_path" "$$package_name"; \
fi

package-slim: build-slim archive-slim
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

By making package-slim depend only on archive-slim, you ensure a correct execution order during parallel builds.

package-slim: archive-slim

Loading
Loading