Skip to content

Commit

Permalink
ci: add main flow with goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
alexppg committed Jun 28, 2021
1 parent 5551698 commit c7af778
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 14 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/generic-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests

on: push

jobs:
unit-test:
runs-on: ubuntu-18.04
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Run unit tests
run: make unit

static:
runs-on: ubuntu-18.04
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Run static linters
run: make static
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on: push

jobs:
release:
runs-on: ubuntu-18.04
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.COMMITER_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/coverage.out
/bin/
dist/
57 changes: 57 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
ldflags:
- -s -w
- -X github.com/little-angry-clouds/particle/cmd.Version={{.Version}}
- -X github.com/little-angry-clouds/particle/cmd.Commit={{.Commit}}
- -X github.com/little-angry-clouds/particle/cmd.Date={{.Date}}
goarch:
- amd64
- arm
- arm64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^ci:'
release:
github:
owner: little-angry-clouds
name: particle
draft: true
brews:
- name: particle
tap:
owner: little-angry-clouds
name: homebrew-my-brews
url_template: "https://github.com/little-angry-clouds/homebrew-my-brews{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: goreleaserbot
email: [email protected]
folder: Formula
homepage: https://github.com/little-angry-clouds/particle/
description: Particle is a project designed to aid in the development and testing of Helm charts and other kubernetes manifests.
license: "GPL3"
dependencies:
- name: go
- name: helm
type: optional
- name: kind
type: optional
install: |
ENV.prepend "CGO_ENABLED", "0"
system "go", "build", "-a", "-o", "particle.bin", "main.go"
bin.install "particle.bin" => "#{bin}/particle"
24 changes: 10 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ $(BIN)/golangci-lint: | $(BIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.24.0
$(BIN)/gopherbadger: | $(BIN)
GOBIN=$(BIN) go get github.com/jpoles1/gopherbadger
$(BIN)/goreleaser: | $(BIN)
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh

# Binaries to install
GOLANGCI-LINT = $(BIN)/golangci-lint
GOPHERBADGER = $(BIN)/gopherbadger
GORELEASER = $(BIN)/goreleaser

###############################################################################
###############################################################################
###############################################################################

all: clean static test build
all: clean static unit build

# Build binaries
build:
go build -a -o bin/particle main.go;
build: | $(GORELEASER)
$(GORELEASER) build --rm-dist --skip-validate

clean:
-rm -r bin/
-rm -r releases/
rm -r bin/
rm -r dist/

static: | $(GOLANGCI-LINT) $(GOPHERBADGER)
$(GOLANGCI-LINT) run ./... --fix
Expand All @@ -32,12 +35,5 @@ static: | $(GOLANGCI-LINT) $(GOPHERBADGER)
unit:
go test ./... -cover

PLATFORMS := linux-amd64 linux-386 darwin-amd64 windows-amd64 windows-386
temp = $(subst -, ,$@)
os = $(word 1, $(temp))
arch = $(word 2, $(temp))
releases: $(PLATFORMS)
$(PLATFORMS):
@mkdir -p releases; \
CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) go build -a -o bin/particle-$(os)-$(arch) main.go; \
tar -C bin -cvzf releases/particle-$(os)-$(arch).tar.gz particle-$(os)-$(arch) particle-$(os)-$(arch); \
releases:
$(GORELEASER) release
30 changes: 30 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
goVersion "go.hein.dev/go-version"
)

var (
Version = "dev"
Commit = "none"
Date = "unknown"
shortened = false
output = "json"
versionCmd = &cobra.Command{
Use: "version",
Short: "Outputs the current build information",
Run: func(_ *cobra.Command, _ []string) {
resp := goVersion.FuncWithOutput(shortened, Version, Commit, Date, output)
fmt.Print(resp)
},
}
)

func init() {
versionCmd.Flags().BoolVar(&shortened, "short", false, "Print just the version number.")
versionCmd.Flags().StringVar(&output, "output", "yaml", "Output format. One of 'yaml' or 'json'.")
rootCmd.AddCommand(versionCmd)
}

0 comments on commit c7af778

Please sign in to comment.