Skip to content

Commit 16f6597

Browse files
abhimanyu003cardoe
authored andcommitted
feat: add understack cli release.
1 parent 6629285 commit 16f6597

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Releases
2+
on:
3+
push:
4+
tags:
5+
- "understack/v[0-9]+.[0-9]+.[0-9]+"
6+
7+
permissions:
8+
contents: write
9+
packages: write
10+
id-token: write
11+
issues: write
12+
13+
jobs:
14+
goreleaser:
15+
runs-on: ubuntu-24.04
16+
permissions:
17+
contents: read
18+
id-token: write
19+
packages: write
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4
23+
with:
24+
fetch-depth: 1
25+
26+
- name: Setup Go
27+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.1
28+
with:
29+
go-version: stable
30+
cache: true
31+
32+
- name: Install dependencies
33+
run: sudo apt-get install -y zip tar make sed grep
34+
35+
- name: Build and Package
36+
working-directory: go/understack
37+
run: |
38+
make build-all package-all checksums
39+
40+
- name: Upload release artifacts
41+
uses: softprops/action-gh-release@v2
42+
with:
43+
files: |
44+
go/understack/build/*.zip
45+
go/understack/build/*.tar.gz
46+
go/understack/build/checksums.txt
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

go/understack/Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Makefile will understack go binary for multiple GOOS and GOARCH
2+
#
3+
# Output will be like this:
4+
# understack_darwin_amd64/
5+
# └── understack
6+
# understack_windows_amd64/
7+
# └── understack.exe
8+
# understack_darwin_amd64.tar.gz
9+
# understack_windows_amd64.zip
10+
#
11+
# package-all: will package folders into .tar.gz and for windows .zip
12+
13+
BINARY_NAME=understack
14+
15+
GOOS_LIST=linux darwin windows
16+
GOARCH_LIST=386 amd64 arm64
17+
18+
BUILD_DIR=build
19+
20+
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev")
21+
COMMIT := $(shell git rev-parse --short HEAD)
22+
LDFLAGS := -ldflags="-s -w -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)'"
23+
24+
.PHONY: all
25+
all: build build-all package-all
26+
27+
.PHONY: build
28+
build:
29+
@echo "Building for current OS/Arch..."
30+
@mkdir -p $(BUILD_DIR)/$(BINARY_NAME)
31+
CGO_ENABLED=0 GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)/$(BINARY_NAME) .
32+
33+
.PHONY: build-all
34+
build-all:
35+
@mkdir -p $(BUILD_DIR)
36+
@for GOOS in $(GOOS_LIST); do \
37+
for GOARCH in $(GOARCH_LIST); do \
38+
if [ "$$GOOS" = "darwin" ] && [ "$$GOARCH" = "386" ]; then \
39+
continue; \
40+
fi; \
41+
DIR=$(BUILD_DIR)/$(BINARY_NAME)_$$GOOS\_$$GOARCH; \
42+
EXT=$$([ "$$GOOS" = "windows" ] && echo ".exe" || echo ""); \
43+
OUTFILE=$$DIR/$(BINARY_NAME)$$EXT; \
44+
mkdir -p $$DIR; \
45+
echo "Building $$OUTFILE..."; \
46+
CGO_ENABLED=0 GOOS=$$GOOS GOARCH=$$GOARCH go build $() -o $$OUTFILE . || echo "Failed to build $$GOOS/$$GOARCH"; \
47+
done \
48+
done
49+
50+
# Loops over all the dirs in build/ folder
51+
# for windows build zip
52+
# else use .tar.gz
53+
.PHONY: package-all
54+
package-all:
55+
@echo "Packaging builds..."
56+
@cd $(BUILD_DIR) && for d in $(BINARY_NAME)_*; do \
57+
if echo $$d | grep -q "windows"; then \
58+
zip -qr "$$d.zip" "$$d"; \
59+
else \
60+
tar -czf "$$d.tar.gz" "$$d"; \
61+
fi \
62+
done
63+
64+
65+
# Loops over *.zip and *.tar.gz in build/
66+
# Uses sha256sum if available (Linux)
67+
# Falls back to shasum -a 256 on macOS
68+
# Outputs clean filenames without ./
69+
# Result is stored in build/checksums.txt
70+
.PHONY: checksums
71+
checksums:
72+
@echo "Generating checksums..."
73+
@cd $(BUILD_DIR) && \
74+
for f in *.zip *.tar.gz; do \
75+
if command -v sha256sum >/dev/null 2>&1; then \
76+
sha256sum "$$f"; \
77+
else \
78+
shasum -a 256 "$$f"; \
79+
fi; \
80+
done | sort > checksums.txt
81+
82+
# remove build dir
83+
.PHONY: clean
84+
clean:
85+
rm -rf $(BUILD_DIR)

0 commit comments

Comments
 (0)