How to create github release using TravisCI from multiple build matrixes? - go

I have setup a simple go repository and configured TravisCI in the following way
language: go
go:
- 1.8.x
- master
gobuild_args: -ldflags "-X main.Version=${TRAVIS_TAG} -X main.buildTime=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.commitId=${TRAVIS_COMMIT}"
env:
- GOOS=linux GOARCH=amd64
- GOOS=windows GOARCH=amd64
after_success:
- ./build.sh
matrix:
allow_failures:
- go: master
This will essentially create 4 different builds in TravisCI. This is great for building a cross compilation project where I can build windows and linux binaries separately.
What I have been struggling to do is to create 1 single release in Github from all the binaries generated across those builds?
TravisCI documentation says they support releases but it is very vague on how to handle such a scenario.
Don't all the the build run on different virtual servers? If so how do I specify the file in each
If I setup a release will it run for each build? How does work with github, will it fail because the release will be attempted to be created several times?
Has anybody attempted this?

Related

How can I get my github action to compile my rust program for Mac on Ubuntu

Attempting to compile a rust program for usage on Mac. Configured Github Action as follows:
build_macos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Install required tools
run: sudo apt install libdbus-1-dev pkg-config libudev-dev libglfw3-dev libglew-dev
- name: Install required target
run: rustup target add aarch64-apple-darwin
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Build Release
run: cargo build --verbose --release --target=aarch64-apple-darwin
- name: Artifact MacOS
uses: actions/upload-artifact#v3
with:
name: Build MacOS
path: ./target/aarch64-apple-darwin/release/control_harts
retention-days: 5
which fails on Build Release Image
Investigating the log further points me to the following (full log):
= note: cc: error: unrecognized command-line option '-arch'
cc: error: unrecognized command-line option '-framework'
cc: error: unrecognized command-line option '-framework'
What would be the best way to solve this? If any further information is required, please let me know.
P.S. the program uses quite some libraries, but it does not appear to fail when compiling those, but only on the project itself. This makes me believe it maybe a configuration error on my end, but I cannot seem to figure that out.
P.P.S. the windows and linux tasks pass and produce a functioning executable, with all tests passing.
P.P.P.S. If it is preferable that I make a minimal piece of code or a repo that runs into this issue I could, but I am hoping the issue is just a simple oversight.
I was expecting a MacOS executable to pop out like the files for windows and linux do, but unfortunately the task runs into this error.
I tried looking for existing solutions for this problem, and I found:
(1, 2, 3 found after searching for the first line (-arch), 4 and 5 for the second line (-framework))
1. -> I cannot seem to configure these flags myself, as (from my very limited understanding) they are either part of the packages' build scripts or generated by rustc.
2. -> Unsolved github issue
3. -> Potentially solved github issue but it seems this is just part of the build script of that lib
4. -> Requires access to the MakeFile, which I may have but I cannot seem to figure out where it is.
5. -> for GoLang, and also without solution.
I was building with runs-on: ubuntu-latest as Azeem pointed out. After changing this to runs-on: macos-latest and removing the Install required tools task, it ran smoothly and created the distr as I wanted.
I cannot test this because I do not have a Mac, but the test cases pass so it seems ok.

How do you read debug VCS version info from a Go 1.18 binary?

I'm trying to read version control information from my Go binaries, but the build info doesn't seem to contain any VCS info.
From the Go 1.18 release notes:
The go command now embeds version control information in binaries. It includes the currently checked-out revision, commit time, and a flag indicating whether edited or untracked files are present. Version control information is embedded if the go command is invoked in a directory within a Git, Mercurial, Fossil, or Bazaar repository, and the main package and its containing main module are in the same repository. This information may be omitted using the flag -buildvcs=false.
Sample program:
package main
import (
"fmt"
"runtime/debug"
)
func main() {
if bi, ok := debug.ReadBuildInfo(); ok {
fmt.Printf("%+v\n", bi)
}
}
Using this code, here's my output:
go go1.18
path [redacted]
mod [redacted] (devel)
dep [redacted] v1.2.3
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=amd64
build GOOS=windows
build GOAMD64=v1
I expected to see this included, but didn't:
build vcs=git
build vcs.revision=[sha]
build vcs.time=2022-03-28T03:11:12Z
build vcs.modified=true
I'm running the go command from the root directory of a git repo, and the repo has commits. The program I'm building is in a subdirectory of the repo.
I have tried a number of different variations for building the binary, but none of them worked:
go run client/main.go
go build -o client.exe client/main.go && ./client.exe
go build -o client.exe client/main.go && ./client.exe
go build -o client.exe -buildvcs=true client/main.go && ./client.exe
To be clear, the program builds and executes, but doesn't contain embedded VCS information.
I also tried using go version -m client.exe to see if that could read something that the binary couldn't read about itself, but the results were the same.
I'm using the first release of Go 1.18, so -buildvcs should still default to true as far as I know. I saw on the issue tracker that a future minor release will likely change the default to -buildvcs=auto.
As far as I can tell, both conditions listed in the release notes (go is invoked in a directory inside a git repo, and the main package is in the same repo) should both be satisfied when building from the project root. What might I be doing wrong?
I believe my issue was due to incorrect usage of the go run and go build commands. I was running and building against file patterns because I had originally tried go build client from the project root and gotten an error of "package is not in GOROOT", so I was building file patterns instead without understanding the difference (because it compiled and ran successfully).
I found that if I change directories into the subdirectory with the program I want to build (rather than build from the project root) the build command will embed the version information as expected.
e.g.:
cd client/ && go build
As #JimB pointed out in the comments, the go command is meant to operate on packages.
When building from the project root, this is the command I should have been using that will properly embed VCS version info inside the binary:
go build ./client
This behavior around relative path names is still confusing behavior to me, since I had expected go build client and go build ./client to be equivalent (which they are apparently not). Behavior around relative paths seems to be documented here: https://pkg.go.dev/cmd/go#go1.18#hdr-Relative_import_paths

Building a Go project: go mod download vs go build

I'm new to go and am trying to figure out how to execute the build step in my circleci project.
I noticed in the CircleCI Go orb, that there was no use of go build, which was confusing to me because in the CircleCI Go Language Guide, they specifically use go build via a makefile.
So I am not sure if using the Go orb alone is sufficient (though that seems odd to me). I vaguely understand what go mod download does, and what go build does, but I've seen examples where they are used together:
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
Currently, according to the go orb usage doc, I have:
build:
executor: go
steps:
- checkout
- go/load-cache:
key: go-mod-v1-{{ checksum "go.sum" }}
- go/mod-download
- go/save-cache:
key: go-mod-v1-{{ checksum "go.sum" }}
- slack/notify:
event: fail
template: basic_fail_1
What am I missing or unintentionally including by using go mod download instead of go build or go build with go mod download?
go mod download downloads source code for all dependency modules, and verifies checksums for newly-downloaded modules. (Note that in Go 1.18 we plan to change the behavior of go mod download so that it can instead download only the modules needed to build packages and tests in in main module.)
go build builds packages. It automatically downloads (and verifies) module source code as needed to build those packages. In many cases, that is a much smaller set of modules than what is downloaded by go mod download.
Documentation of go mod download details that all dependencies will be downloaded as no argument is provided.
With no arguments, download applies to all dependencies of the main
module.
The lines in the question seem to be a subset of the complete instructions of the CI job. The example from Circle CI documentation suggests a build step which is mandatory to get an executable.
Any build command allows to choose the behavior regarding dependencies. As suggested, having a separate go mod download depends on the constraints of the environment.

How to manage building golang projects on travis-ci

I'm developing Golang project and using TravisCI. As dependency tool, Godeps is used.
After running test by git push, something error was happened as below.
# command-line-arguments
cmd/proj/main_test.go:6:2: cannot find package
"command-line-/vendor/github.com/xxxxx/xxxxx/abc" in any of:
/home/travis/.gimme/versions/go1.6.linux.amd64/src/command-line-/vendor/github.com/xxxxx/xxxxx/xxx
Why it can't find package?
As build log, it seems to work well by go get command.
My travis.yml is here.
language: go
sudo: false
go:
- 1.6
- tip
services:
- redis-server
env:
global:
- secure: "xxxxx"
script:
- go fmt ./...
- go vet $(go list ./... | grep -v /vendor/)
- go test -v cmd/xxxx/*.go -xxxx ${XXXXX}
before_install:
- go get github.com/tools/godep
branches:
only:
- master
tip of go version is OK.
But 1.6 or 1.5 version can't run well.
How can I manage that situation?
The way Go 1.6 manages dependencies is different than Go 1.5 and previous versions.
1.6 introduces the /vendor folder. Whenever you import a dependency, if the library exists in /vendor, then the library is loaded.
The behavior was introduced in 1.5, but in that version it was experimental. It means that you need to enable it using the GO15VENDOREXPERIMENT=1 environment variable.
If you only need to provide support for 1.5 and 1.6, then simply add the variable to Travis when building 1.5 projects.
If you need to extend support also for versions before 1.5, then it's a little bit more complicated.

How to setup Coverity Scan on GitHub with TravisCI?

I've managed to setup TravisCI for my C++ hosted on Github project, it works fine.
I would like to move on to static analysis of my C++ code with Coverity Scan.
Automatic upload with TravisCI to Scan Coverity is possible but I can't find a way to make it work.
My git repository is simple, there are two branches: master and coverity_scan.
To avoid triggering static analysis each time I'm pushing something, all stuff related to Scan Coverity is filled in coverity_scan branch:
language: cpp
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "UEHXnbNPk49F6Ta/+d+UZl74EhtIevExwCo1l6qBndw+LvIXQDNSfsFiIJsZVfSgacBEOtd7CSY6rtccDpGeS9oX5/G/pnCz/2Cu+NOCCWlpy/S3qcUtdz52nMVatTgRhEi14WfrghpHk7nxxSi1W5+VIBfew+In11V1Xln3W06hhGOOK17Ljik18LbjSY1K9yVwK60r3tzwzSBMm/MArsqCeigzw15c0THQUtLlaLg/5nfP31f1QV9W1WlF4zIHjzd0970M385vNDDPyG+qRCfMPDEJrWb9/hJVi5x2poHLDObSE25rSQqfzc5nfiSDbH888mkdbBZXSwMVveVEhufyEk0nxI0Tddh/WNYFs+7g1gyV9409Tj288Omx++zpb0jM7/++wgkRwvBnqfBN7GWxoZJ9rHTxauJ+IIOR1jvskCTFMFMLI3C1+IpT4SgV0i6v2PtRsdGbXgI9qywhmPEjC+lS6Nu/rZQItr27rZowvw1ITYwJrDX4YQOAZxJkYNLFdGfqEMSjx0nfq6Kpl/4PaHQ7X0OtnJNgssMk3LNcYEwV1tLhTt+qODONjB7yWilcsWo8yVurr4vnFS2nIV7N4XgBvJcZHWfovxiQhfJU2UQxDvCYlDJ0RpM8kxpze+LR2vh+BbYOgPcr7YKG9MoAbsQXDGiF7yTz1VjVQr4="
addons:
coverity_scan:
project:
name: LeFlou/Citadel
build_command_prepend: "cmake"
build_command: "make"
branch_pattern: coverity_scan
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- clang
compiler:
- gcc
- clang
before_script:
- cmake .
script:
- make
install:
# Use g++4.8 and not 4.6 (C++11 missing)
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
branches:
only:
- coverity_scan
I want to trigger static analysis only when I push to coverity_scan, not building on TravisCI.
However, continuous integration must be working on master branch.
For the moment, code is only built but never uploaded to Coverity Scan.
What's wrong in my configuration ?
Edit:
I noticed in TravisCI validator multiple addons generate errors, only the last entry is processed. On the other hand, coverity_scan seem to build without trouble (I need apt to install more recent versions of g++, this is related to C++11 features).
Edit 20150910:
I merged both addons sections and this works.
But I'm still stuck on "Submitted first build" step.
I also changed COVERITY_SCAN_TOKEN, still this does not submit the build to Coverity Scan
TravisCI build with these changes
I think your problem is in build_command_prepend, it's cmake . and not cmake.
I think the problem might be that you indicated the branch you are using as coverity_scan here:
branch_pattern: coverity_scan
but you said you are pushing to the branch scan_coverity. So you might want to try pushing to coverity_scan instead?
I had trouble too but got it working eventually.
First go to your "Project Settings" in Coverity. Copy the token
Install the travis gem locally.
Then run:
travis encrypt -r <coverity_project_name> COVERITY_SCAN_TOKEN=<token>
For "coverity_project_name", use the name that is shown in your Coverity dashboard exactly as it appears.
You need to put the key generated by 'travis encrypt' into the "secure" field. So you should wind up with something like this:
- os: linux
dist: bionic
compiler: gcc
env:
- secure: "key generated by travis -r"
before_install:
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
addons:
coverity_scan:
project:
name: "theimpossibleastronaut/rmw"
description: "Console recycle bin written in C"
notification_email:
build_command_prepend: "./configure"
build_command: "make"
branch_pattern: coverity_scan

Resources