This repository was archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathscript.sh
More file actions
97 lines (74 loc) · 1.84 KB
/
script.sh
File metadata and controls
97 lines (74 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# **START**
export GOPATH=$HOME
export PATH=$GOPATH/bin:$PATH
echo "machine github.com login $GITHUB_USERNAME password $GITHUB_PAT" >> $HOME/.netrc
echo "" >> $HOME/.netrc
echo "machine api.github.com login $GITHUB_USERNAME password $GITHUB_PAT" >> $HOME/.netrc
git config --global user.email "$GITHUB_USERNAME@example.com"
git config --global user.name "$GITHUB_USERNAME"
git config --global advice.detachedHead false
git config --global push.default current
# tidy up if we already have the repo
now=$(date +'%Y%m%d%H%M%S_%N')
githubcli repo renameIfExists $GITHUB_ORG/tools tools_$now
githubcli repo transfer $GITHUB_ORG/tools_$now $GITHUB_ORG_ARCHIVE
githubcli repo create $GITHUB_ORG/tools
# block: repo
echo https://github.com/$GITHUB_ORG/tools
# block: setup
mkdir -p $HOME/scratchpad/tools
cd $HOME/scratchpad/tools
git init -q
git remote add origin https://github.com/$GITHUB_ORG/tools
go mod init
# block: set bin target
export GOBIN=$PWD/bin
export PATH=$GOBIN:$PATH
cat <<EOD > tools.go
// +build tools
package tools
import (
_ "golang.org/x/tools/cmd/stringer"
)
EOD
gofmt -w tools.go
# block: add tool dependency
catfile tools.go
# block: install tool dependency
go install golang.org/x/tools/cmd/stringer
# block: module deps
go list -m all
# block: tool on path
which stringer
cat <<EOD > painkiller.go
package main
import "fmt"
//go:generate stringer -type=Pill
type Pill int
const (
Placebo Pill = iota
Aspirin
Ibuprofen
Paracetamol
Acetaminophen = Paracetamol
)
func main() {
fmt.Printf("For headaches, take %v\n", Ibuprofen)
}
EOD
gofmt -w painkiller.go
# block: painkiller.go
catfile painkiller.go
# block: go generate and run
go generate
go run .
# block: commit and push
cat <<EOD > .gitignore
/bin
EOD
git add -A
git commit -q -am 'Initial commit'
git push -q origin
# block: version details
go version