Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use new version pkg #29

Merged
merged 4 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ jobs:
- name: clone
uses: actions/checkout@v2

- name: setup
run: |
# setup git tag in Actions environment
echo "GITHUB_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: build
env:
GOOS: linux
CGO_ENABLED: '0'
run: |
go build -a \
-ldflags '-s -w -extldflags "-static"' \
-o release/vela-downstream \
github.com/go-vela/vela-downstream/cmd/vela-downstream
make build-static-ci

- name: publish
uses: elgohr/Publish-Docker-Github-Action@master
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
GOOS: linux
CGO_ENABLED: '0'
run: |
go build -a \
-ldflags '-s -w -extldflags "-static"' \
-o release/vela-downstream \
github.com/go-vela/vela-downstream/cmd/vela-downstream
make build-static-ci

- name: publish
uses: elgohr/Publish-Docker-Github-Action@master
Expand Down
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
#
# Use of this source code is governed by the LICENSE file in this repository.

# capture the current date we build the application from
BUILD_DATE = $(shell date +%Y-%m-%dT%H:%M:%SZ)

# check if a git commit sha is already set
ifndef GITHUB_SHA
# capture the current git commit sha we build the application from
GITHUB_SHA = $(shell git rev-parse HEAD)
endif

# check if a git tag is already set
ifndef GITHUB_TAG
# capture the current git tag we build the application from
GITHUB_TAG = $(shell git describe --tag --abbrev=0)
endif

# check if a go version is already set
ifndef GOLANG_VERSION
# capture the current go version we build the application from
GOLANG_VERSION = $(shell go version | awk '{ print $$3 }')
endif

# create a list of linker flags for building the golang application
LD_FLAGS = -X github.com/go-vela/vela-downstream/version.Commit=${GITHUB_SHA} -X github.com/go-vela/vela-downstream/version.Date=${BUILD_DATE} -X github.com/go-vela/vela-downstream/version.Go=${GOLANG_VERSION} -X github.com/go-vela/vela-downstream/version.Tag=${GITHUB_TAG}

# The `clean` target is intended to clean the workspace
# and prepare the local changes for submission.
#
Expand Down Expand Up @@ -90,6 +114,7 @@ build:
@echo "### Building release/vela-downstream binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '${LD_FLAGS}' \
-o release/vela-downstream \
github.com/go-vela/vela-downstream/cmd/vela-downstream

Expand All @@ -103,7 +128,21 @@ build-static:
@echo "### Building static release/vela-downstream binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '-s -w -extldflags "-static"' \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-downstream \
github.com/go-vela/vela-downstream/cmd/vela-downstream

# The `build-static-ci` target is intended to compile
# the Go source code into a statically linked binary
# when used within a CI environment.
#
# Usage: `make build-static-ci`
.PHONY: build-static-ci
build-static-ci:
@echo
@echo "### Building CI static release/vela-downstream binary"
@go build -a \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-downstream \
github.com/go-vela/vela-downstream/cmd/vela-downstream

Expand Down
26 changes: 20 additions & 6 deletions cmd/vela-downstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
package main

import (
"encoding/json"
"fmt"
"os"

"time"

"github.com/go-vela/vela-downstream/version"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

Expand All @@ -33,8 +37,9 @@ func main() {

// Plugin Metadata

app.Compiled = time.Now()
app.Action = run
app.Compiled = time.Now()
app.Version = version.New().Semantic()

// Plugin Flags

Expand All @@ -51,13 +56,13 @@ func main() {
// Config Flags

&cli.StringFlag{
EnvVars: []string{"PARAMETER_SERVER", "CONFIG_SERVER", "VELA_SERVER", "DOWNSTREAM_SERVER"},
EnvVars: []string{"PARAMETER_SERVER", "VELA_SERVER", "DOWNSTREAM_SERVER"},
FilePath: string("/vela/parameters/downstream/config/server,/vela/secrets/downstream/config/server"),
jbrockopp marked this conversation as resolved.
Show resolved Hide resolved
Name: "config.server",
Usage: "Vela server to authenticate with",
},
&cli.StringFlag{
EnvVars: []string{"PARAMETER_TOKEN", "CONFIG_TOKEN", "VELA_TOKEN", "DOWNSTREAM_TOKEN"},
EnvVars: []string{"PARAMETER_TOKEN", "VELA_TOKEN", "DOWNSTREAM_TOKEN"},
FilePath: string("/vela/parameters/downstream/config/token,/vela/secrets/downstream/config/token"),
jbrockopp marked this conversation as resolved.
Show resolved Hide resolved
Name: "config.token",
Usage: "user token to authenticate with the Vela server",
Expand All @@ -66,14 +71,14 @@ func main() {
// Repo Flags

&cli.StringFlag{
EnvVars: []string{"PARAMETER_BRANCH", "REPO_BRANCH"},
EnvVars: []string{"PARAMETER_BRANCH", "DOWNSTREAM_BRANCH"},
FilePath: string("/vela/parameters/downstream/repo/branch,/vela/secrets/downstream/repo/branch"),
Name: "repo.branch",
Usage: "default branch to trigger builds for the repo",
Value: "master",
},
&cli.StringSliceFlag{
EnvVars: []string{"PARAMETER_REPOS", "REPO_NAMES", "DOWNSTREAM_REPOS"},
EnvVars: []string{"PARAMETER_REPOS", "DOWNSTREAM_REPOS"},
FilePath: string("/vela/parameters/downstream/repo/names,/vela/secrets/downstream/repo/names"),
Name: "repo.names",
Usage: "list of <org>/<repo> names to trigger",
Expand All @@ -88,6 +93,15 @@ func main() {

// run executes the plugin based off the configuration provided.
func run(c *cli.Context) error {
// capture the version information as pretty JSON
v, err := json.MarshalIndent(version.New(), "", " ")
if err != nil {
return err
}

// output the version information to stdout
fmt.Fprintf(os.Stdout, "%s\n", string(v))

// set the log level for the plugin
switch c.String("log.level") {
case "t", "trace", "Trace", "TRACE":
Expand Down Expand Up @@ -129,7 +143,7 @@ func run(c *cli.Context) error {
}

// validate the plugin
err := p.Validate()
err = p.Validate()
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/go-vela/vela-downstream
go 1.13

require (
github.com/Masterminds/semver v1.5.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/go-vela/sdk-go v0.4.3
github.com/go-vela/types v0.4.3
github.com/go-vela/sdk-go v0.6.0
github.com/go-vela/types v0.6.1-0.20201019123446-226d0cc72538
github.com/joho/godotenv v1.3.0
github.com/sirupsen/logrus v1.6.0
github.com/urfave/cli/v2 v2.2.0
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
)
Loading