Skip to content

Commit

Permalink
feat: merge in base repo changes for homebrew goodness
Browse files Browse the repository at this point in the history
  • Loading branch information
deweysasser committed Nov 9, 2022
2 parents 2e34fb3 + 1f0fdf2 commit 2ae1dc4
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 87 deletions.
38 changes: 38 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})

{{ range .CommitGroups -}}
### {{ .Title }}

{{ range .Commits -}}
* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts

{{ range .RevertCommits -}}
* {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .MergeCommits -}}
### Pull Requests

{{ range .MergeCommits -}}
* {{ .Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}

{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
28 changes: 28 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/deweysasser/golang-program
options:
commits:
# filters:
# Type:
# - feat
# - fix
# - perf
# - refactor
commit_groups:
# title_maps:
# feat: Features
# fix: Bug Fixes
# perf: Performance Improvements
# refactor: Code Refactoring
header:
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
pattern_maps:
- Type
- Scope
- Subject
notes:
keywords:
- BREAKING CHANGE
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
name: Run checks and build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}

Expand All @@ -31,10 +31,10 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}

Expand Down
76 changes: 40 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,45 @@ jobs:
- GOOS: windows
ext: .exe
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION}}

- name: Repo Name
id: repo-name
run: echo ::set-output name=name::$(basename ${{github.repository}})
run: echo name=$(basename ${{github.repository}}) >> $GITHUB_OUTPUT

- name: Test
run: go test -v ./...

- name: Build
run: make compile PROGRAM=output/${{steps.repo-name.outputs.name}}-${{env.GOOS}}-${{env.GOARCH}}${{matrix.ext}}
run: make package PROGRAM=bin/${{env.GOOS}}-${{env.GOARCH}}/${{steps.repo-name.outputs.name}}${{matrix.ext}} PACKAGE=dist/${{steps.repo-name.outputs.name}}-${{env.GOOS}}-${{env.GOARCH}}.zip
env:
GOOS: ${{matrix.GOOS}}
GOARCH: ${{matrix.GOARCH}}

- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: output
path: dist
retention-days: 1
if-no-files-found: error

release:
runs-on: ubuntu-latest
needs:
- build
- docker-build
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download Artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3

- name: Install ChangeLog generator
run: |
Expand All @@ -72,7 +73,7 @@ jobs:

- name: Generate Changelog for ${{ github.ref_name }}
id: generate-changelog
run: make CHANGELOG.md
run: PATH="${PATH}:." make CHANGELOG.md

- name: Create Release
id: create_release
Expand All @@ -81,37 +82,40 @@ jobs:
files: ./artifacts/*
body_path: ./CHANGELOG.md
draft: false
#
# docker-build:
# runs-on: ubuntu-latest
# name: Build the docker image
# steps:
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Checkout
# uses: actions/checkout@v2
#
# - name: Docker Release to GHCR
# uses: docker/build-push-action@v2
# with:
# context: .
# push: true
# build-args: |
# GO_VERSION=${{ env.GO_VERSION }}
# VERSION=${{ github.ref_name }}
# tags: |
# ghcr.io/${{env.REPO}}:latest
# ghcr.io/${{env.REPO}}:${{ github.ref_name }}

docker-build:
runs-on: ubuntu-latest
name: Build the docker image
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout
uses: actions/checkout@v3

- name: Checkout
uses: actions/checkout@v2

- name: Build Image
run: make image IMAGE=ghcr.io/${{env.REPO}}:${{ github.ref_name }}

- name: Tag latest
run: docker tag ghcr.io/${{env.REPO}}:${{ github.ref_name }} ghcr.io/${{env.REPO}}:latest

- name: Push
run: docker push ghcr.io/${{env.REPO}}:${{ github.ref_name }}

- name: Push Latest
run: docker push ghcr.io/${{env.REPO}}:latest

# uncomment this if you're also using docker hub
# - name: Login to Docker Container Registry
# if: ${{ secrets.DOCKERHUB_TOKEN }}
# uses: docker/login-action@v1
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-multiplatform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}

Expand Down
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/
golang-program
.idea
CHANGELOG.md
eks-kubeconfig-update
.idea
CHANGELOG.md
eks-kubeconfig-update
dist
bin
.Dockerfile.tmp
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ repos:
rev: v1.0.0-beta.5
hooks:
- id: go-fmt
- id: go-vet
# this hook isn't doing the right thing right now
# - id: go-vet
- id: go-sec-mod
- id: go-staticcheck-mod
- id: go-critic
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ RUN GOBIN=/output make install VERSION=$VERSION
RUN PROGRAM=$(ls /output); echo "#!/bin/sh\nexec '/usr/bin/$PROGRAM' \"\$@\"" > /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh


FROM alpine:latest
RUN apk add --no-cache libc6-compat ca-certificates
FROM gcr.io/distroless/base:latest
ARG PROGRAM=nothing

COPY --from=builder /output/* /usr/bin
COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
COPY --from=builder /output/${PROGRAM} /
USER 1000
ENTRYPOINT [""]
44 changes: 34 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,72 @@

ifeq ($(OS),Windows_NT)
ifeq ($(shell go env GOOS),windows)
EXE=.exe
else
EXE=
endif

DIST=dist
BINDIR=.

BASENAME=$(notdir $(shell pwd))
PROGRAM=$(BASENAME)$(EXE)
PROGRAM=$(BINDIR)/$(BASENAME)$(EXE)
LAST_RELEASE=

REPO=$(shell go list | head -n 1)
IMAGE=$(BASENAME)
VERSION ?= $(shell git describe --tags --always --dirty)
DOCKER=docker
PACKAGE=$(DIST)/$(basename $(notdir $(PROGRAM)))-$(shell go env GOOS)-$(shell go env GOARCH).zip


.PHONY: $(PROGRAM)

all: $(PROGRAM)

compile: $(PROGRAM)

$(PROGRAM):
$(PROGRAM): $(BINDIR)
mkdir -p $(dir $@)
go build -ldflags="-X '$(REPO)/program.Version=${VERSION}'" -o $(PROGRAM)

package: $(PACKAGE)

$(PACKAGE): $(PROGRAM)

# These next 2 recipes know how to make .zip and .tar files, which are used implicitly in making the package
%.zip:
mkdir $(dir $@)
zip -j $@ $?

%.tar.gz %.tgz:
mkdir $(dir $@)
tar -czf $@ -C $(dir $<) $(notdir $<)



install:
go install -ldflags="-X '$(REPO)/program.Version=${VERSION}'"


image: Dockerfile
$(DOCKER) build --build-arg PROGRAM=$(BASENAME) --build-arg VERSION=$(VERSION) --build-arg BASENAME=$(BASENAME) -t $(IMAGE) .
image: .Dockerfile.tmp
$(DOCKER) build -f $< --build-arg PROGRAM=$(BASENAME) --build-arg VERSION=$(VERSION) --build-arg BASENAME=$(BASENAME) -t $(IMAGE) .

.Dockerfile.tmp: Dockerfile
sed -e "s|^ENTRYPOINT.*|ENTRYPOINT [\"/${BASENAME}\"]|" < $< > $@.tmp
mv -f $@.tmp $@

test:
go test -v ./...

vet:
go vet ./...


changelog: CHANGELOG.md
CHANGELOG.md: .chglog/config.yml
git chglog $(LAST_RELEASE) >$@

CHANGELOG.md: LAST=$(shell git tag --sort=-version:refname | tail -n -1 | head -n 1)
CHANGELOG.md: TOP=$(shell git tag --sort=-version:refname | head -n 1)
CHANGELOG.md:
git log --pretty="* %s (%h)" $(LAST).. >> $@
.chglog/config.yml: go.mod
sed -i.bak -e "s|repository_url:.*|repository_url: https://$(REPO)|" $@

hooks: .git/hooks/pre-commit

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
}

// This ends up calling options.Run()
if err := context.Run(); err != nil {
if err := context.Run(&options); err != nil {
log.Err(err).Msg("Program failed")
os.Exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (program *Options) Parse(args []string) (*kong.Context, error) {
}

// Run runs the program
func (program *Options) Run() error {
func (program *Options) Run(options *Options) error {
config, err := program.ReadConfig()
if err != nil {
log.Error().Err(err).Msg("Failed to read kubeconfig file")
Expand Down Expand Up @@ -95,7 +95,6 @@ func (program *Options) AfterApply() error {
program.initLogging()

if len(program.Regions) < 1 {
//log.Error().Msg("Must specify at least one region")
return errors.New("Must specify at least one region")
}
return nil
Expand Down
Loading

0 comments on commit 2ae1dc4

Please sign in to comment.