Skip to content

Commit

Permalink
feat: Merge pull request #1 from opencloudengineer/improve-ci
Browse files Browse the repository at this point in the history
fixes and features needed to improve ci & build process
  • Loading branch information
opencloudengineer authored Dec 20, 2020
2 parents 52300f1 + 58692d7 commit 5867e4e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 32 deletions.
25 changes: 15 additions & 10 deletions .github/build.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/bin/bash
echo "Building app for Version : ${VERSION} && Git Commit SHA : ${GITHUB_SHA}"
set -xeuo pipefail

set -x
echo "Building on platform with OS: $(go env GOOS) & Arch: $(go env GOARCH)"
echo "Building app for Version : ${VERSION:=$(git describe --tags)} && Git Commit SHA : ${GITHUB_SHA:=$(git rev-parse HEAD)}"

export GO111MODULE=on
export CGO_ENABLED=0

go get ./...

go vet ./...

mkdir -p ./bin

LDFLAGS="-s -w -X github.com/opencloudengineer/gogeta/cmd.Version=${VERSION} -X github.com/opencloudengineer/gogeta/cmd.GitCommit=${GITHUB_SHA}"
FLAGS='-a -installsuffix cgo -o'
BUILD='go build -ldflags'
LDFLAGS="-s -w -X 'github.com/opencloudengineer/gogeta/cmd.Version=${VERSION}' -X 'github.com/opencloudengineer/gogeta/cmd.GitCommit=${GITHUB_SHA}'"

function buildFor() {
GOOS="${1}" GOARCH="${2}" go build -ldflags="${LDFLAGS}" -a -installsuffix cgo -o "./bin/gogeta-${1}-${2}"
}

buildFor windows amd64
buildFor darwin amd64
buildFor linux amd64
buildFor linux arm64

GOOS=windows ${BUILD} "${LDFLAGS}" ${FLAGS} ./bin/gogeta-windows-amd64.exe
GOOS=darwin ${BUILD} "${LDFLAGS}" ${FLAGS} ./bin/gogeta-darwin-amd64
GOOS=linux ${BUILD} "${LDFLAGS}" ${FLAGS} ./bin/gogeta-linux-amd64
GOOS=linux GOARCH=arm64 ${BUILD} "${LDFLAGS}" ${FLAGS} ./bin/gogeta-linux-arm64
# add .exe extension to windows binary
mv ./bin/gogeta-windows-amd64{,.exe}
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
push:
branches:
- "*"
pull_request:
branches:
- "*"

jobs:
build:
strategy:
matrix:
go-version: [1.15.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Generate Binaries
run: bash ./.github/build.sh
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
build-tag-release:
strategy:
matrix:
go-version: [ 1.15.x ]
os: [ ubuntu-latest ]
go-version: [1.15.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand All @@ -32,11 +32,12 @@ jobs:
output-file: "false"

- name: Generate Binaries
run: bash ./.github/build.sh
run: ./.github/build.sh
env:
VERSION: ${{ steps.changelog.outputs.tag }}

- name: Release Binaries
if: ${{ steps.changelog.outputs.tag }}
env:
TAG: ${{ steps.changelog.outputs.tag }}
MSG: ${{ steps.changelog.outputs.clean_changelog }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
bin/gogeta*
5 changes: 4 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
tasks:
- before: >
brew install hadolint;
brew install hadolint ;
brew install shfmt ;
brew install shellcheck ;
npm install -g prettier ;
( cd && go get github.com/jessfraz/dockfmt ) ;
init: go get -v ./...
command: go build .
23 changes: 13 additions & 10 deletions cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@ import (

func Github() *cobra.Command {

example := `gogeta github github.com/GoogleContainerTools/skaffold
gogeta github /stedolan/jq -m linux64
gogeta github aquasecurity/trivy -m 64bit.deb
gogeta github koalaman/shellcheck -m linux.x86_64
gogeta github https://github.com/starship/starship -m linux-gnu`

var command = &cobra.Command{
Use: "github",
Short: `Fetch Github Release(s)`,
Long: `Fetch Github Release(s)`,
Example: `gogeta github github.com/GoogleContainerTools/skaffold
gogeta github /stedolan/jq -m linux64
gogeta github aquasecurity/trivy -m 64bit.deb
gogeta github helm/helm -m linux-amd64
gogeta github https://github.com/starship/starship -m linux-gnu`,
Long: `To Fetch a Github Release
Repository URL is a required argument for the github command`,
Example: example,
SilenceUsage: true,
Aliases: []string{"gh"},
Aliases: []string{"gh", "hub"},
}

command.Flags().StringP("match", "m", "", `Download release matching a specific pattern.
If no pattern is passed, then all releases are fetched.`)
command.Flags().StringP("match", "m", "", `download release matching a specific pattern.
if no pattern is passed, then all releases are fetched.`)

command.RunE = func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {

fmt.Println("Pass Repo Address")
cmd.Help()
return nil
}

Expand Down
10 changes: 3 additions & 7 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
Version string
Version string = "Dev"
GitCommit string
)

Expand All @@ -19,12 +19,8 @@ func AppVersion() *cobra.Command {
SilenceUsage: false,
}
command.Run = func(cmd *cobra.Command, args []string) {
if len(Version) == 0 {
fmt.Println("Version: dev")
} else {
fmt.Println("Version:", Version)
}
fmt.Println("Git Commit:", GitCommit)
fmt.Println("Version :", Version)
fmt.Println("Git Commit :", GitCommit)
}
return command
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
Version := cmd.AppVersion()
Github := cmd.Github()
var rootCmd = &cobra.Command{
Use: "gogeta",
Use: "gogeta",
Short: "Go Get That App",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Expand Down

0 comments on commit 5867e4e

Please sign in to comment.