diff --git a/.github/build.sh b/.github/build.sh index 565f4ba..ae8a718 100755 --- a/.github/build.sh +++ b/.github/build.sh @@ -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} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..82c90ca --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 99c8d66..5efd86f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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 }} diff --git a/.gitignore b/.gitignore index 66fd13c..828be96 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +bin/gogeta* \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index e942803..69460c5 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -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 . diff --git a/cmd/github.go b/cmd/github.go index b14152a..a5a4a34 100644 --- a/cmd/github.go +++ b/cmd/github.go @@ -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 } diff --git a/cmd/version.go b/cmd/version.go index 1064c78..2cdeb83 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( ) var ( - Version string + Version string = "Dev" GitCommit string ) @@ -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 } diff --git a/main.go b/main.go index c9736a2..18a95be 100644 --- a/main.go +++ b/main.go @@ -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()