-
Notifications
You must be signed in to change notification settings - Fork 289
refactor: add makefile and refactor the github action #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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: | ||
|
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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| 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); \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| cp LICENSE "$$stage_dir/LICENSE" | ||
|
|
||
| archive-slim: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Uh oh!
There was an error while loading. Please reload this page.