From 8409b7657049f31082a0470c9f4cc9b0639dfa58 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Mon, 8 Apr 2024 22:27:27 +0200 Subject: [PATCH] Add build workflow for different platforms (#23) * Add build workflow for different platforms * Add release workflow * Use PLUGIN_NAME variable * Fix message --- .github/workflows/release.yml | 40 +++++++++++++++++++++++++++++ .gitignore | 1 + Makefile | 47 +++++++++++++++++++++++++++++------ plugin/module.go | 3 ++- 4 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3f7159d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: Build and release gatewayd-plugin-cache + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + build-and-release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go 1.22 + uses: actions/setup-go@v3 + with: + go-version: "1.22" + cache: true + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu + - name: Build and release binaries + run: | + make build-release + - name: Create release and add artifacts + uses: softprops/action-gh-release@v1 + with: + files: | + dist/*.tar.gz + dist/checksums.txt + dist/*.zip + draft: false + prerelease: false + tag_name: ${{ github.ref_name }} + name: ${{ github.ref_name }} + generate_release_notes: true diff --git a/.gitignore b/.gitignore index edd1bbe..92d8beb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ # vendor/ gatewayd-plugin-sql-ids-ips +dist/ diff --git a/Makefile b/Makefile index dfd0f55..bea3043 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,51 @@ +PLUGIN_NAME=gatewayd-plugin-sql-ids-ips +PROJECT_URL=github.com/gatewayd-io/$(PLUGIN_NAME) +CONFIG_PACKAGE=${PROJECT_URL}/plugin +LAST_TAGGED_COMMIT=$(shell git rev-list --tags --max-count=1) +VERSION=$(shell git describe --tags ${LAST_TAGGED_COMMIT}) +EXTRA_LDFLAGS=-X ${CONFIG_PACKAGE}.Version=$(shell echo ${VERSION} | sed 's/^v//') +FILES=$(PLUGIN_NAME) checksum.txt gatewayd_plugin.yaml README.md LICENSE + tidy: - go mod tidy + @go mod tidy build: tidy - go build -ldflags "-s -w" + @go build -ldflags "-s -w" checksum: - sha256sum -b gatewayd-plugin-sql-ids-ips + @sha256sum -b $(PLUGIN_NAME) update-all: - go get -u ./... - go mod tidy + @go get -u ./... + @go mod tidy build-dev: tidy - go build + @go build test: - go test -v ./... + @go test -v ./... + +create-build-dir: + @mkdir -p dist + +build-release: tidy create-build-dir + @echo "Building ${PLUGIN_NAME} ${VERSION} for release" + @$(MAKE) build-platform GOOS=linux GOARCH=amd64 OUTPUT_DIR=dist/linux-amd64 + @$(MAKE) build-platform GOOS=linux GOARCH=arm64 OUTPUT_DIR=dist/linux-arm64 + @$(MAKE) build-platform GOOS=darwin GOARCH=amd64 OUTPUT_DIR=dist/darwin-amd64 + @$(MAKE) build-platform GOOS=darwin GOARCH=arm64 OUTPUT_DIR=dist/darwin-arm64 + @$(MAKE) build-platform GOOS=windows GOARCH=amd64 OUTPUT_DIR=dist/windows-amd64 + @$(MAKE) build-platform GOOS=windows GOARCH=arm64 OUTPUT_DIR=dist/windows-arm64 + +build-platform: tidy + @echo "Building ${PLUGIN_NAME} ${VERSION} for $(GOOS)-$(GOARCH)" + @mkdir -p $(OUTPUT_DIR) + @cp README.md LICENSE gatewayd_plugin.yaml $(OUTPUT_DIR)/ + @GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/$(PLUGIN_NAME) + @sha256sum $(OUTPUT_DIR)/$(PLUGIN_NAME) | sed 's#$(OUTPUT_DIR)/##g' >> $(OUTPUT_DIR)/checksum.txt + @if [ "$(GOOS)" = "windows" ]; then \ + zip -q -r dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.zip -j $(OUTPUT_DIR)/; \ + else \ + tar czf dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.tar.gz -C $(OUTPUT_DIR)/ ${FILES}; \ + fi + @sha256sum dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.* | sed '#dist/##g' >> dist/checksums.txt diff --git a/plugin/module.go b/plugin/module.go index 0de4891..4571988 100644 --- a/plugin/module.go +++ b/plugin/module.go @@ -7,9 +7,10 @@ import ( ) var ( + Version = "0.0.0" PluginID = v1.PluginID{ Name: "gatewayd-plugin-sql-ids-ips", - Version: "0.0.5", + Version: Version, RemoteUrl: "github.com/gatewayd-io/gatewayd-plugin-sql-ids-ips", } PluginMap = map[string]goplugin.Plugin{