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 ¶
- func BuildFolders(packagesToBuild []string, binDir, ldfFlags string) error
- func ConvertTestResults(logPath, xmlResult, workDir string) error
- func CoverTestFolders(packagesToCover []string, logDir, logFileName string) error
- func EnsureDirectoryExists(path string) error
- func FindPackagesToBuild(sourceDir string) ([]string, error)
- func FindPackagesToTest(sourceDir string) ([]string, error)
- func GetGitHash(workDir string) (string, error)
- func GetGitHeight(versionFile, workDir string) (int, error)
- func InstallTestConverter(workDir string) error
- func PathExists(path string) bool
- func ReadOSDistribution() (string, error)
- func RemovePaths(paths []string) error
- func RunTestFolders(packagesToTest []string, logDir, logFileName string) []error
- func RunTestFoldersEarlyExit(packagesToTest []string, logDir, logFileName string) error
- func ZipFolders(sources []string, target string) error
- type OsNotSupportedByThisMethod
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFolders ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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
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 ¶
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 ¶
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
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 ¶
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
func (e *OsNotSupportedByThisMethod) Error() string