From c278e6b4985f126e1dab6f8d94cf89729547e5ef Mon Sep 17 00:00:00 2001 From: joe miller Date: Wed, 20 Nov 2024 17:36:13 +0000 Subject: [PATCH] fix tests after main branch rename; drop common make some tests were failing after renaming master branch to main. fixed. makefile: drop common-make includes; simplify make tasks gha: bump GHA actions versions and configure dependabot to automate updates --- .github/dependabot.yml | 5 + .github/workflows/CI.yml | 51 ++++------- .gitignore | 1 + Makefile | 25 +++-- autotag_test.go | 9 +- scripts/install-libgit2.sh | 24 ----- scripts/make/common-go.mk | 166 ---------------------------------- scripts/make/common.mk | 12 --- scripts/make/sh/install-go.sh | 79 ---------------- scripts/mkbins.sh | 16 ---- scripts/static-git2go.sh | 13 --- 11 files changed, 46 insertions(+), 355 deletions(-) delete mode 100644 scripts/install-libgit2.sh delete mode 100644 scripts/make/common-go.mk delete mode 100644 scripts/make/common.mk delete mode 100644 scripts/make/sh/install-go.sh delete mode 100644 scripts/mkbins.sh delete mode 100755 scripts/static-git2go.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 36b24f2..80404e8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,8 @@ updates: directory: / schedule: interval: daily + + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d2dc512..47b67b7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,35 +1,33 @@ name: CI + on: push: branches: - - 'main' + - main pull_request: + types: + - opened + - reopened + - synchronize jobs: - test: + lint: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/checkout@v4 - - name: Restore Go Modules Cache - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 - - name: Environment Config - run: | - echo "$HOME/go/bin" >> $GITHUB_PATH + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 - - name: Download Dependencies - run: | - go mod download + - name: Set up Go + uses: actions/setup-go@v5 - name: Git Config for Unit Tests run: | @@ -38,25 +36,16 @@ jobs: - name: Run Unit Tests run: | - make test-gha - - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Run Linter - uses: golangci/golangci-lint-action@v2 + make test goreleaser-check: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Check goreleaser's Configuration - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: version: latest args: check diff --git a/.gitignore b/.gitignore index 1c79715..eb7dae6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist/ Attic .vscode/ /.idea/ +cover.out diff --git a/Makefile b/Makefile index 120927f..e21bd54 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,22 @@ APP := autotag -include scripts/make/common.mk -include scripts/make/common-go.mk +.PHONY: lint build test cov run -build:: - CGO_ENABLED=0 go build -o $(APP)/$(APP) $(APP)/*.go +default: build -snapshot: - @goreleaser --rm-dist --snapshot --debug +build: + CGO_ENABLED=0 go build -trimpath -v -o $(APP)/$(APP) $(APP)/*.go + +lint: + golangci-lint run -v ./... + +test: + go test -cover -coverprofile=cover.out -v ./... -.PHONY:: test-gha -test-gha:: test-go ## for running unit tests on GitHub Actions +cov: + @echo "--- Coverage:" + go tool cover -html=cover.out + go tool cover -func cover.out + +snapshot: + @goreleaser --rm-dist --snapshot --debug \ No newline at end of file diff --git a/autotag_test.go b/autotag_test.go index 5fd540a..a2e64c8 100644 --- a/autotag_test.go +++ b/autotag_test.go @@ -62,7 +62,7 @@ func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo { branch := setup.branch if branch == "" { - branch = "master" + branch = "main" } tag := setup.initialTag @@ -99,7 +99,6 @@ func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo { Scheme: setup.scheme, Prefix: !setup.disablePrefix, }) - if err != nil { t.Fatal("Error creating repo: ", err) } @@ -179,7 +178,7 @@ func TestValidateConfig(t *testing.T) { } func TestNewRepo(t *testing.T) { - var newRepoTests = []struct { + newRepoTests := []struct { createBranch string requestBranch string expectBranch string @@ -203,7 +202,6 @@ func TestNewRepo(t *testing.T) { Branch: tt.requestBranch, RepoPath: repo.Path(), }) - if err != nil { t.Fatal("Error creating repo: ", err) } @@ -243,7 +241,7 @@ func TestNewRepoMainAndMaster(t *testing.T) { makeTag(repo, "v0.2.1") // check results - var newRepoTests = []struct { + newRepoTests := []struct { requestBranch string expectBranch string }{ @@ -257,7 +255,6 @@ func TestNewRepoMainAndMaster(t *testing.T) { Branch: tt.requestBranch, RepoPath: repo.Path(), }) - if err != nil { t.Fatal("Error creating repo: ", err) } diff --git a/scripts/install-libgit2.sh b/scripts/install-libgit2.sh deleted file mode 100644 index 4fe6141..0000000 --- a/scripts/install-libgit2.sh +++ /dev/null @@ -1,24 +0,0 @@ -set -e - -version="0.23.2" -dirname="libgit2-$version" -basedir=$(pwd) - - -sudo apt-get install -y libssh2-1-dev openssl pkg-config -if [ -d ~/libgit2 ] ; then - echo "libgit2 already setup" - exit 0 -fi - - -sudo apt-get update -sudo apt-get install -y curl build-essential python cmake - -curl -L "https://github.com/libgit2/libgit2/archive/v${version}.tar.gz" -o ~/${dirname}.tar.gz -tar -xzvf ~/${dirname}.tar.gz -C ~/ - -cd ~/${dirname} -mkdir build && cd build -cmake .. -DCMAKE_INSTALL_PREFIX=~/libgit2 -cmake --build . --target install diff --git a/scripts/make/common-go.mk b/scripts/make/common-go.mk deleted file mode 100644 index 658524a..0000000 --- a/scripts/make/common-go.mk +++ /dev/null @@ -1,166 +0,0 @@ -# Common Go Tasks -# -# INPUT VARIABLES -# - GOTEST_ARGS: Override the options passed by default ot go test (--race by default) -# -# - FETCH_CA_CERT: The presence of this variable will cause the root CA certs -# to be downloaded to the file ca-certificates.crt before building. -# This can then be copied into the docker container. -# -#------------------------------------------------------------------------------- - -## Append tasks to the global tasks -deps:: deps-go -deps-circle:: deps-circle-go deps -lint:: lint-go -test:: lint-go test-go -test-circle:: test test-coveralls -test-coverage:: test-coverage-go - -ifndef GOTEST_ARGS - GOTEST_ARGS := "--race" -endif - -## dependency manager detection -ifneq (,$(wildcard go.mod)) # if there IS go.mod - USE_MODULE = 1 - GO111MODULE=on - export GO11MODULE - GOLANGCI_VERSION := v1.24.0 -else ifneq (,$(wildcard Gopkg.toml)) # if ther IS Gopkg.toml - USE_DEP = 1 -else - USE_GVT = 1 -endif - -DEBUG ?= false -CGO_ENABLED ?= 0 -GO_FLAGS ?= -ldflags="-s -w" -ifneq (false,$(DEBUG)) - GO_FLAGS := -gcflags=all='-N -l' -endif - -## go tasks -deps-go:: _go-install-dep-tools deps-lint ## install dependencies for project assumes you have go binary installed -ifneq (,$(wildcard vendor)) - @find ./vendor/* -maxdepth 0 -type d -exec rm -rf "{}" \; || true -endif - -ifdef USE_MODULE - $(call INFO, "restoring dependencies using modules via \'go get\'") - @GO111MODULE=on go get -endif - -ifdef USE_GVT - $(call INFO, "restoring dependencies with \'gvt\'") - @gvt rebuild > /dev/null -endif - -ifdef USE_DEP - $(call INFO, "ensuring dependencies with \'dep\'") - ifdef CIRCLECI - @cd $$(readlink -f "$$(pwd)") && dep ensure > /dev/null - else - @dep ensure > /dev/null - endif -endif - -lint-go:: deps-lint - ifdef USE_MODULE - $(call INFO, "scanning source with golangci-lint") - golangci-lint run -E goimports -v - else - $(call INFO, "scanning source with gometalinter") -# for now we disable gotype because its vendor suport is mostly broken -# https://github.com/alecthomas/gometalinter/issues/91 - gometalinter.v2 --vendor --enable-gc -Dstaticcheck -Dgotype -Ddupl -Dgocyclo -Dinterfacer -Daligncheck -Dunconvert -Dvarcheck -Dstructcheck -E vet -E golint -E gofmt -E unused --deadline=80s - gometalinter.v2 --vendor --enable-gc --disable-all -E staticcheck --deadline=60s - gometalinter.v2 --vendor --enable-gc --disable-all -E interfacer --deadline=30s - gometalinter.v2 --vendor --enable-gc --disable-all -E unconvert -E varcheck --deadline=30s - gometalinter.v2 --vendor --enable-gc --disable-all -E structcheck --deadline=30s - endif - -GO_TEST_CMD := go test $(GOTEST_ARGS) $$(go list ./... | grep -v /vendor/) -ifneq (,$(findstring -race, $(GOTEST_ARGS))) - GO_TEST_CMD := CGO_ENABLED=1 $(GO_TEST_CMD) -endif -test-go:: ## run go tests (fmt vet) - $(call INFO, "running tests with $(GOTEST_ARGS)") - @$(GO_TEST_CMD) - -test-no-race:: lint ## run tests without race detector - $(call WARN, "DEPRECATED: set GOTEST_ARGS and run make test-go to change how go-test runs from common-go. Running tests without race detection.") - go test $$(go list ./... | grep -v /vendor/) - - -deps-circle-go:: ## install Go build and test dependencies on Circle-CI - $(call INFO, "installing the go binary @$(GOVERSION)") - @bash devops/make/sh/install-go.sh - -deps-lint:: -ifdef USE_MODULE - ifeq (, $(shell which golangci-lint)) - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_VERSION) - else - $(call INFO, "golangci already installed") - endif -else - ifeq (, $(shell which gometalinter.v2)) - $(call INFO, "installing gometalinter") - @go get -u gopkg.in/alecthomas/gometalinter.v2 > /dev/null - @gometalinter.v2 --install > /dev/null - else - $(call INFO, "gometalinter already installed") - endif -endif - -deps-coverage:: -ifeq (, $(shell which gotestcover)) - $(call INFO, "installing gotestcover") - @GO111MODULE=off go get github.com/pierrre/gotestcover -endif - -deps-status:: ## check status of deps with gostatus -ifeq (, $(shell which gostatus)) - $(call INFO, "installing gostatus") - @GO111MODULE=off go get -u github.com/shurcooL/gostatus > /dev/null -endif - @go list -f '{{join .Deps "\n"}}' . | gostatus -stdin -v - -test-coverage-go:: deps-coverage ## run coverage report - $(call INFO, "running gotestcover") - @gotestcover -v -coverprofile=coverage.out $$(go list ./... | grep -v /vendor/) > /dev/null - -test-coverage-html:: test-coverage ## output html coverage file - $(call INFO, "generating html coverage report") - @go tool cover -html=coverage.out > /dev/null - -# this will detect if the project is dep or not and use it if it is. If not install gvt -# if no manifest then its probably dep -ifdef USE_GVT - _go-install-dep-tools: _go-install-gvt -endif -ifdef USE_DEP - _go-install-dep-tools: _go-install-dep -endif - -_go-install-gvt:: -ifeq (, $(shell which gvt)) - $(call INFO, "installing 'gvt' go dependency tool") - @go get -u github.com/FiloSottile/gvt > /dev/null -endif - -_go-install-dep:: -ifeq (, $(shell which dep)) - $(call INFO, "installing 'dep' go dependency tool") - @go get -u github.com/golang/dep/... > /dev/null -endif - - -_fetch-cert:: -ifdef FETCH_CA_CERT - $(call INFO, "fetching CA certs from haxx.se") - @curl -s -L https://curl.haxx.se/ca/cacert.pem -o ca-certificates.crt > /dev/null -endif - -.PHONY:: _fetch-cert _gvt-install test-coverage-html deps-status deps-coverage deps-circle deps-go test-circle test-go build-circle build-linux build-go _go-install-dep-tools diff --git a/scripts/make/common.mk b/scripts/make/common.mk deleted file mode 100644 index 2056ae2..0000000 --- a/scripts/make/common.mk +++ /dev/null @@ -1,12 +0,0 @@ -# common make tasks and variables that should be imported into all projects -# -#------------------------------------------------------------------------------- -help: ## print list of tasks and descriptions - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?##"}; { split($$0,a,":"); printf "\033[36m%-30s\033[0m %s \n", a[2], $$2}' -.DEFAULT_GOAL := help - -readme-toc: ## update the Table of Contents in ./README.md (replaces tag) - docker run --rm -v `pwd`:/src quay.io/getpantheon/markdown-toc -i /src/README.md - - -.PHONY:: all help update-makefiles diff --git a/scripts/make/sh/install-go.sh b/scripts/make/sh/install-go.sh deleted file mode 100644 index b1a028b..0000000 --- a/scripts/make/sh/install-go.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -# -# Use this script to help override circle-ci's go inference. -# -# Set env var GOVERSION to the version of go you'd like installed. Then call this script in the -# dependencies/override build phase. Your Go version will be installed to /home/ubuntu/go in the -# container, and your project's source code will be rsync'd into the $GOPATH so that local import -# paths will resolve correctly. -# -# Add `../go` path to your dependencies/cache_directories setting in circle.yml for -# faster builds. -# -# Example circle.yml: -# -# --- -# machine: -# environment: -# GOVERSION: 1.6.1 -# GOPATH: /home/ubuntu/go_workspace -# GOROOT: /home/ubuntu/go -# PATH: /home/ubuntu/go/bin:$GOPATH/bin:$PATH -# -# dependencies: -# cache_directories: -# - ../go_workspace -# - ../go -# -# overide: -# - bash scripts/install-go.sh -# - -set -ex - -if [ "$CIRCLECI" != "true" ]; then - echo "This script meant to only be run on CIRCLECI" - exit 1 -fi - -if [ -z "$GOVERSION" ] ; then - echo "set GOVERSION environment var" - exit 1 -fi - - -function fu_circle { - # convert CIRCLE_REPOSITORY_URL=https://github.com/user/repo -> github.com/user/repo - local IMPORT_PATH - IMPORT_PATH=$(sed -e 's#https://##' <<< "$CIRCLE_REPOSITORY_URL") - sudo rm -rf /usr/local/go - sudo rm -rf /home/ubuntu/.go_workspace || true - sudo ln -s "$HOME/go" /usr/local/go - # remove the destination dir if it exists - if [ -d "$GOPATH/src/$IMPORT_PATH" ] ; then - rm -rf "$GOPATH/src/$IMPORT_PATH" - fi - - # move our new stuf into the destination - pd=$(pwd) - cd ../ - - basedir=$(dirname "$GOPATH/src/$IMPORT_PATH") - if [ ! -d "$basedir" ] ; then - mkdir -p "$basedir" - fi - mv "$pd" "$GOPATH/src/$IMPORT_PATH" - ln -s "$GOPATH/src/$IMPORT_PATH" "$pd" -} - -if "$HOME/go/bin/go" version | grep -q " go$GOVERSION "; then - echo "go $GOVERSION installed preping go import path" - fu_circle - exit 0 -fi - -gotar=go${GOVERSION}.tar.gz -curl -o "$HOME/$gotar" "https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz" -tar -C "$HOME/" -xzf "$HOME/$gotar" - -fu_circle diff --git a/scripts/mkbins.sh b/scripts/mkbins.sh deleted file mode 100644 index 19d000c..0000000 --- a/scripts/mkbins.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -xe - -if [ ! -d ~/bin ] ; then - mkdir -p ~/bin -fi - -if [ ! -f ~/bin/gh-release ] ; then - # when https://github.com/progrium/gh-release/pull/13 is merged we can go back - # to upstream on this for now I am using my build from that pr -jesse - # curl -L https://github.com/progrium/gh-release/releases/download/v2.2.0/gh-release_2.2.0_linux_x86_64.tgz | tar -xzv - # mv gh-release ~/bin/gh-release - curl -L https://www.dropbox.com/s/4k3eq7xpehwwqr5/gh-release?dl=0 -o ~/bin/gh-release - chmod 755 ~/bin/gh-release -fi diff --git a/scripts/static-git2go.sh b/scripts/static-git2go.sh deleted file mode 100755 index b8a39ef..0000000 --- a/scripts/static-git2go.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -ex - -g2g_path="$GOPATH/src/github.com/libgit2/git2go" -if [ -n "$CIRCLECI" ] ; then - g2g_path="/home/ubuntu/.go_workspace/src/github.com/libgit2/git2go" -fi - -cd $g2g_path -git checkout next -git submodule update --init -make install