Travis CI failed to install Go - 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

Related

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

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.

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

How to make a linux executable file using gitlab (go env)?

I am trying to make a Linux executable file of my Go project. I have the following configuration in my .config-ci.yml in my gitlab project.
demo_job_1:
tags:
- cpf
- cpf-test
- testing
- unit-testing
script:
- go run test/main.go
- GOOS=linux GOARCH=amd64 go build
- go env
- cd test
- ./test
- echo Successfully run and Built
After running this pipeline, I still get the GOOS=windows when I check in env file. How can I build my project so that the output after building is of Linux executable file. Right now, I am getting .exe file which runs on Windows only.
You can see the project details in the following gitlab:
https://gitlab.com/smilekison/test
This is the error that is shown by Pipeline Job:
$ go run test/main.go
Hello world
$ GOOS=linux GOARCH=amd64 go build
GOOS=linux : The term 'GOOS=linux' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\WINDOWS\TEMP\build_script487326907\script.ps1:207 char:1
+ GOOS=linux GOARCH=amd64 go build
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (GOOS=linux:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
First to address your actual error: it seems you are on a windows based runner. That means you have to use windows CMD commands. It does not know ENV, etc.
You can do go env -w GOOS="linux" instead. Same with GOARCH. Then just run go build ..
You can also use a variables section to overwrite go env with environment variables:
variables:
GOOS: "linux"
GOARCH: "amd64"
It goes at the top of the gitlab file somewhere.
Here my typical build pipeline for Go projects using docker containers:
build_App:
image: golang:1.15.3
stage: build
allow_failure: false
tags:
- unix
script:
- go mod download
- mkdir $CI_PROJECT_DIR/release
- cd cmd/app
- GOOS=linux GOARCH=amd64 go build -o $CI_PROJECT_DIR/release/app .
artifacts:
paths:
- $CI_PROJECT_DIR/release
And test pipeline
go_test:
image: golang:1.15.3
stage: verify
allow_failure: false
tags:
- unix
script:
- go mod download
- go test -race -cover ./...
This is based on a runner that uses docker images to build in.
I needed to write go env -w GOOS="linux" GOARCH="amd64" to make the executable file for linux and if I want to make executable for windows I have to just rename linux to windows and I can make go language install by using image : golang:1.15.7 here. This way my .gitlab-ci.yml file can get GO Lang install and can run any go command.
demo_job_1:
stages:
-build
build:
stage: build
image : golang:1.15.7
tags:
- cpf
- cpf-test
- testing
- unit-testing
script:
- go run test/main.go
- go env -w GOOS=linux GOARCH=amd64
- go env
- cd test
- ./test
- echo Successfully run and Built

How can I fix the following Google Cloud Platform deployment error? [Error 2]

I'm trying to deploy my web-app to Google Cloud Platform, and I got an error while deploying. I understand that last package (go-sqlite3) needs gcc compiler, and Google Cloud WM has it:
$which gcc
/usr/bin/gcc
but it won't work
Step 3 : RUN go-wrapper install -tags appenginevm
---> Running in b0f03024342d
+ exec go install -v -tags appenginevm
github.com/mattn/go-colorable
github.com/mattn/go-isatty
github.com/labstack/gommon/color
github.com/valyala/fasttemplate/vendor/github.com/valyala/bytebufferpool
github.com/valyala/fasttemplate
github.com/labstack/gommon/log
golang.org/x/crypto/acme
golang.org/x/crypto/acme/autocert
github.com/labstack/echo
golang.org/x/net/context
github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
exec: "gcc": executable file not found in $PATH
The command '/bin/sh -c go-wrapper install -tags appenginevm' returned a non-zero code: 2
ERROR
ERROR: build step "gcr.io/cloud-builders/docker#sha256:926dc1a14e6f7eb5b3462b5c1d491aa6c73090291167ac2bf181c026b05f19da" failed: exit status 2
You have to make your path correct by following command on your shell.
PATH=/usr/bin:$PATH

Travis CI + Go: creating a specific build flow for different OS

I have a Go project that I want to build with Travis-CI and deploy it to a specific provider.
I familiar with Gimme project that will use a cross-compilation to do so.
But because Travis already support linux and osx I only need this feature for Windows build.
The big motivation is, of course, to avoid cross-compilation run time error as there are plenty of it.
My question is how can I create, in the same .travis.yml file, a different build flow:
Native linux/os build (with "os" section).
Windows compilation using Gimmme
The .travis.yml file for the first option will look something like:
language: go
go:
- 1.5.1
branches:
only:
- master
os:
- osx
- linux
before_script:
- go get -d -v ./...
script:
- go build -v ./...
# - go test -v ./...
before_deploy:
- chmod +x ./before_deploy.sh
- ./before_deploy.sh
The .travis.yml file for the second option will look something like:
language: go
go:
- 1.5.1
branches:
only:
- master
env:
- GIMME_OS=windows GIMME_ARCH=amd64
before_script:
- go get -d -v ./...
script:
- go build -v ./...
# - go test -v ./...
before_deploy:
- chmod +x ./before_deploy.sh
- ./before_deploy.sh
Is there a nice clean way to combine these two (with Environment variables or any other crazy idea)?
It might be simple, but matrix environement can not be done for a specific OS ...
Then just select with local environement variable:
language: go
go:
- 1.5.1
branches:
only:
- master
os:
- osx
- linux
install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
export GIMME_OS=windows;
export GIMME_ARCH=amd64;
fi
before_script:
- go get -d -v ./...
script:
- go build -v ./...
after_script:
- go test -v ./...
before_deploy:
- ./before_deploy.sh
An other way:
language: go
go:
- 1.5.1
branches:
only:
- master
matrix:
include:
- os: linux
env: GIMME_OS=windows; GIMME_ARCH=amd64;
- os: osx
before_script:
- go get -d -v ./...
script:
- go build -v ./...
after_script:
- go test -v ./...
before_deploy:
- ./before_deploy.sh
Note: the commande: - chmod +x ./before_deploy.sh can be directly done in your repository and commited on it ...
Note: The environament variable can be accessibe: http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables or calling \printenv`

Resources