build: add drone build
continuous-integration/drone/tag Build is passing Details

master v0.1.0
Evan Chen 2021-11-17 10:44:22 +08:00
parent f78900130b
commit 220dd90b01
5 changed files with 122 additions and 0 deletions

23
.drone.yml Normal file
View File

@ -0,0 +1,23 @@
kind: pipeline
name: default
steps:
- name: build
image: golang:1.17.2
commands:
- git tag $DRONE_TAG
- bash make.sh
- echo -n "latest,${DRONE_TAG#v}" > .tags
- 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

View File

@ -11,3 +11,22 @@ enc := Encrypt(msg, key)
dec, _ := Decrypt(enc, key) dec, _ := Decrypt(enc, key)
fmt.Printf("%s -> %s -> %s\n", msg, enc, dec) fmt.Printf("%s -> %s -> %s\n", msg, enc, dec)
``` ```
## Helper cli
```shell
usage: xorenc [e|d] msg key
$ xorenc e test secret
BwAQBg==
$ xorenc d BwAQBg== secret
test
```
### Install
```sh
sudo rm -f /usr/local/bin/xorenc
sudo sh -c "curl -fsSL RELEASE_URL | tar -C /usr/local/bin/ -xz"
```

46
cmd/xorenc/main.go Normal file
View File

@ -0,0 +1,46 @@
package main
import (
"flag"
"fmt"
"os"
"strings"
"kumoly.io/lib/xorencrypt"
)
var Version = "0.0.0"
var Build = "alpha"
var verFlag bool
func init() {
flag.BoolVar(&verFlag, "v", false, "shoe version")
}
func main() {
flag.Parse()
if verFlag {
fmt.Printf("%s - %s\n", Version, Build)
return
}
if len(os.Args) < 3 {
fmt.Println("usage: xorencrypt [e|d] msg key")
os.Exit(1)
}
key := ""
if len(os.Args) > 3 {
key = os.Args[3]
}
msg := os.Args[2]
if strings.HasPrefix(os.Args[1], "e") {
fmt.Println(xorencrypt.Encrypt(msg, key))
} else {
str, err := xorencrypt.Decrypt(msg, key)
if err != nil {
panic(err)
}
fmt.Println(str)
}
}

33
make.sh Normal file
View File

@ -0,0 +1,33 @@
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=xorenc
DIST=dist
LDFLAGS="-ldflags \"-X main.Version=${VERSION} -X main.Build=${BUILD} -w -s\""
FAILURES=""
PLATFORMS="darwin/amd64 darwin/arm64"
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="GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o ${DIST}/${BIN_FILENAME} cmd/xorenc/main.go"
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