Skip to content

Commit

Permalink
🌱 init: Bootstrap project (#1)
Browse files Browse the repository at this point in the history
Bootstrap the project bu installing the standard foxygoat tooling for
Go programs:

* Go 1.22
* golangci-lint
* hermit
* gh
* make

Use the standard Makefile tool configs, mostly copied from
`foxygoat/offscreen`, but add a new way of doing GitHub releases
instead of using goreleaser.

Use the MIT license - it's simpler than Apache 2.0

This merges the following commits:
* init: Add MIT license
* init: Hermitise repository
* init: Add initial README
* init: Bootstrap project

     .github/workflows/cicd.yaml   |  38 +++++++++++
     .gitignore                    |   1 +
     .golangci.yaml                |  38 +++++++++++
     LICENSE                       |  21 ++++++
     Makefile                      | 122 ++++++++++++++++++++++++++++++++++
     README.md                     |  16 +++++
     bin/.gh-2.54.0.pkg            |   1 +
     bin/.go-1.22.5.pkg            |   1 +
     bin/.golangci-lint-1.59.1.pkg |   1 +
     bin/.make-4.4.pkg             |   1 +
     bin/README.hermit.md          |   7 ++
     bin/activate-hermit           |  21 ++++++
     bin/gh                        |   1 +
     bin/go                        |   1 +
     bin/gofmt                     |   1 +
     bin/golangci-lint             |   1 +
     bin/hermit                    |  43 ++++++++++++
     bin/hermit.hcl                |   1 +
     bin/make                      |   1 +
     go.mod                        |   5 ++
     go.sum                        |   8 +++
     main.go                       |  28 ++++++++
     22 files changed, 358 insertions(+)

Pull-request: #1
  • Loading branch information
camh- committed Aug 7, 2024
2 parents cb2ef64 + 281f9c7 commit 905bccd
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci/cd

on:
push:
branches: [ master ]
pull_request:

jobs:
# CI is run on pull requests and pushes to master (i.e merging PRs)
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./bin/make ci

# Release is run only on pushes to master (i.e. merging PRs)
release:
runs-on: ubuntu-latest
needs: [ ci ]
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./bin/make release

# Send failure notification to slack if push to master job fails
howl-on-fail:
runs-on: ubuntu-latest
needs: [ ci, release ]
if: failure() && github.event_name == 'push'
steps:
- uses: foxygoat/howl@v1
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
SLACK_TEXT: <!here|here>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out/
38 changes: 38 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
issues:
exclude-use-default: false
exclude:
- "^don't use ALL_CAPS"
- "^ST1003: should not use ALL_CAPS"
- "^G304: Potential file inclusion via variable"

linters:
enable-all: true
disable:
- cyclop
- depguard
- execinquery
- exhaustive
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gochecknoglobals
- gocognit
- goconst
- gocyclo
- godox
- gomnd
- ireturn
- lll
- nlreturn
- nonamedreturns
- paralleltest
- revive
- rowserrcheck
- sqlclosecheck
- tagalign
- testpackage
- varnamelen
- wastedassign
- wrapcheck
- wsl
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 the foxygoat authors

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.
122 changes: 122 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Run `make help` to display help
.DEFAULT_GOAL := help

# --- Global -------------------------------------------------------------------
O = out
COVERAGE = 0
VERSION ?= $(shell git describe --tags --dirty --always)

## Build and lint
all: build lint
@if [ -e .git/rebase-merge ]; then git --no-pager log -1 --pretty='%h %s'; fi
@echo '$(COLOUR_GREEN)Success$(COLOUR_NORMAL)'

## Full clean build and up-to-date checks as run on CI
ci: clean check-uptodate all

check-uptodate: tidy
test -z "$$(git status --porcelain -- go.mod go.sum)" || { git status; false; }

## Remove generated files
clean::
-rm -rf $(O)

.PHONY: all check-uptodate ci clean

# --- Build --------------------------------------------------------------------
BIN_NAME = git-credential-fdoss
GO_TAGS =
GO_LDFLAGS = -X main.version=$(VERSION)
GO_FLAGS += $(if $(GO_TAGS),-tags='$(GO_TAGS)')
GO_FLAGS += $(if $(GO_LDFLAGS),-ldflags='$(GO_LDFLAGS)')
GO_BIN_SUFFIX = $(if $(GOOS),_$(GOOS))$(if $(GOARCH),_$(GOARCH))
GO_BIN_NAME = $(BIN_NAME)$(GO_BIN_SUFFIX)

## Build git-credential-fdoss binary
build: | $(O)
go build -o $(O)/$(GO_BIN_NAME) $(GO_FLAGS) .

## Tidy go modules with "go mod tidy"
tidy:
go mod tidy

.PHONY: build tidy

# --- Lint ---------------------------------------------------------------------
## Lint go source code
lint:
golangci-lint run

.PHONY: lint

# --- Release -------------------------------------------------------------------
RELEASE_DIR = $(O)/release

## Tag and release binaries for different OS on GitHub release
release: tag-release .WAIT build-release .WAIT publish-release

tag-release: nexttag
git tag $(RELEASE_TAG)
git push origin $(RELEASE_TAG)

build-release:
$(MAKE) build GOOS=linux GOARCH=amd64 O=$(RELEASE_DIR)
$(MAKE) build GOOS=linux GOARCH=arm64 O=$(RELEASE_DIR)
$(MAKE) build GOOS=linux GOARCH=arm O=$(RELEASE_DIR)
$(MAKE) build GOOS=linux GOARCH=386 O=$(RELEASE_DIR)

publish-release:
gh release create $(RELEASE_TAG) --generate-notes $(RELEASE_DIR)/*

nexttag:
$(if $(RELEASE_TAG),,$(eval RELEASE_TAG := $(shell $(NEXTTAG_CMD))))

.PHONY: build-release nexttag publish-release release tag-release

define NEXTTAG_CMD
{ git tag --list --merged HEAD --sort=-v:refname; echo v0.0.0; }
| grep -E "^v?[0-9]+.[0-9]+.[0-9]+$$"
| head -n1
| awk -F . '{ print $$1 "." $$2 "." $$3 + 1 }'
endef

# --- Utilities ----------------------------------------------------------------
COLOUR_NORMAL = $(shell tput sgr0 2>/dev/null)
COLOUR_RED = $(shell tput setaf 1 2>/dev/null)
COLOUR_GREEN = $(shell tput setaf 2 2>/dev/null)
COLOUR_WHITE = $(shell tput setaf 7 2>/dev/null)

help:
$(eval export HELP_AWK)
@awk "$${HELP_AWK}" $(MAKEFILE_LIST) | sort | column -s "$$(printf \\t)" -t

$(O):
@mkdir -p $@

.PHONY: help

# Awk script to extract and print target descriptions for `make help`.
define HELP_AWK
/^## / { desc = desc substr($$0, 3) }
/^[A-Za-z0-9%_-]+:/ && desc {
sub(/::?$$/, "", $$1)
printf "$(COLOUR_WHITE)%s$(COLOUR_NORMAL)\t%s\n", $$1, desc
desc = ""
}
endef

define nl


endef
ifndef ACTIVE_HERMIT
$(eval $(subst \n,$(nl),$(shell bin/hermit env -r | sed 's/^\(.*\)$$/export \1\\n/')))
endif

# Ensure make version is gnu make 4.4 or higher (for .WAIT target)
ifeq ($(filter shell-export,$(value .FEATURES)),)
$(error Unsupported Make version. \
$(nl)Use GNU Make 4.4 or higher (current: $(MAKE_VERSION)). \
$(nl)Activate 🐚 hermit with `. bin/activate-hermit` and run again \
$(nl)or use `bin/make`)
endif
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# git-credential-fdoss

`git-credential-fdoss` is a [git credential helper] that uses the
[freedesktop.org Secret Service] via [D-Bus] for storage of git credentials.

[git credential helper]: https://git-scm.com/doc/credential-helpers
[freedesktop.org Secret Service]: https://specifications.freedesktop.org/secret-service/
[D-Bus]: https://www.freedesktop.org/wiki/Software/dbus/

go install foxygo.at/git-credential-helper@latest

This credential helper fulfils the same role as `git-credential-libsecret` but
is intended to be easier to install and be more portable as a binary.
`git-credential-libsecret` is mostly distributed as source code as a
contribution to `git`. A binary build has dependencies on a number of GNOME
desktop libraries which may not be present on a target machine.
1 change: 1 addition & 0 deletions bin/.gh-2.54.0.pkg
1 change: 1 addition & 0 deletions bin/.go-1.22.5.pkg
1 change: 1 addition & 0 deletions bin/.golangci-lint-1.59.1.pkg
1 change: 1 addition & 0 deletions bin/.make-4.4.pkg
7 changes: 7 additions & 0 deletions bin/README.hermit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Hermit environment

This is a [Hermit](https://github.com/cashapp/hermit) bin directory.

The symlinks in this directory are managed by Hermit and will automatically
download and install Hermit itself as well as packages. These packages are
local to this environment.
21 changes: 21 additions & 0 deletions bin/activate-hermit
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# This file must be used with "source bin/activate-hermit" from bash or zsh.
# You cannot run it directly
#
# THIS FILE IS GENERATED; DO NOT MODIFY

if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi

BIN_DIR="$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")"
if "${BIN_DIR}/hermit" noop > /dev/null; then
eval "$("${BIN_DIR}/hermit" activate "${BIN_DIR}/..")"

if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ]; then
hash -r 2>/dev/null
fi

echo "Hermit environment $("${HERMIT_ENV}"/bin/hermit env HERMIT_ENV) activated"
fi
1 change: 1 addition & 0 deletions bin/gh
1 change: 1 addition & 0 deletions bin/go
1 change: 1 addition & 0 deletions bin/gofmt
1 change: 1 addition & 0 deletions bin/golangci-lint
43 changes: 43 additions & 0 deletions bin/hermit
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
#
# THIS FILE IS GENERATED; DO NOT MODIFY

set -eo pipefail

export HERMIT_USER_HOME=~

if [ -z "${HERMIT_STATE_DIR}" ]; then
case "$(uname -s)" in
Darwin)
export HERMIT_STATE_DIR="${HERMIT_USER_HOME}/Library/Caches/hermit"
;;
Linux)
export HERMIT_STATE_DIR="${XDG_CACHE_HOME:-${HERMIT_USER_HOME}/.cache}/hermit"
;;
esac
fi

export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://github.com/cashapp/hermit/releases/download/stable}"
HERMIT_CHANNEL="$(basename "${HERMIT_DIST_URL}")"
export HERMIT_CHANNEL
export HERMIT_EXE=${HERMIT_EXE:-${HERMIT_STATE_DIR}/pkg/hermit@${HERMIT_CHANNEL}/hermit}

if [ ! -x "${HERMIT_EXE}" ]; then
echo "Bootstrapping ${HERMIT_EXE} from ${HERMIT_DIST_URL}" 1>&2
INSTALL_SCRIPT="$(mktemp)"
# This value must match that of the install script
INSTALL_SCRIPT_SHA256="180e997dd837f839a3072a5e2f558619b6d12555cd5452d3ab19d87720704e38"
if [ "${INSTALL_SCRIPT_SHA256}" = "BYPASS" ]; then
curl -fsSL "${HERMIT_DIST_URL}/install.sh" -o "${INSTALL_SCRIPT}"
else
# Install script is versioned by its sha256sum value
curl -fsSL "${HERMIT_DIST_URL}/install-${INSTALL_SCRIPT_SHA256}.sh" -o "${INSTALL_SCRIPT}"
# Verify install script's sha256sum
openssl dgst -sha256 "${INSTALL_SCRIPT}" | \
awk -v EXPECTED="$INSTALL_SCRIPT_SHA256" \
'$2!=EXPECTED {print "Install script sha256 " $2 " does not match " EXPECTED; exit 1}'
fi
/bin/bash "${INSTALL_SCRIPT}" 1>&2
fi

exec "${HERMIT_EXE}" --level=fatal exec "$0" -- "$@"
1 change: 1 addition & 0 deletions bin/hermit.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manage-git = false
1 change: 1 addition & 0 deletions bin/make
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module foxygo.at/git-credential-fdoss

go 1.22.5

require github.com/alecthomas/kong v0.9.0
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// cmd git-credential-fdoss is a git credentials helper that uses the
// freedesktop.org secret service for storing and retrieving git credentials.
package main

import (
"github.com/alecthomas/kong"
)

var version string = "v0.0.0"

const description = `
git-credential-fdoss manages your git credentials using the freedesktop.org
Secret Service.
`

type CLI struct {
Version kong.VersionFlag `short:"V" help:"Print program version"`
}

func main() {
cli := &CLI{}
kctx := kong.Parse(cli,
kong.Description(description),
kong.Vars{"version": version},
)
err := kctx.Run(cli)
kctx.FatalIfErrorf(err)
}

0 comments on commit 905bccd

Please sign in to comment.