Skip to content

Commit

Permalink
feat: deb, rpm, and homebrew support (#28)
Browse files Browse the repository at this point in the history
* Adds support for deb, rpm, and Homebrew installation
  • Loading branch information
djschleen authored Aug 2, 2022
1 parent f10c664 commit 063a098
Show file tree
Hide file tree
Showing 15 changed files with 2,153 additions and 465 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ updates:
schedule:
interval: daily
time: "05:00"
timezone: UTC
timezone: US/Pacific
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
time: "05:00"
timezone: UTC
timezone: US/Pacific
3 changes: 2 additions & 1 deletion .github/workflows/go-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
-
name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
Expand Down
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: hinge 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/hinge
env:
FILE: build/hinge-${{ 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/hinge
env:
FILE: build/hinge-${{ 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/hinge
env:
FILE: build/hinge-${{ 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/hinge-${{ 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/hinge-${{ 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/hinge-${{ 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: hinge.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/hinge-${{ steps.get_version.outputs.VERSION }}-${{ matrix.os }}-${{ matrix.arch }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# vendor/

.DS_Store

hinge
41 changes: 41 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
project_name: hinge

builds:
-
binary: hinge
goos:
- darwin
- linux
goarch:
- amd64
- arm64

release:
prerelease: auto

universal_binaries:
- replace: true

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

checksum:
name_template: 'checksums.txt'

nfpms:
- maintainer: DJ Schleen <djschleen@gmail.com>
description: Creates and updates your Dependabot config.
homepage: https://github.com/devops-kung-fu/hinge
license: MPL
formats:
- deb
- rpm

19 changes: 12 additions & 7 deletions .hookz.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.4.0
version: 2.4.1
sources:
- source: github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@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 @@ -30,7 +30,7 @@
exec: gocyclo
args: ["-over", "8", "."]
- name: Hinge
exec: hinge
exec: ./hinge
args: ["."]
- name: "go: Build (Ensure pulled modules do not break the build)"
exec: go
Expand All @@ -41,9 +41,14 @@
- 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", "hinge-sbom.json"]
- name: "syft: Generate a Software Bill of Materials (SBoM)"
exec: syft
args: [".","-o ","json=sbom/hinge.syft.json","-o", "spdx-json=sbom/hinge.spdx.json", "-o", "cyclonedx-json=sbom/hinge.cyclonedx.json"]
- name: "git: Add all changed files during the pre-commit stage"
exec: git
args: ["add", "."]
args: ["add", "."]
- type: pre-push
actions:
- name: "hookz: example pre-push hook"
exec: /bin/echo
args: ["Pushing changes..."]
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ title:
@echo "--------------"

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

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

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

all: title build test ## Makes all targets
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ Creates and updates your Dependabot configuration file, `dependabot.yml`.

## Installation

To install ```hinge```, [download the latest release](https://github.com/devops-kung-fu/hinge/releases) , make it executable, rename it to `hinge` and move it to the `/usr/local/bin` directory for Linux, or on your `PATH` for other operating systems.
### Mac

### Linux Example
You can use [Homebrew](https://brew.sh) to install ```Hookz``` using the following:

```bash
sudo chmod +x hinge-1.0.0-linux-amd64
sudo mv hinge-1.0.0-linux-amd64 /usr/local/bin/hinge
``` bash
brew tap devops-kung-fu/homebrew-tap
brew install devops-kung-fu/homebrew-tap/hinge
```

### Linux

To install ```hinge```, download the latest release [deb or rpm](https://github.com/devops-kung-fu/hinge/releases and install.

``` bash
# Debian Example
dpkg -i hinge_1.0.1_linux_amd64.deb

### With a Go Development Environment

If you have a Go development environment set up, you can also simply do this:
Expand Down Expand Up @@ -71,7 +80,7 @@ Once ```hinge``` is installed, you can run this command in the root of your git
hinge .
```

**NOTE**: The provided path needs to be a git repository.
**NOTE**: The provided path must be a git repository.

### Flag Notes

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

var (
version = "1.0.0"
version = "1.0.1"
//Afs stores a global OS Filesystem that is used throughout hinge
Afs = &afero.Afero{Fs: afero.NewOsFs()}
//Verbose determines if the execution of hing should output verbose information
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/devops-kung-fu/common v0.2.3
github.com/gookit/color v1.5.1
github.com/spf13/afero v1.8.2
github.com/spf13/afero v1.9.2
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -17,7 +17,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 063a098

Please sign in to comment.