Skip to content

Commit cef9781

Browse files
committed
Opt: build and release
1 parent fc57002 commit cef9781

File tree

6 files changed

+99
-78
lines changed

6 files changed

+99
-78
lines changed

.github/workflows/build-and-release.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

.github/workflows/goreleaser.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build and Release
2+
3+
on:
4+
create:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.21'
21+
22+
- name: Make All
23+
run: make multi VERSION="${{ github.ref_name }}"
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v4
27+
with:
28+
version: latest
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor/
2+
release/
23
.idea
34
.git
45
tryssh

.goreleaser.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
builds:
2+
- skip: true
3+
checksum:
4+
name_template: '{{ .ProjectName }}-sha256-checksums.txt'
5+
algorithm: sha256
6+
extra_files:
7+
- glob: ./release/*
8+
release:
9+
# Same as for github
10+
# Note: it can only be one: either github, gitlab or gitea
11+
github:
12+
owner: Driver-C
13+
name: tryssh
14+
15+
draft: false
16+
17+
# You can add extra pre-existing files to the release.
18+
# The filename on the release will be the last part of the path (base). If
19+
# another file with the same name exists, the latest one found will be used.
20+
# Defaults to empty.
21+
extra_files:
22+
- glob: ./release/*

Makefile

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
PACKAGE := tryssh/cmd/version
2-
VERSION := v0.3.4
32
GO_VERSION := $(shell go version | awk '{print $$3}')
43
BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
54
LDFLAGS :=
65

7-
LDFLAGS += -X '$(PACKAGE).TrysshVersion=$(VERSION)'
6+
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
7+
8+
os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm linux:arm64 windows:amd64 windows:arm64
9+
10+
ifdef VERSION
11+
BINARY_VERSION = $(VERSION)
12+
endif
13+
BINARY_VERSION ?= ${GIT_TAG}
14+
15+
# Only set Version if building a tag or VERSION is set
16+
ifneq ($(BINARY_VERSION),)
17+
LDFLAGS += -X '$(PACKAGE).TrysshVersion=$(BINARY_VERSION)'
18+
else
19+
# If you cannot find any information that can be used as a version number, change it to debug
20+
BINARY_VERSION = "debug"
21+
endif
22+
823
LDFLAGS += -X '$(PACKAGE).BuildGoVersion=$(GO_VERSION)'
924
LDFLAGS += -X '$(PACKAGE).BuildTime=$(BUILD_TIME) UTC'
1025

@@ -13,12 +28,27 @@ default: build
1328

1429
.PHONY: build
1530
build: tidy
16-
@go build -ldflags "$(LDFLAGS)" ./
31+
@go build -v -trimpath -ldflags "$(LDFLAGS)" ./
1732

1833
.PHONY: tidy
19-
tidy:
34+
tidy: clean
2035
@go mod tidy
2136

2237
.PHONY: clean
2338
clean:
2439
@go clean
40+
@rm -rf ./release
41+
42+
.PHONY: multi
43+
multi: tidy
44+
@$(foreach n, $(os-archs),\
45+
os=$(shell echo "$(n)" | cut -d : -f 1);\
46+
arch=$(shell echo "$(n)" | cut -d : -f 2);\
47+
target_suffix=${BINARY_VERSION}-$${os}-$${arch};\
48+
echo "Build $${os}-$${arch}...";\
49+
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} go build -v -trimpath -ldflags "$(LDFLAGS)" \
50+
-o ./release/tryssh-$${target_suffix};\
51+
echo "Build $${os}-$${arch} done";\
52+
)
53+
@mv ./release/tryssh-${BINARY_VERSION}-windows-amd64 ./release/tryssh-${BINARY_VERSION}-windows-amd64.exe
54+
@mv ./release/tryssh-${BINARY_VERSION}-windows-arm64 ./release/tryssh-${BINARY_VERSION}-windows-arm64.exe

cmd/version/version.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ func NewVersionCommand() *cobra.Command {
1717
Short: "Print the client version information for the current context",
1818
Long: "Print the client version information for the current context",
1919
Run: func(cmd *cobra.Command, args []string) {
20-
fmt.Printf("TrysshVersion: %s, GoVersion: %s, BuildTime: %s\n",
21-
TrysshVersion, BuildGoVersion, BuildTime)
20+
var versionContent string
21+
if TrysshVersion != "" {
22+
versionContent += fmt.Sprintf("TrysshVersion: %s\n", TrysshVersion)
23+
}
24+
if BuildGoVersion != "" {
25+
versionContent += fmt.Sprintf("GoVersion: %s\n", BuildGoVersion)
26+
}
27+
if BuildTime != "" {
28+
versionContent += fmt.Sprintf("BuildTime: %s\n", BuildTime)
29+
}
30+
fmt.Printf(versionContent)
2231
},
2332
}
2433
return versionCmd

0 commit comments

Comments
 (0)