golangci-lint: exec: "git": executable file not found in $PATH - go

I'm trying to integrate golangci-lint on my project. I use golangci-lint v1.49.0 that I install from snap. I've added ci config on my project but when I try to run it, it throws a very bizarre error.
$ golangci-lint run -v
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 7 linters: [errcheck gosimple govet ineffassign staticcheck typecheck unused]
INFO [loader] Go packages loading at mode 575 (files|name|types_sizes|deps|exports_file|compiled_files|imports) took 805.161254ms
ERRO Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: github.com/user/repo#v1.3.4: git init --bare in /home/user/snap/golangci-lint/94/go/pkg/mod/cache/vcs/88980456e822acee6ee17242ca10c17af0281944db0d695e6f13a17951f304ee: exec: "git": executable file not found in $PATH
go: github.com/user/repo#v1.3.4: git init --bare in /home/user/snap/golangci-lint/94/go/pkg/mod/cache/vcs/88980456e822acee6ee17242ca10c17af0281944db0d695e6f13a17951f304ee: exec: "git": executable file not found in $PATH
INFO Memory: 10 samples, avg is 27.8MB, max is 27.8MB
INFO Execution took 809.752753ms
github.com/user/repo isn't a real url, the one I use is private.
These are my config files
# .gitlab-ci.yml
stages:
- test
- build
- sast
- deploy
- cleanup
golangci-lint:
stage: test
image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine
script:
- golangci-lint run -v
# .golangci.yml
run:
tests: false
timeout: 10m
skip-dirs:
- "service/mocks"
output:
format: colored-line-number
Why is it unable to read git in $PATH? I've been using git for years using this machine, this is my first time I got an error like this. I also just reinstalled using sudo apt-get install git just to make sure, but it still throws the same error. It looks like Git has already been installed, but it keeps throwing that error.
My OS is Ubuntu v20.04
I've also added the git path by running export PATH=$PATH:/usr/bin/git, but it still keeps throwing the same error.

Related

Build kustomize 3.2.0 on Windows

Can someone suggest how to install 3.2.0 version of kustomize on Windows, please?
I need specifically v3.2.0 on Windows. I am following this tutorial.
Source code: https://github.com/kubernetes-sigs/kustomize/releases/tag/v3.2.0
I downloaded the zip file and installed Go. However when I run go install . inside that kustomize folder i get: no Go files in path/kustomize/..
Also tried step by step aforementioned tutorial but same error..
EDIT: Trying to install via https://github.com/kubernetes-sigs/kustomize/blob/master/hack/install_kustomize.sh ./install_kustomize.sh 3.2.0 I get: Version v3.2.0 does not exist.
When I try ./install_kustomize.sh 3.2.1 I get:
tar (child): ./kustomize_v*_windows_amd64.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Env: Windows 10, executing in GIT Bash
You'll need to run go install ./cmd/kustomize/.
That is where the main.go is you want built.
This will install the executable in your %GOBIN%.
You might want to use go build -o kustomize.exe ./cmd/kustomize/ instead to get the executable in your current working directory.

Golang linter issues 'context loading failed: no go files to analyze'

We are using
golangci-lint version 1.40.1 together with
golang version 1.16.4
in our project for linting our Golang code.
Until now, what we did is running this bash script (from the root
directory of our repository):
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go mod tidy
fi
golangci-lint run --build-tags="unit contract container"
With some recent updates of Golang and golangci-lint, we suddenly face this error message:
ERRO Running error: context loading failed: no go files to analyze
There is a lengthy post on GitHub regarding this issue but the only useful suggestion there is to turn off the GO111MODULE env variable. When I run the linter with GO111MODULE turned off like
GO111MODULE=off golangci-lint run --build-tags="unit contract container"
the upper error message disappears but instead I am getting lots of false linting errors like:
api/router.go:152:5: undeclared name: `PermissionUpdatePackage` (typecheck)
PermissionUpdatePackage,
^
My go environment looks like this:
GO111MODULE=on
GOPATH=/Users/USER/workspace/go
GOROOT=/usr/local/opt/go/libexec
GOPRIVATE=*.CUSTOMER.com
GOSS_PATH=/usr/local/bin/goss
I tried to install the linter via go get... as well as go install ... and finally brew install golangci-lint which seems to be the recommended way following this documentation.
Running a go get ./... in the root of the project eventually solved the issues. In between we ran the following commands that probably cleared some (module?) caches that might have caused trouble as well:
golangci-lint cache clean && go clean -modcache -cache -i
golangci-lint run -v --timeout=5s
The error message
ERRO Running error: context loading failed: failed to load packages: timed out to load packages: context deadline exceeded
in the latter command pointed us to this GitHub post that made me try out go get ./...
For installing the linter (with a specified version), we ended up with this script:
linter_version='1.40.1'
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Fetching linter..."
# we cannot install linter in the project directory, otherwise we get dependency errors
# hence, temporarily jump into the /tmp directory
pushd /tmp > /dev/null
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint#v"${linter_version}" 2>&1
popd >/dev/null
fi

Travis CI failed to install Go

I am using Travis CI, on commit is it is not building the module as expected and giving the following error:
0.52s$ git clone --depth=50 --branch=master https://github.com/kadnan/gkeevee.git kadnan/gkeevee
$ travis_export_go 1.14 github.com/kadnan/gkeevee
0.01s
Setting environment variables from .travis.yml
$ export GO111MODULE=on
$ export GOFLAGS='-mod vendor'
150.68s$ travis_setup_go
I don't have any idea what to do with '1.14'.
(using download type 'auto')
Failed to run gimme
The command "travis_setup_go" failed and exited with 86 during .
Below is my travis.yml:
language: go
env: GO111MODULE=on GOFLAGS='-mod vendor'
go:
1.14
install: true
notifications:
email: false
script:
- go test -v

GitLab CI - Cache not working

I'm currently using GitLab in combination with CI runners to run unit tests of my project, to speed up the process of bootstrapping the tests I'm using the built-in cache functionality, however this doesn't seem to work.
Each time someone commits to master, my runner does a git fetch and proceeds to remove all cached files, which means I have to stare at my screen for around 10 minutes to wait for a test to complete while the runner re-downloads all dependencies (NPM and PIP being the biggest time killers).
Output of the CI runner:
Fetching changes...
Removing bower_modules/jquery/ --+-- Shouldn't happen!
Removing bower_modules/tether/ |
Removing node_modules/ |
Removing vendor/ --'
HEAD is now at 7c513dd Update .gitlab-ci.yml
Currently my .gitlab-ci.yml
image: python:latest
services:
- redis:latest
- node:latest
cache:
key: "$CI_BUILD_REF_NAME"
untracked: true
paths:
- ~/.cache/pip/
- vendor/
- node_modules/
- bower_components/
before_script:
- python -V
# Still gets executed even though node is listed as a service??
- '(which nodejs && which npm) || (apt-get update -q && apt-get -o dir::cache::archives="vendor/apt/" install nodejs npm -yqq)'
- npm install -g bower gulp
# Following statements ignore cache!
- pip install -r requirements.txt
- npm install --only=dev
- bower install --allow-root
- gulp build
test:
variables:
DEBUG: "1"
script:
- python -m unittest myproject
I've tried reading the following articles for help however none of them seem to fix my problem:
http://docs.gitlab.com/ce/ci/yaml/README.html#cache
https://fleschenberg.net/gitlab-pip-cache/
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/336
Turns out that I was doing some things wrong:
Your script can't cache files outside of your project scope, creating a virtual environment instead and caching that allows you to cache your pip modules.
Most important of all: Your test must succeed in order for it to cache the files.
After using the following config I got a -3 minute time difference:
Currently my configuration looks like follows and works for me.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python
image: python:latest
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
services:
- mysql:latest
- redis:latest
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- venv/
- node_modules/
- bower_components/
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
# Check python installation
- python -V
# Install NodeJS (Gulp & Bower)
# Default repository is outdated, this is the latest version
- 'curl -sL https://deb.nodesource.com/setup_8.x | bash -'
- apt-get install -y nodejs
- npm install -g bower gulp
# Install dependencie
- pip install -U pip setuptools
- pip install virtualenv
test:
# Indicate to the framework that it's being unit tested
variables:
DEBUG: "1"
# Test script
script:
# Set up virtual environment
- virtualenv venv -ppython3
- source venv/bin/activate
- pip install coverage
- pip install -r requirements.txt
# Install NodeJS & Bower + Compile JS
- npm install --only=dev
- bower install --allow-root
- gulp build
# Run all unit tests
- coverage run -m unittest project.tests
- coverage report -m project/**/*.py
Which resulted in the following output:
Fetching changes...
Removing .coverage --+-- Don't worry about this
Removing bower_components/ |
Removing node_modules/ |
Removing venv/ --`
HEAD is now at 24e7618 Fix for issue #16
From https://git.example.com/repo
85f2f9b..42ba753 master -> origin/master
Checking out 42ba7537 as master...
Skipping Git submodules setup
Checking cache for master... --+-- The files are back now :)
Successfully extracted cache --`
...
project/module/script.py 157 9 94% 182, 231-244
---------------------------------------------------------------------------
TOTAL 1084 328 70%
Creating cache master...
Created cache
Uploading artifacts...
venv/: found 9859 matching files
node_modules/: found 7070 matching files
bower_components/: found 982 matching files
Trying to load /builds/repo.tmp/CI_SERVER_TLS_CA_FILE ...
Dialing: tcp git.example.com:443 ...
Uploading artifacts to coordinator... ok id=127 responseStatus=201 Created token=XXXXXX
Job succeeded
For the coverage report, I used the following regular expression:
^TOTAL\s+(?:\d+\s+){2}(\d{1,3}%)$

Composer installs only globally (Windows 10)

When I try to install Composer (exe installer, curl, tried all methods), it installs only in C:\ProgramData\ComposerSetup\bin and never localy, even if I run it (obviously) from another directory.
When I run composer init - it does not create json config anywhere, composer install - is installing only in C:/Users/Username/AppData/Roaming/Composer/
D:\test>composer init
←[37;44m ←[39;49m
←[37;44m Welcome to the Composer config generator ←[39;49m
←[37;44m ←[39;49m
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [←[33mUsername/test←[39m]: test/test
Description []:
Author []: test <test#test.test>
Minimum Stability []:
Package Type []:
License []:
Define your dependencies.
Would you like to define your dependencies (require) interactively [←[33myes←[39m]?
Search for a package:
Would you like to define your dev dependencies (require-dev) interactively [←[33myes←[39m]?
Search for a package:
{
"name": "test/test",
"authors": [
{
"name": "test",
"email": "test#test.test"
}
],
"require": {}
}
D:\test>dir
29.08.2015 12:39 <DIR> .
29.08.2015 12:39 <DIR> ..
0 files
D:\test>composer require slim/slim -vvv
Reading ./composer.json
Loading config file ./composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Reading C:/Users/Username/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/Username/AppData/Roaming/Composer/composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Downloading https://packagist.org/packages.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/packages.json into cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2013.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014-10.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-01.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-04.json from cache Downloading http://packagist.org/p/provider-2015-07$bf4d7ab35da85686431ee3c47d0d6d2eee3d913013b38506fbc197c5e95c2420.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-07.json into cache Downloading http://packagist.org/p/provider-latest$ee6937b535cc76629a8e81c4362790bd14ce6a824def5d75f7222438e756a7b0.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-latest.json into cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/provider-slim$slim.json from cache Using version ←[32m^2.6←[39m for ←[32mslim/slim←[39m
←[32m./composer.json has been updated←[39m
Reading ./composer.json
Loading config file ./composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
Reading C:/Users/Username/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/Username/AppData/Roaming/Composer/composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Executing command (CWD): hg branch
Executing command (CWD): svn info --xml
←[32mLoading composer repositories with package information←[39m
Downloading https://packagist.org/packages.json
Writing C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/packages.json into cache
←[32mUpdating dependencies (including require-dev)←[39m
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2013.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2014-10.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-01.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-04.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-2015-07.json from cache Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/p-provider-latest.json from cache
Reading C:/Users/Username/AppData/Local/Composer/repo/https---packagist.org/provider-slim$slim.json from cache Analyzed 63 packages to resolve dependencies
Analyzed 45 rules to resolve dependencies
- Installing ←[32mslim/slim←[39m (←[33m2.6.2←[39m)
Reading C:/Users/Username/AppData/Local/Composer/files/slim/slim/20a02782f76830b67ae56a5c08eb1f563c351a37.zip from cache
Loading from cache
Extracting archive
REASON: Required by root: Install command rule (install slim/slim 2.6.0|install slim/slim 2.6.1|install slim/slim 2.6.2)
←[32mWriting lock file←[39m
←[32mGenerating autoload files←[39m
Any ideas how to fix it?
Before applying all steps, try step 5 with your current setup.
Installation Steps
Manually download: https://getcomposer.org/composer.phar
place composer.phar into your PHP folder, next to php.exe
add a batch file composer.bat in the same folder (to execute composer a bit easier), with the following content:
#echo off
:: Composer CLI Shortcut (Global Installation)
"%~dp0php.exe" "%~dp0composer.phar" %*
pause
add the PHP folder to your ENV path, so that php and composer are available on any path
then create your new project
mkdir slim
cd slim
composer require slim/slim 2.6.2 -vvv (this time with version)

Resources