From 11e48d9887e5ba0a351c32315704be88840734e5 Mon Sep 17 00:00:00 2001 From: Cam Hutchison Date: Sat, 28 Dec 2024 18:04:33 +1100 Subject: [PATCH] tools: Hermitise repo and pin versions required Hermitise this repository as the version of golangci-lint used is not compatible with more recent Go releases so we will either need to pin to an older version of Go or upgrade golangci-lint. The former is tricky to do simply, and the latter is painful with the churn in golangci-lint. The alternative is to use hermit and pin the versions currently required. This is what is done here: hermit init --no-git hermit install go-1.13.5 hermit install golangci-lint-1.37.0 Remove the custom version login for golangci-lint from the Makefile, and add the hermit auto-activation. Note that the only 1.13 version of Go in hermit is 1.13.5, while the latest point release is 1.13.15. I chose 1.13 as that is what is in the `go.mod` file. Subsequent commits will bump these versions and adjust the code to work with newer golangci-lint errors. Update GitHub CI to rely on hermit for installing the right versions instead of using specific actions. Also run on all PRs, not just those to be merged to master. This allows CI to run for stacked PRs. Add `/.hermit/` to `.gitignore` - this is hermit's "state" directory for certain hermit packages and should never be committed. --- .github/workflows/ci.yaml | 8 +------ .gitignore | 1 + Makefile | 22 ++++++++---------- bin/.go-1.13.5.pkg | 1 + bin/.golangci-lint-1.37.0.pkg | 1 + bin/README.hermit.md | 7 ++++++ bin/activate-hermit | 21 +++++++++++++++++ bin/go | 1 + bin/gofmt | 1 + bin/golangci-lint | 1 + bin/hermit | 43 +++++++++++++++++++++++++++++++++++ bin/hermit.hcl | 1 + 12 files changed, 89 insertions(+), 19 deletions(-) create mode 120000 bin/.go-1.13.5.pkg create mode 120000 bin/.golangci-lint-1.37.0.pkg create mode 100644 bin/README.hermit.md create mode 100755 bin/activate-hermit create mode 120000 bin/go create mode 120000 bin/gofmt create mode 120000 bin/golangci-lint create mode 100755 bin/hermit create mode 100644 bin/hermit.hcl diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2cc3051..e0a1ec5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,6 @@ on: push: branches: [ master ] pull_request: - branches: [ master ] jobs: test: @@ -15,9 +14,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: '^1.14' - run: make test - run: make cover lint: @@ -25,6 +21,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: golangci/golangci-lint-action@v2 - with: - version: v1.37.0 + - run: make lint diff --git a/.gitignore b/.gitignore index 6a3417b..2aa1e93 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/.hermit/ /out/ diff --git a/Makefile b/Makefile index 682b9ba..f635373 100644 --- a/Makefile +++ b/Makefile @@ -48,19 +48,9 @@ FAIL_COVERAGE = { echo '$(COLOUR_RED)FAIL - Coverage below $(COVERAGE)%$(COLOUR_ .PHONY: check-coverage cover test # --- Lint --------------------------------------------------------------------- -GOLINT_VERSION = 1.37.0 -GOLINT_INSTALLED_VERSION = $(or $(word 4,$(shell golangci-lint --version 2>/dev/null)),0.0.0) -GOLINT_USE_INSTALLED = $(filter $(GOLINT_INSTALLED_VERSION),v$(GOLINT_VERSION) $(GOLINT_VERSION)) -GOLINT = $(if $(GOLINT_USE_INSTALLED),golangci-lint,golangci-lint-v$(GOLINT_VERSION)) -GOBIN ?= $(firstword $(subst :, ,$(or $(GOPATH),$(HOME)/go)))/bin - -lint: $(if $(GOLINT_USE_INSTALLED),,$(GOBIN)/$(GOLINT)) ## Lint go source code - $(GOLINT) run - -$(GOBIN)/$(GOLINT): - GOBIN=/tmp go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLINT_VERSION) && \ - mv /tmp/golangci-lint $@ +lint: ## Lint go source code + golangci-lint run .PHONY: lint @@ -77,3 +67,11 @@ $(O): @mkdir -p $@ .PHONY: help + +define nl + + +endef +ifndef ACTIVE_HERMIT +$(eval $(subst \n,$(nl),$(shell bin/hermit env -r | sed 's/^\(.*\)$$/export \1\\n/'))) +endif diff --git a/bin/.go-1.13.5.pkg b/bin/.go-1.13.5.pkg new file mode 120000 index 0000000..383f451 --- /dev/null +++ b/bin/.go-1.13.5.pkg @@ -0,0 +1 @@ +hermit \ No newline at end of file diff --git a/bin/.golangci-lint-1.37.0.pkg b/bin/.golangci-lint-1.37.0.pkg new file mode 120000 index 0000000..383f451 --- /dev/null +++ b/bin/.golangci-lint-1.37.0.pkg @@ -0,0 +1 @@ +hermit \ No newline at end of file diff --git a/bin/README.hermit.md b/bin/README.hermit.md new file mode 100644 index 0000000..e889550 --- /dev/null +++ b/bin/README.hermit.md @@ -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. diff --git a/bin/activate-hermit b/bin/activate-hermit new file mode 100755 index 0000000..fe28214 --- /dev/null +++ b/bin/activate-hermit @@ -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 diff --git a/bin/go b/bin/go new file mode 120000 index 0000000..d3e6925 --- /dev/null +++ b/bin/go @@ -0,0 +1 @@ +.go-1.13.5.pkg \ No newline at end of file diff --git a/bin/gofmt b/bin/gofmt new file mode 120000 index 0000000..d3e6925 --- /dev/null +++ b/bin/gofmt @@ -0,0 +1 @@ +.go-1.13.5.pkg \ No newline at end of file diff --git a/bin/golangci-lint b/bin/golangci-lint new file mode 120000 index 0000000..cf27348 --- /dev/null +++ b/bin/golangci-lint @@ -0,0 +1 @@ +.golangci-lint-1.37.0.pkg \ No newline at end of file diff --git a/bin/hermit b/bin/hermit new file mode 100755 index 0000000..7fef769 --- /dev/null +++ b/bin/hermit @@ -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" -- "$@" diff --git a/bin/hermit.hcl b/bin/hermit.hcl new file mode 100644 index 0000000..29b6a5c --- /dev/null +++ b/bin/hermit.hcl @@ -0,0 +1 @@ +manage-git = false