Skip to content

Commit

Permalink
generate binaries for multiple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
rorydbain committed Oct 29, 2024
1 parent 35c030e commit f048718
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*'

permissions:
contents: write # Grants write access to the repository contents, including releases and assets
contents: write # Grants write access to repository contents, including releases and assets

jobs:
release:
Expand All @@ -22,15 +22,17 @@ jobs:
go-version: '1.22'

- name: Get version from tag
id: get_version
run: echo "::set-output name=version::${GITHUB_REF##*/}"
run: echo "version=${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Build binaries
run: make release VERSION=${{ env.version }}


- name: Build binary
run: make build VERSION=${{ steps.get_version.outputs.version }}

- name: Create GitHub Release
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: ${{ steps.get_version.outputs.version }}
files: ./notify_incident_io
tag_name: ${{ env.version }}
name: ${{ env.version }}
files: ./notify_incident_io-*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ go.work.sum

.idea/

notify_incident_io
notify_incident_io
notify_incident_io-*
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for the Nagios Incident.io Notification Plugin

# Name of the binary to generate
# Name of the binary to generate (base name)
BINARY = notify_incident_io

# Version can be set manually or passed in from the GitHub Actions workflow
Expand All @@ -9,15 +9,24 @@ VERSION ?= development
# Go build flags with version information
BUILD_FLAGS = -ldflags "-s -w -X 'main.version=$(VERSION)'"

.PHONY: all build clean
# Platforms to build for
PLATFORMS = linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64

# Default target: Build the binary
.PHONY: all build clean release

# Default target: Build the binary for the current OS and architecture
all: build

# Build the binary
# Build the binary for the current OS and architecture
build:
go build $(BUILD_FLAGS) -o $(BINARY) main.go

# Cross-compile binaries for all target platforms
release: clean
@for platform in $(PLATFORMS); do \
GOOS=$${platform%/*} GOARCH=$${platform#*/} go build $(BUILD_FLAGS) -o $(BINARY)-$${platform%/*}-$${platform#*/} main.go || exit 1; \
done

# Clean up build artifacts
clean:
rm -f $(BINARY)
rm -f $(BINARY) $(BINARY)-*

0 comments on commit f048718

Please sign in to comment.