generated from gatewayd-io/plugin-template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build workflow for different platforms (#23)
* Add build workflow for different platforms * Add release workflow * Use PLUGIN_NAME variable * Fix message
- Loading branch information
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
# vendor/ | ||
|
||
gatewayd-plugin-sql-ids-ips | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters