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: New Release Process and Homebrew Deployment #82

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 18 additions & 9 deletions .github/workflows/go-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,40 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
-
name: Checkout
uses: actions/checkout@v2
- name: Setup Go
-
name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.18'
- name: Install Dependencies
-
name: Install Dependencies
run: |
go version
go install golang.org/x/lint/golint@latest
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
- name: Tests
-
name: Test
run: |
go test -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
- name: CodeCov
-
name: CodeCov
run: bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Build
-
name: Build
run: go build
- name: Vet
-
name: Vet
run: go vet -v
- name: Lint
-
name: Lint
run: golint ./...
- name: gocyclo
-
name: gocyclo
run: gocyclo .

163 changes: 29 additions & 134 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,150 +1,45 @@
name: hookz Release
name: Release

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.upload_url.outputs.upload_url }}

steps:
- name: Checkout code
-
name: Checkout
uses: actions/checkout@v2

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
This release has the following changes:
- README Updates.
draft: false
prerelease: false

- name: Fix Upload URL
id: upload_url
run: echo ::set-output name=upload_url::$(echo "${{ steps.create_release.outputs.upload_url }}" | cut -d"{" -f1)

- name: Echo upload url
run: echo "${{ steps.upload_url.outputs.upload_url }}"

build:
needs: release
strategy:
matrix:
os: ["darwin", "freebsd", "linux", "netbsd", "openbsd", "windows"]
arch: ["amd64", "arm64", "arm"]

env:
UPLOAD_URL: ${{ needs.release.outputs.upload_url }}

name: Build and Upload Assets
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Go
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.18'

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Generate SBOM
uses: CycloneDX/gh-gomod-generate-sbom@v0.3.0
go-version: 1.18
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
include-stdlib: true
json: true
output: sbom.json
resolve-licenses: true
version: "^v0"

- name: Build amd64 Assets
if: matrix.arch == 'amd64'
run: |
echo "${{ matrix.os }} ${{ matrix.arch }}"
env GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o $FILE github.com/devops-kung-fu/hookz
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}

- name: Build arm64 Assets
if: matrix.arch == 'arm64' && matrix.os == 'linux'
run: |
echo "${{ matrix.os }} ${{ matrix.arch }}"
env GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o $FILE github.com/devops-kung-fu/hookz
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}

- name: Build arm Assets
if: matrix.arch == 'arm' && (matrix.os == 'freebsd' || matrix.os == 'netbsd' || matrix.os == 'openbsd')
run: |
echo "${{ matrix.os }} ${{ matrix.arch }}"
env GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o $FILE github.com/devops-kung-fu/hookz
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}

- name: Upload SBoM
run: |
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$(basename $FILE)"
env:
FILE: sbom.json

- name: Upload amd64 Non-Windows
if: matrix.os != 'windows' && matrix.arch == 'amd64'
run: |
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$(basename $FILE)"
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}

- name: Upload amd64 Windows
if: matrix.os == 'windows' && matrix.arch == 'amd64'
run: |
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$(basename $FILE)"
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.exe

- name: Upload arm64
if: matrix.os == 'linux' && matrix.arch == 'arm64'
run: |
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$(basename $FILE)"
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}
distribution: goreleaser
version: ${{ env.GITHUB_REF_NAME }}
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
-
name: Generate SBOM
uses: anchore/sbom-action@v0
with:
artifact-name: hookz.spdx.json
path: .
-
name: Release SBOM
uses: anchore/sbom-action/publish-sbom@v0
with:
sbom-artifact-match: ".*\\.spdx.json$"

- name: Upload arm
if: (matrix.os == 'freebsd' || matrix.os == 'netbsd' || matrix.os == 'openbsd') && matrix.arch == 'arm'
run: |
curl \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"$UPLOAD_URL?name=$(basename $FILE)"
env:
FILE: build/hookz-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}
32 changes: 32 additions & 0 deletions .goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
builds:
- binary: hookz
goos:
- darwin
- linux
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
flags:
- -mod=vendor

release:
prerelease: auto

universal_binaries:
- replace: true

brews:
-
name: hookz
homepage: "https://github.com/devops-kung-fu/hooks"
tap:
owner: devops-kung-fu
name: homebrew-tap
commit_author:
name: djschleen
email: djschleen@gmail.com

checksum:
name_template: 'checksums.txt'
11 changes: 5 additions & 6 deletions .hookz.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: 2.4.0
version: 2.4.1
sources:
- source: github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
- source: github.com/devops-kung-fu/lucha@latest
- source: github.com/anchore/syft/cmd/syft@latest
- source: github.com/devops-kung-fu/hinge@latest
- source: github.com/kisielk/errcheck@latest
- source: golang.org/x/lint/golint@latest
Expand Down Expand Up @@ -42,9 +41,9 @@
- name: "go: Test coverage"
exec: go
args: ["tool", "cover", "-func=coverage.out"]
- name: "cyclone-dx: Generate a Software Bill of Materials (SBoM)"
exec: cyclonedx-gomod
args: ["-json", "-output", "hookz-sbom.json"]
- name: "syft: Generate a Software Bill of Materials (SBoM)"
exec: syft
args: [".","-o ","json=sbom/hookz.syft.json","-o", "spdx-json=sbom/hookz.spdx.json", "-o", "cyclonedx-json=sbom/hookz.cyclonedx.json"]
- name: "git: Add all changed files during the pre-commit stage"
exec: git
args: ["add", "."]
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"gomod",
"hookz",
"ignoretests",
"sbom"
"sbom",
"syft"
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to SHS
# Contributing

## We Develop with Github

Expand Down
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help

help: ## This help
Expand All @@ -14,19 +11,19 @@ title:

build: ## Builds the application
go get -u ./...
go mod tidy
go build
@go mod tidy
@go build

check: build ## Tests the pre-commit hooks if they exist
./hookz reset --verbose --debug --verbose-output
. .git/hooks/pre-commit

test: ## Runs tests and coverage
go test -v -coverprofile=coverage.out ./... && go tool cover -func=coverage.out
@go test -v -coverprofile=coverage.out ./... && go tool cover -func=coverage.out

install: build ## Builds an executable local version of Hookz and puts in in /usr/local/bin
sudo chmod +x hookz
sudo mv hookz /usr/local/bin
@sudo chmod +x hookz
@sudo mv hookz /usr/local/bin

all: title build test ## Makes all targets

Loading