Skip to content

Commit 8e20e87

Browse files
committed
feat: Add release automation
1 parent 9b9ccbe commit 8e20e87

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

.github/workflows/release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build-and-release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version: '1.24.2'
19+
20+
- name: Build release binaries
21+
run: make release-build
22+
23+
- name: Create Release
24+
id: create_release
25+
uses: actions/create-release@v1
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
tag_name: ${{ github.ref }}
30+
release_name: Release ${{ github.ref }}
31+
draft: false
32+
prerelease: false
33+
34+
- name: Upload Linux binary
35+
uses: actions/upload-release-asset@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
upload_url: ${{ steps.create_release.outputs.upload_url }}
40+
asset_path: ./como-linux-amd64
41+
asset_name: como-linux-amd64
42+
asset_content_type: application/octet-stream
43+
44+
- name: Upload Windows binary
45+
uses: actions/upload-release-asset@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
upload_url: ${{ steps.create_release.outputs.upload_url }}
50+
asset_path: ./como-windows-amd64.exe
51+
asset_name: como-windows-amd64.exe
52+
asset_content_type: application/octet-stream
53+
54+
- name: Upload macOS binary
55+
uses: actions/upload-release-asset@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
upload_url: ${{ steps.create_release.outputs.upload_url }}
60+
asset_path: ./como-mac-amd64
61+
asset_name: como-mac-amd64
62+
asset_content_type: application/octet-stream

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.exe
2+
*.exe~
3+
*.dll
4+
*.so
5+
*.dylib
6+
7+
*.test
8+
9+
*.out
10+
11+
/como
12+
/como-*
13+
test-output.txt

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
GOCMD=go
2+
GOBUILD=$(GOCMD) build
3+
GOCLEAN=$(GOCMD) clean
4+
GOTEST=$(GOCMD) test
5+
GOGET=$(GOCMD) get
6+
BINARY_NAME=como
7+
BINARY_UNIX=$(BINARY_NAME)
8+
9+
# Get the version from the latest git tag
10+
VERSION := $(shell git describe --tags --abbrev=0)
11+
12+
# Build flags
13+
LDFLAGS = -ldflags="-X 'como/cmd.version=$(VERSION)'"
14+
15+
# Default target
16+
all: build
17+
18+
# Build the binary
19+
build:
20+
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .
21+
22+
# Test the application
23+
test:
24+
$(GOTEST) -v ./...
25+
26+
# Clean the binary
27+
clean:
28+
$(GOCLEAN)
29+
rm -f $(BINARY_NAME)
30+
rm -f $(BINARY_NAME).exe
31+
32+
# Cross-compilation targets
33+
build-linux:
34+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 .
35+
36+
build-windows:
37+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe .
38+
39+
build-mac:
40+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-mac-amd64 .
41+
42+
# Build all release binaries
43+
release-build: build-linux build-windows build-mac
44+
45+
.PHONY: all build test clean build-linux build-windows build-mac release-build

cmd/version.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// This will be set by the linker
10+
var version string
11+
12+
// versionCmd represents the version command
13+
var versionCmd = &cobra.Command{
14+
Use: "version",
15+
Short: "Print the version number of context-monkey",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
if version == "" {
18+
// fallback for local builds
19+
version = "dev"
20+
}
21+
fmt.Fprintf(cmd.OutOrStdout(), "context-monkey version %s\n", version)
22+
},
23+
}
24+
25+
func init() {
26+
rootCmd.AddCommand(versionCmd)
27+
}

0 commit comments

Comments
 (0)