Skip to content

Commit

Permalink
Add build workflow for different platforms (#23)
Browse files Browse the repository at this point in the history
* Add build workflow for different platforms
* Add release workflow
* Use PLUGIN_NAME variable
* Fix message
  • Loading branch information
mostafa authored Apr 8, 2024
1 parent 5940233 commit 8409b76
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# vendor/

gatewayd-plugin-sql-ids-ips
dist/
47 changes: 40 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion plugin/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 8409b76

Please sign in to comment.