Skip to content

Commit ad17ef6

Browse files
committed
[Fea] support self upgrade
1 parent 0e9102a commit ad17ef6

File tree

8 files changed

+333
-409
lines changed

8 files changed

+333
-409
lines changed

.github/workflows/build.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths-ignore:
6+
- "README.md"
7+
# branches:
8+
# - main
9+
tags:
10+
- "v*"
11+
pull_request_target:
12+
branches:
13+
- main
14+
- dev
15+
jobs:
16+
build:
17+
permissions: write-all
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
os: [ubuntu-22.04]
22+
fail-fast: false
23+
defaults:
24+
run:
25+
shell: bash
26+
working-directory: .
27+
steps:
28+
- name: Check out code into the Go module directory
29+
uses: actions/checkout@v3
30+
31+
- name: Set variables
32+
if: ${{github.ref_name=='main'}}
33+
run: echo "VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
34+
35+
- name: Set variables
36+
if: ${{github.ref_name=='' || github.ref_type=='tag'}}
37+
run: echo "VERSION=$(git describe --tags)" >> $GITHUB_ENV
38+
39+
- name: Setup Go
40+
uses: actions/setup-go@v3
41+
with:
42+
go-version: "1.23.0"
43+
check-latest: true
44+
45+
- name: Install UPX
46+
uses: crazy-max/ghaction-upx@v3
47+
with:
48+
install-only: true
49+
50+
- name: Build dssh
51+
run: make all
52+
53+
- name: Compress binaries
54+
run: make compress
55+
56+
- name: Upload Release
57+
if: ${{ success() && github.ref_type=='tag' }}
58+
uses: softprops/action-gh-release@v1
59+
with:
60+
tag: ${{ github.ref_name }}
61+
tag_name: ${{ github.ref_name }}
62+
files: bin/dssh-*
63+
generate_release_notes: true

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
VERSION := $(shell git describe --tags --always)
2+
GIT_COMMIT := $(shell git rev-parse --short HEAD)
3+
4+
GO_BUILD_COMMAND := go build -a -ldflags '-s -w -extldflags "-static" -X "github.com/PWZER/dssh/cmd.Version=$(VERSION)" -X "github.com/PWZER/dssh/cmd.GitCommit=$(GIT_COMMIT)"'
5+
6+
all: darwin linux
7+
8+
compress:
9+
upx --best bin/* || true
10+
11+
darwin-amd64:
12+
GOOS=darwin GOARCH=amd64 $(GO_BUILD_COMMAND) -o bin/dssh-darwin-amd64 .
13+
14+
darwin-arm64:
15+
GOOS=darwin GOARCH=arm64 $(GO_BUILD_COMMAND) -o bin/dssh-darwin-arm64 .
16+
17+
darwin: darwin-amd64 darwin-arm64
18+
19+
linux-amd64:
20+
GOOS=linux GOARCH=amd64 $(GO_BUILD_COMMAND) -o bin/dssh-linux-amd64 .
21+
22+
linux-arm64:
23+
GOOS=linux GOARCH=arm64 $(GO_BUILD_COMMAND) -o bin/dssh-linux-arm64 .
24+
25+
linux: linux-amd64 linux-arm64
26+
27+
install:
28+
GOOS=$(shell uname | tr '[:upper:]' '[:lower:]') GOARCH=$(shell go env GOARCH) $(GO_BUILD_COMMAND) -o ~/.local/bin/dssh .

build.sh

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

cmd/upgrade.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright © 2024 PWZER <[email protected]>
3+
*/
4+
package cmd
5+
6+
import (
7+
"github.com/PWZER/dssh/utils"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
dummy bool
13+
)
14+
15+
var upgradeCmd = &cobra.Command{
16+
Use: "upgrade",
17+
Short: "upgrade dssh to the latest version",
18+
Long: "upgrade dssh to the latest version",
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
return utils.Upgrade(dummy, Version)
21+
},
22+
}
23+
24+
func init() {
25+
rootCmd.AddCommand(upgradeCmd)
26+
upgradeCmd.Flags().BoolVar(&dummy, "dummy", false, "dummy flag for testing")
27+
}

cmd/version.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var Version = "v0.0.1"
10+
var GitCommit = "<unknown>"
11+
12+
var versionCmd = &cobra.Command{
13+
Use: "version",
14+
Short: "print dssh version",
15+
Long: "print dssh version",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
fmt.Printf("dssh version: %s, git commit: %s\n", Version, GitCommit)
18+
},
19+
}
20+
21+
func init() {
22+
rootCmd.AddCommand(versionCmd)
23+
}

go.mod

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
module github.com/PWZER/dssh
22

3-
go 1.15
3+
go 1.20
44

55
require (
66
github.com/mitchellh/go-homedir v1.1.0
7-
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
87
github.com/pkg/sftp v1.13.5
98
github.com/schollz/progressbar/v3 v3.8.6
109
github.com/spf13/cobra v1.5.0
1110
github.com/spf13/viper v1.12.0
12-
github.com/subosito/gotenv v1.4.0 // indirect
1311
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
12+
gopkg.in/yaml.v2 v2.4.0
13+
)
14+
15+
require (
16+
github.com/fsnotify/fsnotify v1.5.4 // indirect
17+
github.com/hashicorp/hcl v1.0.0 // indirect
18+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
19+
github.com/kr/fs v0.1.0 // indirect
20+
github.com/magiconair/properties v1.8.6 // indirect
21+
github.com/mattn/go-runewidth v0.0.13 // indirect
22+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
23+
github.com/mitchellh/mapstructure v1.5.0 // indirect
24+
github.com/pelletier/go-toml v1.9.5 // indirect
25+
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
26+
github.com/rivo/uniseg v0.2.0 // indirect
27+
github.com/spf13/afero v1.8.2 // indirect
28+
github.com/spf13/cast v1.5.0 // indirect
29+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
30+
github.com/spf13/pflag v1.0.5 // indirect
31+
github.com/subosito/gotenv v1.4.0 // indirect
1432
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
1533
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
34+
golang.org/x/text v0.3.7 // indirect
1635
gopkg.in/ini.v1 v1.66.6 // indirect
17-
gopkg.in/yaml.v2 v2.4.0
36+
gopkg.in/yaml.v3 v3.0.1 // indirect
1837
)

0 commit comments

Comments
 (0)