gobuildhelpers

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

Go Build Helpers

Go package with helper functions for go based CI/CD workflows May be used within https://magefile.org/ based build scripts

This package is used in my own magefiles, and may is helpful fo others.

There are no plans to enhance this further than needed.

Documentation

Overview

gobuildhelpers - Go package with helper functions for go based CI/CD workflows May be used within https://magefile.org/ based build scripts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFolders

func BuildFolders(packagesToBuild []string, binDir, ldfFlags string) error

BuildFolders - Runs 'go build -o <binDir>/packageName -v -ldflags <ldfFlags>' for all given packages to build Any package folder in the list should contain a go package with a 'go.mod' file - packagesToBuild: List of the packages directory path to build. Each directory should contain a 'go.mod' file - binDir: The output directory of the build. Any package to build will create an executable there - ldfFlags: Flags passed to the command via '-ldflags', may be empty It returns any error that may occur or nil

func ConvertTestResults

func ConvertTestResults(logPath, xmlResult, workDir string) error

ConvertTestResults - Converts a given 'go test' output log and converts the content into a junit xml result file It uses 'github.com/tebeka/go2xunit' to do so. You need to install this package before you can run this function. To install the converter you might want to use the 'InstallTestConverter' function - logPath: The path to the 'go test' output log to convert - xmlResult: The junit xml result output file - workDir: The directory this operation will run in. Usually the repository root directory It returns any error that may occur or nil

func CoverTestFolders

func CoverTestFolders(packagesToCover []string, logDir, logFileName string) error

CoverTestFolders - Runs 'go test -v -cover' on all given packages to test and creates a log file with the output Any package folder in the list should contain a go package with at least one '*_test.go' file - packagesToCover: List of directory path that contains '*_test.go' files test coverage should be measured - logDir: Path to the directory the log file is crated - logFileName: Name of the log file It returns any error that may occur or nil

func EnsureDirectoryExists added in v0.1.2

func EnsureDirectoryExists(path string) error

EnsureDirectoryExists - Checks if the given directory path exists, and creates it if not - path: The directory that should exist It returns any error that may occor or nil

func FindPackagesToBuild

func FindPackagesToBuild(sourceDir string) ([]string, error)

FindPackagesToBuild - Find a list of folders that contain go packages - sourceDir: The directory this function will start to search in recursively It returns the list of directory paths and nil in case of no error If an error occur the error and an empty list will be returned

func FindPackagesToTest

func FindPackagesToTest(sourceDir string) ([]string, error)

FindPackagesToBuild - Find a list of folders that contain go packages with tests - sourceDir: The directory this function will start to search in recursively It returns the list of directory paths and nil in case of no error If an error occur the error and an empty list will be returned

func GetGitHash

func GetGitHash(workDir string) (string, error)

GetGitHash - Get the git hash currently checked out in the workDir - workDir: The directory this operation will run in. Usually the repository root directory It returns the git hash string and nil in case no error occur In case of error the error and an empty string is returned

func GetGitHeight

func GetGitHeight(versionFile, workDir string) (int, error)

GetGitHeight - Get the git height ( https://github.com/dotnet/Nerdbank.GitVersioning#what-is-git-height ) to the last change of versionFile - versionFile: The relative path (to workDir) of the file git height is calculated for - workDir: The directory this operation will run in. Usually the repository root directory It returns the git height number and nil in case no error occur In case of error the error and '-1' is returned

func InstallTestConverter

func InstallTestConverter(workDir string) error

InstallTestConverter - Install the 'github.com/tebeka/go2xunit' package used to convert test results in the 'ConvertTestResults' function - workDir: The directory the package will be installed. Might not the repository root It returns any error that may occur or nil

func PathExists added in v0.1.2

func PathExists(path string) bool

PathExists - check if a path exists - path: The file od folder path to check It returns true if a path exists, and false if not

func ReadOSDistribution added in v0.1.2

func ReadOSDistribution() (string, error)

ReadOSDistribution - Read the linux distribution name (ID line) from '/etc/os-release' It returns the distribution name and nil In case of error it returns the error and an empty string Attention: This can only work on linux distributions that follow the FHS (Filesystem Hierarchy Standard)

func RemovePaths

func RemovePaths(paths []string) error

RemovePaths - Deletes the given paths recursively - paths: The list of directory or file path to delete It returns any error may occur or nil

func RunTestFolders

func RunTestFolders(packagesToTest []string, logDir, logFileName string) []error

RunTestFolders - Runs 'go test -v -race' on linux and 'go test -v' on windows for all given packages to test Any package folder in the list should contain a go package with at least one '*_test.go' file All tests will be executed, even if a error occur in the package before, the next package's tests get executed - packagesToTest: List of directory path that contains '*_test.go' files to run - logDir: Path to the directory the log file is crated - logFileName: Name of the log file It returns any error that may occur or an empty list

func RunTestFoldersEarlyExit added in v0.1.3

func RunTestFoldersEarlyExit(packagesToTest []string, logDir, logFileName string) error

RunTestFolders - Runs 'go test -v -race' on linux and 'go test -v' on windows for all given packages to test Any package folder in the list should contain a go package with at least one '*_test.go' file Test execution will stop on first failed test - packagesToTest: List of directory path that contains '*_test.go' files to run - logDir: Path to the directory the log file is crated - logFileName: Name of the log file It returns any error that may occur or nil

func ZipFolders

func ZipFolders(sources []string, target string) error

ZipFolders - Zips the given source folders recursively into the target zip file - sources: List of path to the folders to zip - target: The output zip file It returns any error that may occur or nil

Types

type OsNotSupportedByThisMethod added in v0.1.2

type OsNotSupportedByThisMethod struct {
	// contains filtered or unexported fields
}

func NewOsNotSupportedByThisMethod added in v0.1.2

func NewOsNotSupportedByThisMethod(os, method string) *OsNotSupportedByThisMethod

NewOsNotSupportedByThisMethod- Get a new OsNotSupportedByThisMethod struct

func (*OsNotSupportedByThisMethod) Error added in v0.1.2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL