Skip to content

Commit 9012f87

Browse files
authored
Merge pull request #898 from rackerlabs/understack-cli-release
feat: add understack cli release.
2 parents 648af8c + 66737e4 commit 9012f87

File tree

4 files changed

+164
-3
lines changed

4 files changed

+164
-3
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+
- "understackctl/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 sed grep
34+
35+
- name: Build and Package
36+
working-directory: go/understackctl
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/understackctl/build/*.zip
45+
go/understackctl/build/*.tar.gz
46+
go/understackctl/build/checksums.txt
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

go/understackctl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ vendor/
2121

2222
# goreleaser dist folder
2323
dist/
24+
build/
2425

2526
# IntelliJ
2627
.idea

go/understackctl/Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Makefile will understackctl go binary for multiple GOOS and GOARCH
2+
#
3+
# Output will be like this:
4+
# understackctl_darwin_amd64/
5+
# └── understackctl
6+
# understackctl_windows_amd64/
7+
# └── understackctl.exe
8+
# understackctl_darwin_amd64.tar.gz
9+
# understackctl_windows_amd64.zip
10+
#
11+
# package-all: will package folders into .tar.gz and for windows .zip
12+
13+
BINARY_NAME=understackctl
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 --match "understackctl/v[0-9]*.[0-9]*.[0-9]*" 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)

go/understackctl/README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# understack
1+
# understackctl
22

3-
UnderStack CLI helps quickly generate a deployment repository.
3+
understackctl is a CLI that helps quickly generate a deployment repository.
44

55
## How to use
66

@@ -18,7 +18,7 @@ export UC_DEPLOY_EMAIL="<your_email>"
1818
export UC_AIO=yes
1919
```
2020

21-
* Run
21+
* Quick Run
2222

2323
```
2424
go run *.go quickstart
@@ -27,6 +27,33 @@ go run *.go help
2727

2828
* Commit all changes to the undercloud-deploy repo in your branch
2929

30+
## Build
31+
32+
* Local build `make build` ( this will only build binary for you local os ).
33+
* Cross-Platform build `make build-all` ( build for linux-mac-windows )
34+
35+
## Development
36+
37+
* To add a new command, create a function like this.
38+
39+
```go
40+
func NewCmdMyCommand() *cobra.Command {
41+
return &cobra.Command{
42+
Use: "mycommand",
43+
Short: "This will run my command",
44+
Long: "This will run my command",
45+
Run: myCommandFunction,
46+
}
47+
}
48+
```
49+
50+
* After that register it to `cmd/root/root.go`
51+
52+
```go
53+
func init() {
54+
rootCmd.AddCommand(deploy.NewCmdMyCommand())
55+
}
56+
```
3057

3158
## Contributing
3259

0 commit comments

Comments
 (0)