Skip to content

Commit 8409b76

Browse files
authored
Add build workflow for different platforms (#23)
* Add build workflow for different platforms * Add release workflow * Use PLUGIN_NAME variable * Fix message
1 parent 5940233 commit 8409b76

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

.github/workflows/release.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and release gatewayd-plugin-cache
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-and-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- name: Set up Go 1.22
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version: "1.22"
23+
cache: true
24+
- name: Install dependencies
25+
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
26+
- name: Build and release binaries
27+
run: |
28+
make build-release
29+
- name: Create release and add artifacts
30+
uses: softprops/action-gh-release@v1
31+
with:
32+
files: |
33+
dist/*.tar.gz
34+
dist/checksums.txt
35+
dist/*.zip
36+
draft: false
37+
prerelease: false
38+
tag_name: ${{ github.ref_name }}
39+
name: ${{ github.ref_name }}
40+
generate_release_notes: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
# vendor/
1616

1717
gatewayd-plugin-sql-ids-ips
18+
dist/

Makefile

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,51 @@
1+
PLUGIN_NAME=gatewayd-plugin-sql-ids-ips
2+
PROJECT_URL=github.com/gatewayd-io/$(PLUGIN_NAME)
3+
CONFIG_PACKAGE=${PROJECT_URL}/plugin
4+
LAST_TAGGED_COMMIT=$(shell git rev-list --tags --max-count=1)
5+
VERSION=$(shell git describe --tags ${LAST_TAGGED_COMMIT})
6+
EXTRA_LDFLAGS=-X ${CONFIG_PACKAGE}.Version=$(shell echo ${VERSION} | sed 's/^v//')
7+
FILES=$(PLUGIN_NAME) checksum.txt gatewayd_plugin.yaml README.md LICENSE
8+
19
tidy:
2-
go mod tidy
10+
@go mod tidy
311

412
build: tidy
5-
go build -ldflags "-s -w"
13+
@go build -ldflags "-s -w"
614

715
checksum:
8-
sha256sum -b gatewayd-plugin-sql-ids-ips
16+
@sha256sum -b $(PLUGIN_NAME)
917

1018
update-all:
11-
go get -u ./...
12-
go mod tidy
19+
@go get -u ./...
20+
@go mod tidy
1321

1422
build-dev: tidy
15-
go build
23+
@go build
1624

1725
test:
18-
go test -v ./...
26+
@go test -v ./...
27+
28+
create-build-dir:
29+
@mkdir -p dist
30+
31+
build-release: tidy create-build-dir
32+
@echo "Building ${PLUGIN_NAME} ${VERSION} for release"
33+
@$(MAKE) build-platform GOOS=linux GOARCH=amd64 OUTPUT_DIR=dist/linux-amd64
34+
@$(MAKE) build-platform GOOS=linux GOARCH=arm64 OUTPUT_DIR=dist/linux-arm64
35+
@$(MAKE) build-platform GOOS=darwin GOARCH=amd64 OUTPUT_DIR=dist/darwin-amd64
36+
@$(MAKE) build-platform GOOS=darwin GOARCH=arm64 OUTPUT_DIR=dist/darwin-arm64
37+
@$(MAKE) build-platform GOOS=windows GOARCH=amd64 OUTPUT_DIR=dist/windows-amd64
38+
@$(MAKE) build-platform GOOS=windows GOARCH=arm64 OUTPUT_DIR=dist/windows-arm64
39+
40+
build-platform: tidy
41+
@echo "Building ${PLUGIN_NAME} ${VERSION} for $(GOOS)-$(GOARCH)"
42+
@mkdir -p $(OUTPUT_DIR)
43+
@cp README.md LICENSE gatewayd_plugin.yaml $(OUTPUT_DIR)/
44+
@GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/$(PLUGIN_NAME)
45+
@sha256sum $(OUTPUT_DIR)/$(PLUGIN_NAME) | sed 's#$(OUTPUT_DIR)/##g' >> $(OUTPUT_DIR)/checksum.txt
46+
@if [ "$(GOOS)" = "windows" ]; then \
47+
zip -q -r dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.zip -j $(OUTPUT_DIR)/; \
48+
else \
49+
tar czf dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.tar.gz -C $(OUTPUT_DIR)/ ${FILES}; \
50+
fi
51+
@sha256sum dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.* | sed '#dist/##g' >> dist/checksums.txt

plugin/module.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
)
88

99
var (
10+
Version = "0.0.0"
1011
PluginID = v1.PluginID{
1112
Name: "gatewayd-plugin-sql-ids-ips",
12-
Version: "0.0.5",
13+
Version: Version,
1314
RemoteUrl: "github.com/gatewayd-io/gatewayd-plugin-sql-ids-ips",
1415
}
1516
PluginMap = map[string]goplugin.Plugin{

0 commit comments

Comments
 (0)