Skip to content

Commit

Permalink
batman
Browse files Browse the repository at this point in the history
  • Loading branch information
fentas committed Mar 27, 2024
1 parent b85948b commit b8868b1
Show file tree
Hide file tree
Showing 32 changed files with 1,437 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Template form:
# https://github.com/arg-sh/argsh
# curl -sfLS https://envrc.arg.sh > .envrc
# This is an example of a .envrc file for use with direnv.
# It sets up the environment for the project.
set -euo pipefail

: "${PATH_BASE:="$(git rev-parse --show-toplevel)"}"
: "${PATH_BIN:="${PATH_BASE}/.bin"}"
export PATH_BASE PATH_BIN

# shellcheck disable=SC2120
path::add() {
command -v PATH_add 1>/dev/null || {
_error "This can be only run within direnv"
return
}
PATH_add "${1}"
}

export::env() {
local env="${PATH_BASE}/${1}"
# shellcheck disable=SC2046
[ ! -f "${env}" ] || {
export $(grep -v '^#' "${env}" | sed -E 's/\s+=\s+/=/g' | xargs -d '\n')

! command -v watch_file &>/dev/null ||
watch_file "${env}"
}
}

copy::template() {
local -r file="${PATH_BASE}/${1}"
[ -f "${file}" ] || {
cp "${file}.template" "${file}" 2>/dev/null || :
}
}

main() {
# Use this if you want a template file with example values
# make sure to ignore .env and .secrets in your .gitignore
copy::template .env
copy::template .secrets

# This will load the environment variables from the .env and .secrets files
export::env .env
export::env .secrets

# Make your binaries available in the PATH
# This is handy to make sure that all developers have the same binaries available
path::add "${PATH_BIN:-"${PATH_BASE}/.bin"}"
}

# Run the main function if this file is sourced by direnv
[ -z "${DIRENV_IN_ENVRC}" ] || main "${@}"
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fentas
13 changes: 13 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"bootstrap-sha": "fc023e8337f2f8f4c6e8cd3742f989916f682c77",
"include-component-in-tag": false,
"include-v-in-tag": true,
"packages": {
".": {
"release-type": "go",
"package-name": "b-cli",
"extra-files": ["cmd/b/main.go"]
}
}
}
1 change: 1 addition & 0 deletions .github/release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{".":"dev"}
29 changes: 29 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean --snapshot --skip=sign

- uses: actions/upload-artifact@v4
with:
name: Preview Binaries
path: dist/b-*/b
72 changes: 72 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Run gofmt
run: diff -u <(echo -n) <(gofmt -d -s .)

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Required: the version of golangci-lint is required and must be specified with patch version
version: v1.57.1 # renovate: datasource=github-releases depName=golangci/golangci-lint
# In general linting is quite fast with warm caches, but a fresh run might take some time.
args: --timeout 5m

test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run tests
run: go test -coverprofile=coverage.txt -v -race ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

generate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Delete old generated files
run: find . -name 'zz_*.go' -delete

- name: Run go generate
run: go generate ./...

- name: Check uncommitted changes
run: git diff --exit-code

- if: failure()
run: echo "::error::Check failed, please run 'go generate ./...' and commit the changes."
22 changes: 22 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release-please

on:
push:
branches: [main]

permissions:
contents: write
pull-requests: write

jobs:
release-please:
# Do not run on forks.
if: github.repository == 'hetznercloud/cli'

runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
tags:
- "v*.*.*"

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Set up gon
run: brew install mitchellh/gon/gon

- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean --skip=validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
main
60 changes: 60 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
before:
hooks:
- go mod tidy

builds:
- id: b-build
main: ./cmd/b/main.go
binary: b
ldflags:
- -w
- -X {{ .ModulePath }}/cmd/b.version={{ .Version }}
env:
- CGO_ENABLED=0
goos:
- freebsd
- windows
- linux
goarch:
- amd64
- arm
- arm64
- "386"
goarm:
- "6"
- "7"

checksum:
name_template: checksums.txt
algorithm: sha256

signs:
- artifacts: all
signature: ${artifact}.sig
id: buyo-sign
ids:
- b-build
args:
- --batch
- --local-user=github-bot@buyo.io
- --pinentry-mode=loopback
- --output=${signature}
- --detach-sign
- ${artifact}

archives:
- id: b-archive
builds:
- b-build
name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

format_overrides:
- goos: windows
format: zip

files:
- LICENSE
- README.md

release:
draft: false
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/cmd/b/main.go",
"args": ["--help"]
}
]
}
Loading

0 comments on commit b8868b1

Please sign in to comment.