Skip to content

Commit f8b54d0

Browse files
authored
Support to clone code to customize directory (#31)
* Support to clone code to customize directory * Add goreleaser command in the readme file * Bump goreleaser action from v2.5.0 to v2.8.0
1 parent c636394 commit f8b54d0

23 files changed

+294
-34
lines changed

.github/workflows/pull-request.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jobs:
1010
name: Build
1111
runs-on: macos-10.15
1212
steps:
13-
- name: Set up Go 1.13
13+
- name: Set up Go 1.16
1414
uses: actions/setup-go@v2.1.3
1515
with:
16-
go-version: 1.13
16+
go-version: 1.16
1717
id: go
1818
- name: Check out code into the Go module directory
1919
uses: actions/checkout@v2.3.4
2020
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v2.5.0
21+
uses: goreleaser/goreleaser-action@v2.8.0
2222
with:
2323
version: latest
2424
args: check
@@ -29,10 +29,10 @@ jobs:
2929
name: Lint
3030
runs-on: ubuntu-latest
3131
steps:
32-
- name: Set up Go 1.13
32+
- name: Set up Go 1.16
3333
uses: actions/setup-go@v2.1.3
3434
with:
35-
go-version: 1.13
35+
go-version: 1.16
3636
id: go
3737
- name: Check out code into the Go module directory
3838
uses: actions/checkout@v2.3.4

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
- name: Set up Go
1717
uses: actions/setup-go@v2.1.3
1818
with:
19-
go-version: 1.13.x
19+
go-version: 1.16
2020
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v2.5.0
21+
uses: goreleaser/goreleaser-action@v2.8.0
2222
with:
2323
version: latest
2424
args: release --rm-dist

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ BUILDFLAGS = -ldflags "-X github.com/linuxsuren/cobra-extension/version.version=
77
build:
88
CGO_ENABLE=0 go build $(BUILDFLAGS) -o bin/cgit
99

10+
goreleaser:
11+
goreleaser release --rm-dist --snapshot
12+
1013
copy: build
1114
sudo cp bin/cgit /usr/local/bin/cgit

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module github.com/linuxsuren/cgit
22

3-
go 1.15
3+
go 1.16
44

55
require (
6-
github.com/linuxsuren/cobra-extension v0.0.10
6+
github.com/linuxsuren/cobra-extension v0.0.11
7+
github.com/linuxsuren/go-cli-alias v0.0.9
78
github.com/magiconair/properties v1.8.5
8-
github.com/linuxsuren/go-cli-alias v0.0.6
99
github.com/spf13/cobra v1.1.3
10+
github.com/spf13/viper v1.7.0
1011
)

go.sum

Lines changed: 41 additions & 16 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ import (
55
"fmt"
66
"github.com/linuxsuren/cgit/cmd"
77
"github.com/linuxsuren/cgit/pkg"
8-
ext "github.com/linuxsuren/cobra-extension"
8+
ext "github.com/linuxsuren/cobra-extension/pkg"
99
extver "github.com/linuxsuren/cobra-extension/version"
1010
aliasCmd "github.com/linuxsuren/go-cli-alias/pkg/cmd"
1111
"github.com/spf13/cobra"
12+
"github.com/spf13/viper"
13+
"os"
1214
"os/exec"
15+
"path"
1316
"strings"
1417
)
1518

1619
const (
20+
// TargetCLI is the target command for alias
1721
TargetCLI = "git"
22+
// AliasCLI is the alias command
1823
AliasCLI = "cgit"
1924
)
2025

2126
func main() {
2227
command := &cobra.Command{
2328
Use: AliasCLI,
2429
RunE: func(command *cobra.Command, args []string) (err error) {
25-
fmt.Println(args, "sdfs")
2630
preHook(args)
2731

2832
command.Println(args)
@@ -39,26 +43,33 @@ func main() {
3943

4044
aliasCmd.AddAliasCmd(command, getAliasList())
4145

46+
ctx := context.TODO()
4247
command.AddCommand(ext.NewCompletionCmd(command),
43-
cmd.NewMirrorCmd(context.TODO()))
48+
cmd.NewMirrorCmd(ctx))
4449

45-
aliasCmd.Execute(command, TargetCLI, getAliasList(), preHook)
50+
aliasCmd.ExecuteContextV2(command, context.TODO(), TargetCLI, getAliasList(), preHook)
4651
}
4752

48-
func preHook(args []string) {
49-
preferGitHub(args)
53+
func preHook(args []string) []string {
54+
args = preferGitHub(args)
5055
useMirror(args)
56+
return args
5157
}
5258

53-
func preferGitHub(args []string) {
59+
func preferGitHub(args []string) []string {
5460
if len(args) <= 1 || args[0] != "clone" {
55-
return
61+
return args
5662
}
5763

5864
address := args[1]
5965
if !strings.HasPrefix(address, "http") && !strings.HasPrefix(address, "git@") {
6066
args[1] = fmt.Sprintf("https://github.com.cnpmjs.org/%s", address)
67+
68+
if len(args) == 2 {
69+
args = append(args, path.Join(viper.GetString("ws"), address))
70+
}
6171
}
72+
return args
6273
}
6374

6475
func useMirror(args []string) {
@@ -73,3 +84,21 @@ func useMirror(args []string) {
7384
}
7485
}
7586
}
87+
88+
func init() {
89+
viper.SetConfigName("cgit")
90+
viper.SetConfigType("yaml")
91+
viper.AddConfigPath("$HOME/.config")
92+
viper.AddConfigPath(".")
93+
if err := viper.ReadInConfig(); err != nil {
94+
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
95+
panic(err)
96+
}
97+
}
98+
loadDefaults()
99+
return
100+
}
101+
102+
func loadDefaults() {
103+
viper.SetDefault("ws", os.ExpandEnv("$HOME/ws/github/"))
104+
}

release/cgit-darwin-amd64.tar.gz

3.03 MB
Binary file not shown.

release/cgit-darwin-arm64.tar.gz

2.81 MB
Binary file not shown.

release/cgit-linux-64bit.deb

2.93 MB
Binary file not shown.

release/cgit-linux-64bit.rpm

2.93 MB
Binary file not shown.

release/cgit-linux-amd64.tar.gz

2.93 MB
Binary file not shown.

release/cgit-linux-arm64.deb

2.64 MB
Binary file not shown.

release/cgit-linux-arm64.rpm

2.64 MB
Binary file not shown.

release/cgit-linux-arm64.tar.gz

2.64 MB
Binary file not shown.

release/cgit-windows-amd64.zip

2.9 MB
Binary file not shown.

release/cgit.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# typed: false
2+
# frozen_string_literal: true
3+
4+
# This file was generated by GoReleaser. DO NOT EDIT.
5+
class Cgit < Formula
6+
desc "cgit is a tiny tool for Chinese developers."
7+
homepage "https://github.com/linuxsuren/cgit"
8+
version "v0.0.9-next-df67465"
9+
bottle :unneeded
10+
11+
on_macos do
12+
if Hardware::CPU.intel?
13+
url "https://github.com/LinuxSuRen/cgit/releases/download/v0.0.9/cgit-darwin-amd64.tar.gz"
14+
sha256 "e962e5d22636b5caa8b089e7532228e82d4ab1262e8c93f87aa7054b7557568e"
15+
end
16+
if Hardware::CPU.arm?
17+
url "https://github.com/LinuxSuRen/cgit/releases/download/v0.0.9/cgit-darwin-arm64.tar.gz"
18+
sha256 "94f973d2df36ca1776f17eb25f34b2894e1ce81b2988806dfa8664a106d2fd29"
19+
end
20+
end
21+
22+
on_linux do
23+
if Hardware::CPU.intel?
24+
url "https://github.com/LinuxSuRen/cgit/releases/download/v0.0.9/cgit-linux-amd64.tar.gz"
25+
sha256 "7aaa6bb4492ce04a2d8d5d9d508b6c22daae9dc32a15449415105f3d1718813d"
26+
end
27+
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
28+
url "https://github.com/LinuxSuRen/cgit/releases/download/v0.0.9/cgit-linux-arm64.tar.gz"
29+
sha256 "ca6cd3c14870ca96dfc244a8b471026520028c9c4c0a45547b04b228318680fe"
30+
end
31+
end
32+
33+
depends_on "vim" => :optional
34+
depends_on "bash-completion" => :optional
35+
36+
def install
37+
bin.install name
38+
39+
prefix.install_metafiles
40+
end
41+
42+
test do
43+
version_output = shell_output("#{bin}/cgit version")
44+
assert_match version.to_s, version_output
45+
end
46+
end

release/cgit_darwin_amd64/cgit

3.11 MB
Binary file not shown.

release/cgit_darwin_arm64/cgit

3.55 MB
Binary file not shown.

release/cgit_linux_amd64/cgit

3 MB
Binary file not shown.

release/cgit_linux_arm64/cgit

2.72 MB
Binary file not shown.

release/cgit_windows_amd64/cgit.exe

2.97 MB
Binary file not shown.

release/checksums.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
38912e91f57a3d04ed14dcff0d24d44d65e5d7e141293eddfbc3c23e0c2bf40b cgit-windows-amd64.zip
2+
7aaa6bb4492ce04a2d8d5d9d508b6c22daae9dc32a15449415105f3d1718813d cgit-linux-amd64.tar.gz
3+
80b0e6123ca912f8ad1d3c9d62e019cb788cdda4f1c275b5828db7b45d4f2ac1 cgit-linux-64bit.rpm
4+
824dd6a54c5f7a589a3e5cc4883a359090922f697bc42b556d06d8e6a9776cf6 cgit-linux-64bit.deb
5+
94f973d2df36ca1776f17eb25f34b2894e1ce81b2988806dfa8664a106d2fd29 cgit-darwin-arm64.tar.gz
6+
b88a876863c7a5e3d94ca229069cf1a725e28e07eccd65636c51d2032b550891 cgit-linux-arm64.deb
7+
ca6cd3c14870ca96dfc244a8b471026520028c9c4c0a45547b04b228318680fe cgit-linux-arm64.tar.gz
8+
e962e5d22636b5caa8b089e7532228e82d4ab1262e8c93f87aa7054b7557568e cgit-darwin-amd64.tar.gz
9+
fd7074428b48cff808bb8665af479fe52fb23960b7cdc1fa39355fe81a9deb5e cgit-linux-arm64.rpm

release/config.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
project_name: cgit
2+
release:
3+
github:
4+
owner: LinuxSuRen
5+
name: cgit
6+
name_template: '{{.Tag}}'
7+
milestones:
8+
- repo:
9+
owner: LinuxSuRen
10+
name: cgit
11+
name_template: '{{ .Tag }}'
12+
brews:
13+
- name: cgit
14+
tap:
15+
owner: linuxsuren
16+
name: homebrew-linuxsuren
17+
commit_author:
18+
name: goreleaserbot
19+
email: goreleaser@carlosbecker.com
20+
folder: Formula
21+
install: |
22+
bin.install name
23+
24+
prefix.install_metafiles
25+
dependencies:
26+
- name: vim
27+
type: optional
28+
- name: bash-completion
29+
type: optional
30+
test: |
31+
version_output = shell_output("#{bin}/cgit version")
32+
assert_match version.to_s, version_output
33+
description: cgit is a tiny tool for Chinese developers.
34+
homepage: https://github.com/linuxsuren/cgit
35+
goarm: "6"
36+
scoop:
37+
name: cgit
38+
commit_author:
39+
name: goreleaserbot
40+
email: goreleaser@carlosbecker.com
41+
commit_msg_template: Scoop update for {{ .ProjectName }} version {{ .Tag }}
42+
builds:
43+
- id: cgit
44+
goos:
45+
- windows
46+
- linux
47+
- darwin
48+
goarch:
49+
- amd64
50+
- arm64
51+
goarm:
52+
- "6"
53+
gomips:
54+
- hardfloat
55+
targets:
56+
- windows_amd64
57+
- linux_amd64
58+
- linux_arm64
59+
- darwin_amd64
60+
- darwin_arm64
61+
dir: .
62+
main: .
63+
ldflags:
64+
- -X github.com/linuxsuren/cobra-extension/version.version={{.Version}}
65+
- -X github.com/linuxsuren/cobra-extension/version.commit={{.ShortCommit}}
66+
- -X github.com/linuxsuren/cobra-extension/version.date={{.Date}}
67+
- -w
68+
binary: cgit
69+
hooks:
70+
post:
71+
- cmd: upx "{{ .Path }}"
72+
env:
73+
- CGO_ENABLED=0
74+
lang: go
75+
gobinary: go
76+
archives:
77+
- id: default
78+
builds:
79+
- cgit
80+
name_template: '{{ .Binary }}-{{ .Os }}-{{ .Arch }}'
81+
replacements:
82+
amd64: amd64
83+
arm64: arm64
84+
darwin: darwin
85+
linux: linux
86+
windows: windows
87+
format: tar.gz
88+
format_overrides:
89+
- goos: windows
90+
format: zip
91+
files:
92+
- src: README.md
93+
allow_different_binary_count: false
94+
nfpms:
95+
- file_name_template: '{{ .Binary }}-{{.Os}}-{{.Arch}}'
96+
package_name: cgit
97+
replacements:
98+
amd64: 64bit
99+
arm64: arm64
100+
darwin: macOS
101+
linux: linux
102+
windows: windows
103+
recommends:
104+
- bash-completion
105+
- vim
106+
id: default
107+
builds:
108+
- cgit
109+
formats:
110+
- deb
111+
- rpm
112+
vendor: Jenkins
113+
homepage: https://github.com/linuxsuren/cgit
114+
maintainer: rick <rick@jenkins-zh.cn>
115+
description: cgit is a tiny tool for Chinese developers.
116+
license: MIT
117+
bindir: /usr/bin
118+
snapshot:
119+
name_template: '{{ .Tag }}-next-{{.ShortCommit}}'
120+
checksum:
121+
name_template: checksums.txt
122+
algorithm: sha256
123+
changelog:
124+
filters:
125+
exclude:
126+
- '^docs:'
127+
- '^test:'
128+
sort: asc
129+
skip: true
130+
dist: release
131+
env_files:
132+
github_token: ~/.config/goreleaser/github_token
133+
gitlab_token: ~/.config/goreleaser/gitlab_token
134+
gitea_token: ~/.config/goreleaser/gitea_token
135+
source:
136+
name_template: '{{ .ProjectName }}-{{ .Version }}'
137+
format: tar.gz
138+
gomod:
139+
gobinary: go
140+
announce:
141+
twitter:
142+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .GitURL
143+
}}/releases/tag/{{ .Tag }}'
144+
github_urls:
145+
download: https://github.com
146+
gitlab_urls:
147+
download: https://gitlab.com

0 commit comments

Comments
 (0)