update
continuous-integration/drone/tag Build is passing Details

master v0.1.0
Evan Chen 2021-11-29 12:21:54 +08:00
commit 7126239574
6 changed files with 120 additions and 0 deletions

19
.drone.yml Normal file
View File

@ -0,0 +1,19 @@
kind: pipeline
name: default
steps:
- name: build
image: golang:1.17.2
commands:
- git tag $DRONE_TAG
- bash make.sh main.go
- name: gitea_release
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_api_key
base_url: https://kumoly.io
files: dist/*
checksum:
- sha256
trigger:
event: tag

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
dist

1
README.md Normal file
View File

@ -0,0 +1 @@
# Clock

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module kumoly.io/tools/kclock
go 1.17

64
main.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
var (
Version = "0.0.0"
Build = "alpha"
)
func main() {
var local string
var flagVer bool
flag.StringVar(&local, "local", fmt.Sprint(time.Local), "set local manually")
flag.BoolVar(&flagVer, "v", false, "show version")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: kclock [options]\n")
flag.PrintDefaults()
}
flag.Parse()
if flagVer {
fmt.Printf("%v - %v\n", Version, Build)
return
}
l, err := time.LoadLocation(local)
if err != nil {
panic(err)
}
time.Local = l
watch()
}
func watch() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
start := time.Now()
next := time.Now().Truncate(time.Second).Add(time.Second)
<-time.After(time.Until(next))
tick := time.Tick(time.Second)
fmt.Printf("\n")
for {
fmt.Printf("\r\033[1A\033[0K\033[92m%v\033[0m\n", time.Now().Truncate(time.Second))
select {
case <-tick:
case <-quit:
fmt.Printf("\r\033[0Ktime elapsed: \033[94m%v\033[0m\n", time.Since(start))
return
}
}
}

32
make.sh Normal file
View File

@ -0,0 +1,32 @@
VERSION=$(git describe --tags --abbrev=0)
if [ $? -ne 0 ]; then VERSION=$DRONE_TAG; fi
BUILD=$(git rev-parse --short HEAD)
if [ $? -ne 0 ]; then BUILD=${DRONE_COMMIT:0:7}; fi
PROJ=kclock
DIST=dist
LDFLAGS="-ldflags \"-X main.Version=${VERSION} -X main.Build=${BUILD} -w -s\""
FAILURES=""
PLATFORMS="darwin/amd64"
PLATFORMS="$PLATFORMS windows/amd64"
PLATFORMS="$PLATFORMS linux/amd64"
for PLATFORM in $PLATFORMS; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
BIN_FILENAME="${PROJ}"
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o ${DIST}/${BIN_FILENAME} $@"
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
sh -c "cd ${DIST} && tar -czf ${PROJ}-${VERSION}-${GOOS}-${GOARCH}.tar.gz ${BIN_FILENAME} && rm ${BIN_FILENAME}"
done
if [[ "${FAILURES}" != "" ]]; then
echo ""
echo "${SCRIPT_NAME} failed on: ${FAILURES}"
exit 1
fi