diff --git a/.github/workflows/publish-cli.yaml b/.github/workflows/publish-cli.yaml index 144a7f554..8ebf6b39c 100644 --- a/.github/workflows/publish-cli.yaml +++ b/.github/workflows/publish-cli.yaml @@ -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' @@ -70,35 +74,44 @@ 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 }}" \ @@ -106,21 +119,17 @@ jobs: 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 }} diff --git a/.github/workflows/publish-slim.yaml b/.github/workflows/publish-slim.yaml new file mode 100644 index 000000000..048d8a200 --- /dev/null +++ b/.github/workflows/publish-slim.yaml @@ -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 diff --git a/.gitignore b/.gitignore index f4396dbca..b336b390f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ release/ +dist/ logs/ .vscode/ .idea/ @@ -14,4 +15,4 @@ working cwd/ bin/ .venv/ -integration_test_cwd/ \ No newline at end of file +integration_test_cwd/ diff --git a/.script/install.sh b/.script/install.sh index c9e94491f..d1b90278f 100755 --- a/.script/install.sh +++ b/.script/install.sh @@ -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" # Set installation directory based on OS if [ "$OS" = "darwin" ]; then @@ -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 @@ -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" \ No newline at end of file +echo "Installation completed! The dify plugin daemon has been installed to $INSTALL_DIR/dify-plugin" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..a2b34d757 --- /dev/null +++ b/Makefile @@ -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: + @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 + +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); \ + cp LICENSE "$$stage_dir/LICENSE" + +archive-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 diff --git a/README.md b/README.md index b30912c02..887b9bc47 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,22 @@ brew tap langgenius/dify brew install dify ``` -- Install with the binary file +- Install with the install script -Download the binary file from the assets' list in [the release page](https://github.com/langgenius/dify-plugin-daemon/releases). +```bash +curl -fsSL https://raw.githubusercontent.com/langgenius/dify-plugin-daemon/main/.script/install.sh | VERSION=0.0.7 bash +``` + +- Install manually + +Download the archive for your platform from [the release page](https://github.com/langgenius/dify-plugin-daemon/releases) and extract it: + +```bash +# linux/macOS example (amd64) +tar -xzf dify-plugin-linux-amd64.tar.gz +chmod +x dify-plugin-linux-amd64/dify-plugin +sudo mv dify-plugin-linux-amd64/dify-plugin /usr/local/bin/dify-plugin +``` ## Development diff --git a/cmd/commandline/plugin/templates/.github/workflows/plugin-publish.yml b/cmd/commandline/plugin/templates/.github/workflows/plugin-publish.yml index d24c4dd51..f0939f00e 100644 --- a/cmd/commandline/plugin/templates/.github/workflows/plugin-publish.yml +++ b/cmd/commandline/plugin/templates/.github/workflows/plugin-publish.yml @@ -16,12 +16,14 @@ jobs: mkdir -p $RUNNER_TEMP/bin cd $RUNNER_TEMP/bin - wget https://github.com/langgenius/dify-plugin-daemon/releases/download/0.0.6/dify-plugin-linux-amd64 - chmod +x dify-plugin-linux-amd64 + wget https://github.com/langgenius/dify-plugin-daemon/releases/download/0.0.7/dify-plugin-linux-amd64.tar.gz + tar -xzf dify-plugin-linux-amd64.tar.gz + chmod +x dify-plugin-linux-amd64/dify-plugin + mv dify-plugin-linux-amd64/dify-plugin dify-plugin echo "CLI tool location:" pwd - ls -la dify-plugin-linux-amd64 + ls -la dify-plugin - name: Get basic info from manifest id: get_basic_info @@ -44,7 +46,7 @@ jobs: run: | cd $GITHUB_WORKSPACE PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg" - $RUNNER_TEMP/bin/dify-plugin-linux-amd64 plugin package . -o "$PACKAGE_NAME" + $RUNNER_TEMP/bin/dify-plugin plugin package . -o "$PACKAGE_NAME" echo "Package result:" ls -la "$PACKAGE_NAME"