Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Jun 29, 2022
0 parents commit 6e1658b
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 0 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/release.yaml
@@ -0,0 +1,128 @@
name: Release
on:
push:
branches:
- 'main'

jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: "1.17"
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-code-dependencies-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-code-dependencies
- run: |
go vet ./...
go test ./...
version:
name: Semantic versioning
needs: build
runs-on: ubuntu-latest
outputs:
new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
steps:
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: "1.17"
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-code-dependencies-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-code-dependencies
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
extra_plugins: |
@semantic-release/commit-analyzer
@semantic-release/release-notes-generator
@semantic-release/changelog
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

binary_release:
name: Binary release
needs: version
if: ${{ needs.version.outputs.new_release_published == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set git tag
run: git tag ${{ needs.version.outputs.new_release_version }}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Install vembed
run: go install github.com/NoUseFreak/go-vembed/vembed@latest
- name: Prepare vembed info
run: echo "VEMBED=$(vembed)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

docker_release:
name: Docker release
needs: version
if: ${{ needs.version.outputs.new_release_published == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Current
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}},value=${{ needs.version.outputs.new_release_version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.version.outputs.new_release_version }}
type=semver,pattern={{major}},value=${{ needs.version.outputs.new_release_version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
dist/
.tmp
93 changes: 93 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,93 @@
env:
- PROJECT_DESCRIPTION=
- PROJECT_HOMEPAGE=https://stenic.io
- LICENSE=MIT

before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- "386"
- amd64
- arm
- arm64
goarm:
- "6"
- "7"
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '{{ .Env.VEMBED }}'

checksum:
name_template: 'checksums.txt'

archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE

brews:
- tap:
owner: stenic
name: homebrew-tap
folder: Formula
homepage: "{{ .Env.PROJECT_HOMEPAGE }}"
description: "{{ .Env.PROJECT_DESCRIPTION }}"
license: "{{ .Env.LICENSE }}"
test: |
system "#{bin}/{{ .ProjectName }} -v"
dependencies: []
install: |-
bin.install "{{ .ProjectName }}"
rigs:
- rig:
owner: stenic
name: fish-food
homepage: "{{ .Env.PROJECT_HOMEPAGE }}"
description: "{{ .Env.PROJECT_DESCRIPTION }}"
license: "{{ .Env.LICENSE }}"

scoop:
bucket:
owner: stenic
name: scoop-bucket
homepage: "{{ .Env.PROJECT_HOMEPAGE }}"
description: "{{ .Env.PROJECT_DESCRIPTION }}"
license: "{{ .Env.LICENSE }}"

nfpms:
- file_name_template: '{{ .ConventionalFileName }}'
id: packages
homepage: "{{ .Env.PROJECT_HOMEPAGE }}"
description: "{{ .Env.PROJECT_DESCRIPTION }}"
maintainer: Dries De Peuter <dries@stenic.io>
license: "{{ .Env.LICENSE }}"
vendor: Stenic
formats:
- apk
- deb
- rpm
dependencies: []
recommends: []

# snapcrafts:
# - name_template: '{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
# summary: "{{ .Env.PROJECT_DESCRIPTION }}"
# description: "{{ .Env.PROJECT_DESCRIPTION }}"
# grade: devel
# confinement: strict
# publish: true
17 changes: 17 additions & 0 deletions Dockerfile
@@ -0,0 +1,17 @@
FROM golang:1.17 as builder

WORKDIR /workspace
COPY go.* .
RUN go mod download
COPY main.go main.go
RUN CGO_ENABLED=0 GOOS=linux go build -a -o /project main.go


# Use distroless as minimal base image to package the project
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot

WORKDIR /
COPY --from=builder /project .
ENTRYPOINT ["/project"]

21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Stenic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions README.md
@@ -0,0 +1,60 @@
# [[project]]

[[project]] does things.

## Installation

```shell
# homebrew
brew install stenic/tap/[[project]]

# gofish
gofish rig add https://github.com/stenic/fish-food
gofish install github.com/stenic/fish-food/[[project]]

# scoop
scoop bucket add [[project]] https://github.com/stenic/scoop-bucket.git
scoop install [[project]]

# go
go install github.com/stenic/[[project]]@latest

# docker
docker pull ghcr.io/stenic/[[project]]:latest

# dockerfile
COPY --from=ghcr.io/stenic/[[project]]:latest /[[project]] /usr/local/bin/
```

> For even more options, check the [releases page](https://github.com/stenic/[[project]]/releases).

## Run

```shell
# Installed
[[project]] -h

# Docker
docker run -ti ghcr.io/stenic/[[project]]:latest -h

# Kubernetes
kubectl run [[project]] --image=ghcr.io/stenic/[[project]]:latest --restart=Never -ti --rm -- -h
```

## Documentation

```shell
[[project]] -h
```

## Badges

[![Release](https://img.shields.io/github/release/stenic/[[project]].svg?style=for-the-badge)](https://github.com/stenic/[[project]]/releases/latest)
[![Software License](https://img.shields.io/github/license/stenic/[[project]]?style=for-the-badge)](./LICENSE)
[![Build status](https://img.shields.io/github/workflow/status/stenic/[[project]]/Release?style=for-the-badge)](https://github.com/stenic/[[project]]/actions?workflow=build)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)

## License

[License](./LICENSE)
21 changes: 21 additions & 0 deletions TEMPLATE.md
@@ -0,0 +1,21 @@
# tpl go binary

Template project for building and publishing binaries based on [Go](https://golang.org/).

## Setup

Make sure to search for `[[project]]` once you think you are done.


### Configuration

- .goreleaser.yml
- Dockerfile
- README.md
- Delete this file ;-)

### Pipeline

Create a [personal access token](https://github.com/settings/tokens) for the project
and configure it under `Settings > Secrets` on you repository called `GH_PAT`.

3 changes: 3 additions & 0 deletions go.mod
@@ -0,0 +1,3 @@
module github.com/nousefreak/gorel-poc

go 1.17
5 changes: 5 additions & 0 deletions main.go
@@ -0,0 +1,5 @@
package main

// func main() {
// println("Ba dum, tss!")
// }
14 changes: 14 additions & 0 deletions release.config.js
@@ -0,0 +1,14 @@
module.exports = {
"plugins": [
["@semantic-release/commit-analyzer"],
["@semantic-release/release-notes-generator"],
["@semantic-release/changelog", {
"changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file. See\n[Conventional Commits](https://conventionalcommits.org) for commit guidelines."
}],
["@semantic-release/git", {
"assets": ["CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
}]
],
"branches": ["main"]
}

0 comments on commit 6e1658b

Please sign in to comment.