Add drone builds
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
IamTheFij 2021-02-02 13:49:10 -08:00
parent ee8ec2c8da
commit d19df7e3f9
3 changed files with 99 additions and 2 deletions

82
.drone.yml Normal file
View File

@ -0,0 +1,82 @@
---
kind: pipeline
name: test
steps:
- name: check
image: iamthefij/drone-pre-commit:personal
---
kind: pipeline
name: build and publish
depends_on:
- test
trigger:
event:
- push
- tag
refs:
- refs/heads/master
- refs/tags/v*
steps:
- name: build all binaries
image: golang:1.15
environment:
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
CLIENT_ID:
from_secret: slack_client_id
CLIENT_SECRET:
from_secret: slack_client_secret
commands:
- make all
- name: compress binaries for release
image: ubuntu
commands:
- find ./dist -type f -executable -execdir tar -czvf {}.tar.gz {} \;
when:
event: tag
- name: upload gitea release
image: plugins/gitea-release
settings:
title: ${DRONE_TAG}
files: dist/*.tar.gz
checksum:
- md5
- sha1
- sha256
- sha512
base_url:
from_secret: gitea_base_url
api_key:
from_secret: gitea_token
when:
event: tag
---
kind: pipeline
name: notify
depends_on:
- test
trigger:
status:
- failure
steps:
- name: notify
image: drillster/drone-email
settings:
host:
from_secret: SMTP_HOST # pragma: whitelist secret
username:
from_secret: SMTP_USER # pragma: whitelist secret
password:
from_secret: SMTP_PASS # pragma: whitelist secret
from: drone@iamthefij.com

View File

@ -2,6 +2,7 @@ OUTPUT = slack-status
GOFILES = *.go go.mod go.sum
DIST_ARCH = darwin-amd64 linux-amd64
DIST_TARGETS = $(addprefix dist/$(OUTPUT)-,$(DIST_ARCH))
VERSION ?= $(shell git describe --tags --dirty)
.PHONY: default
default: slack-status
@ -28,12 +29,12 @@ $(DIST_TARGETS): $(GOFILES)
@mkdir -p ./dist
GOOS=$(word 3, $(subst -, ,$(@))) GOARCH=$(word 4, $(subst -, ,$(@))) \
go build \
-ldflags '-X "main.defaultClientID=$(CLIENT_ID)" -X "main.defaultClientSecret=$(CLIENT_SECRET)"' \
-ldflags '-X "main.version=${VERSION}" -X "main.defaultClientID=$(CLIENT_ID)" -X "main.defaultClientSecret=$(CLIENT_SECRET)"' \
-o $@
.PHONY: clean
clean:
rm ./slack-status
rm -f ./slack-status
rm -fr ./dist
.PHONY: install-hooks

14
main.go
View File

@ -10,6 +10,10 @@ import (
"github.com/slack-go/slack"
)
var (
version = "dev"
)
// statusInfo contains all args passed from the command line
type statusInfo struct {
// status contents
@ -20,6 +24,9 @@ type statusInfo struct {
// domain and login management
login, makeDefault bool
domain string
// other
showVersion bool
}
// getExipirationTime returns epoch time that status should expire from the duration.
@ -72,6 +79,7 @@ func readFlags() statusInfo {
login := flag.Bool("login", false, "login to a Slack workspace")
domain := flag.String("domain", "", "domain to set status on")
makeDefault := flag.Bool("make-default", false, "set the current domain to default")
showVersion := flag.Bool("version", false, "show version and exit")
// Status flags
snooze := flag.Bool("snooze", false, "snooze notifications")
@ -111,6 +119,7 @@ func readFlags() statusInfo {
login: *login,
domain: *domain,
makeDefault: *makeDefault,
showVersion: *showVersion,
}
}
@ -163,6 +172,11 @@ func getClient(domain string) (*slack.Client, error) {
func main() {
args := readFlags()
if args.showVersion {
fmt.Println("version:", version)
return
}
var client *slack.Client
var err error