Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

1932 - galasabld versioning list/suffix set/suffix remove #60

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ openapi2beans/build
**/.vscode
**/generated/*
**/target
*.jar
*.jar
temp/
build/
36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
all: bin/galasabld-linux-amd64 \
all: clean test \
bin/galasabld-linux-amd64 \
bin/galasabld-windows-amd64 \
bin/galasabld-darwin-amd64 \
bin/galasabld-linux-s390x \
bin/galasabld-darwin-arm64

bin/galasabld-linux-amd64 : ./Makefile ./cmd/galasabld/main.go ./pkg/cmd/*.go ./pkg/galasayaml/*.go ./pkg/githubjson/*.go
src : ./Makefile \
./cmd/galasabld/main.go \
./pkg/cmd/*.go \
./pkg/galasayaml/*.go \
./pkg/githubjson/*.go \
./pkg/utils/*.go \
./pkg/versioning/*.go

test: src

bin/galasabld-linux-amd64 : src
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/galasabld-linux-amd64 ./cmd/galasabld

bin/galasabld-windows-amd64 : ./Makefile ./cmd/galasabld/main.go ./pkg/cmd/*.go ./pkg/galasayaml/*.go ./pkg/githubjson/*.go
bin/galasabld-windows-amd64 : src
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/galasabld-windows-amd64 ./cmd/galasabld

bin/galasabld-darwin-amd64 : ./Makefile ./cmd/galasabld/main.go ./pkg/cmd/*.go ./pkg/galasayaml/*.go ./pkg/githubjson/*.go
bin/galasabld-darwin-amd64 : src
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/galasabld-darwin-amd64 ./cmd/galasabld

bin/galasabld-darwin-arm64 : ./Makefile ./cmd/galasabld/main.go ./pkg/cmd/*.go ./pkg/galasayaml/*.go ./pkg/githubjson/*.go
bin/galasabld-darwin-arm64 : src
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/galasabld-darwin-arm64 ./cmd/galasabld

bin/galasabld-linux-s390x : ./Makefile ./cmd/galasabld/main.go ./pkg/cmd/*.go ./pkg/galasayaml/*.go ./pkg/githubjson/*.go
bin/galasabld-linux-s390x : src
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -o bin/galasabld-linux-s390x ./cmd/galasabld

test: src build/coverage.txt build/coverage.html build/coverage.out

build/coverage.out : src
mkdir -p build
go test -v -cover -coverprofile=build/coverage.out -coverpkg ./pkg/cmd,./pkg/galasayaml,./pkg/githubjson,./pkg/utils,./pkg/versioning ./pkg/...

build/coverage.html : build/coverage.out
go tool cover -html=build/coverage.out -o build/coverage.html

build/coverage.txt : build/coverage.out
go tool cover -func=build/coverage.out > build/coverage.txt
cat build/coverage.txt

clean:
rm -rf bin
rm -rf build/coverage.*
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,37 @@ This repository is built into tools which themselves are used during a Galasa bu

## To build locally
Use the `./build-locally.sh --help` to get a description of the required parameters and environment variables.

## The `galasabld` utility


### To list the versions of all gradle modules

```
$galasabld versioning list --sourcefolderpath {my-source-folder}
a.b.c. 0.21.0
a.b.d. 0.25.0-SNAPSHOT
```

To find a module version, the code must:
- have a build.gradle file
- have a settings.gradle file
- the build.gradle file must have a line like `version = "0.1.2"` or similar.
- the settings.gradle file must have a line like `rootProject.name = "dev.galasa.examples/module2"`.

### To set a version suffix on all gradle modules
```
$galasabld versioning suffix set --sourcefolderpath {my-source-folder} --suffix "-alpha"
```
This will recursively look for module versions, stripping off any existing suffix, and adding the `-alpha` suffix to everything.

Note: The value of the `--suffix` parameter must start with `-` or `_`

So for example, `0.0.1` will be changed to `0.0.1-alpha` if `-alpha` is the suffix value.

### To remove any suffix on all gradle modules
```
$galasabld versioning suffix remove --sourcefolderpath {my-source-folder}
```
This will recursively look for module versions, stripping off any existing suffix.
So for example, `0.0.1-SNAPSHOT` will be changed to `0.0.1`
98 changes: 44 additions & 54 deletions build-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,16 @@ blue=$(tput setaf 25)
# Headers and Logging
#
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@"
}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@"
}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@"
}
debug() { printf "${white}[.] %s${reset}\n" "$@"
}
info() { printf "${white}[➜] %s${reset}\n" "$@"
}
success() { printf "${white}[${green}✔${white}] ${green}%s${reset}\n" "$@"
}
error() { printf "${white}[${red}✖${white}] ${red}%s${reset}\n" "$@"
}
warn() { printf "${white}[${tan}➜${white}] ${tan}%s${reset}\n" "$@"
}
bold() { printf "${bold}%s${reset}\n" "$@"
}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@"
}
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ; }
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ; }
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ; }
debug() { printf "${white}[.] %s${reset}\n" "$@" ; }
info() { printf "${white}[➜] %s${reset}\n" "$@" ; }
success() { printf "${white}[${green}✔${white}] ${green}%s${reset}\n" "$@" ; }
error() { printf "${white}[${red}✖${white}] ${red}%s${reset}\n" "$@" ; }
warn() { printf "${white}[${tan}➜${white}] ${tan}%s${reset}\n" "$@" ; }
bold() { printf "${bold}%s${reset}\n" "$@" ; }
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ; }

#-----------------------------------------------------------------------------------------
# Functions
Expand All @@ -69,13 +59,6 @@ function usage {
cat << EOF
Options are:
-h | --help : Display this help text

Environment Variables:

LOGS_DIR :
Controls where logs are placed.
Optional. Defaults to creating a new temporary folder

EOF
}

Expand Down Expand Up @@ -136,40 +119,47 @@ done

source_dir="."

project=$(basename ${BASEDIR})
h1 "Building ${project}"
function clean_temp_folder() {
rm -fr $BASEDIR/temp
mkdir -p $BASEDIR/temp
LOGS_DIR=$BASEDIR/temp
}

function build_tools() {

project=$(basename ${BASEDIR})
h1 "Building ${project}"

info "Using source code at ${source_dir}"
cd ${BASEDIR}/${source_dir}

# Create a temporary dir.
# Note: This bash 'spell' works in OSX and Linux.
if [[ -z ${LOGS_DIR} ]]; then
export LOGS_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t "galasa-logs")
info "Logs are stored in the ${LOGS_DIR} folder."
info "Over-ride this setting using the LOGS_DIR environment variable."
else
mkdir -p ${LOGS_DIR} 2>&1 > /dev/null # Don't show output. We don't care if it already existed.
info "Logs are stored in the ${LOGS_DIR} folder."
info "Over-ridden by caller using the LOGS_DIR variable."
fi
log_file=${LOGS_DIR}/${project}.txt
info "Log will be placed at ${log_file}"
date > ${log_file}

info "Using source code at ${source_dir}"
cd ${BASEDIR}/${source_dir}
cmd="make all"
info "Command is '$cmd'"

log_file=${LOGS_DIR}/${project}.txt
info "Log will be placed at ${log_file}"
date > ${log_file}
cd ${BASEDIR}
$cmd 2>&1 >> ${log_file}

rc=$?
check_exit_code $rc "Failed to build the ${project}"
success "${project} built ok - log is at ${log_file}"
}

cmd="make all"
info "Command is '$cmd'"

cd ${BASEDIR}
$cmd 2>&1 >> ${log_file}

rc=$?
check_exit_code $rc "Failed to build the ${project}"
success "${project} built ok - log is at ${log_file}"
function build_openapi2beans() {
h2 "Building openapi2beans."
./openapi2beans/build-locally.sh
}


h2 "Building openapi2beans."
./openapi2beans/build-locally.sh
clean_temp_folder
build_tools
build_openapi2beans

$BASEDIR/test-locally.sh
rc=$? ; check_exit_code $rc "Failed to test galasabld"
check_secrets
8 changes: 4 additions & 4 deletions pkg/cmd/githubbranchcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func githubBranchCopyExecute(cmd *cobra.Command, args []string) {

// First get the sha of the from branch

var url = ""
var url string
if branchCopyFromBranch != "" {
url = fmt.Sprintf("https://api.github.com/repos/galasa-dev/%v/git/ref/heads/%v", githubRepository, branchCopyFromBranch)
} else {
Expand All @@ -67,7 +67,7 @@ func githubBranchCopyExecute(cmd *cobra.Command, args []string) {

req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down Expand Up @@ -99,7 +99,7 @@ func githubBranchCopyExecute(cmd *cobra.Command, args []string) {

req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down Expand Up @@ -153,7 +153,7 @@ func githubBranchCopyExecute(cmd *cobra.Command, args []string) {
}
req, err = http.NewRequest(httpType, url, newReferenceBuffer)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/githubbranchdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func githubBranchDeleteExecute(cmd *cobra.Command, args []string) {
url := fmt.Sprintf("https://api.github.com/repos/galasa-dev/%v/git/ref/heads/%v", githubRepository, branchDeleteBranch)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand All @@ -73,7 +73,7 @@ func githubBranchDeleteExecute(cmd *cobra.Command, args []string) {

req, err = http.NewRequest("DELETE", url, nil)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/githubbranchtag.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func githubBranchTagExecute(cmd *cobra.Command, args []string) {

req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down Expand Up @@ -97,7 +97,7 @@ func githubBranchTagExecute(cmd *cobra.Command, args []string) {

req, err = http.NewRequest(httpType, url, newReferenceBuffer)
if err != nil {
panic(nil)
panic(err)
}

req.Header.Set("Authorization", basicAuth)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/mavendeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func mavenDeploy(
mavenDeployVersion string,
basicAuth string) error {

var err error = nil
var err error
var artifactDirectories []fs.DirEntry
var mavenMetadataExists bool
var versionDirectoryExists bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
Use: "galasabld",
Short: "Build utilities for Galasa",
Long: "",
Version: "0.0.7",
Version: "0.36.0",
}

func Execute() {
Expand Down
27 changes: 16 additions & 11 deletions pkg/cmd/secvulnOssindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func getDependencyChainAsString(dependencyChain []string) string {
return dependencyChainString
}

func processDependencyChain(submatches [][]string, cve, galasaArtifactString, vulnerability string) []string {
func processDependencyChain(submatches [][]string, cve, galasaArtifactString string, vulnerability string) []string {

// Start forming the dependency chain
var dependencyChain []string
Expand All @@ -212,8 +212,9 @@ func processDependencyChain(submatches [][]string, cve, galasaArtifactString, vu
for targetString != galasaArtifactString {

if count == maxLoops {
fmt.Printf("Too many attempts to parse dependency chain from %s to %s\n", galasaArtifactString, vulnerability)
panic(nil)
msg := fmt.Sprintf("Too many attempts to parse dependency chain from %s to %s\n", galasaArtifactString, vulnerability)
fmt.Printf(msg)
panic(msg)
}

for _, submatch := range submatches {
Expand Down Expand Up @@ -302,11 +303,13 @@ func createReport() *SecVulnYamlReport {
if len(depChainMap[getGroupAndArtifact(innerProject)][getGroupArtifactVersion(vulnerableArtifact)]) == 1 {
depChain = depChainMap[getGroupAndArtifact(innerProject)][getGroupArtifactVersion(vulnerableArtifact)][0]
} else if len(depChainMap[getGroupAndArtifact(innerProject)][getGroupArtifactVersion(vulnerableArtifact)]) > 1 {
fmt.Printf("Multiple dependency chains found from %s to %s\n", innerProject, vulnerableArtifact)
panic(nil)
msg := fmt.Sprintf("Multiple dependency chains found from %s to %s\n", innerProject, vulnerableArtifact)
fmt.Printf(msg)
panic(msg)
} else if len(depChainMap[getGroupAndArtifact(innerProject)][getGroupArtifactVersion(vulnerableArtifact)]) == 0 {
fmt.Printf("Unable to find dependency chain from %s to %s\n", innerProject, vulnerableArtifact)
panic(nil)
msg := fmt.Sprintf("Unable to find dependency chain from %s to %s\n", innerProject, vulnerableArtifact)
fmt.Printf(msg)
panic(msg)
}

transientProj := &TransientProject{
Expand All @@ -321,11 +324,13 @@ func createReport() *SecVulnYamlReport {
if len(depChainMap[getGroupAndArtifact(directProject)][getGroupArtifactVersion(vulnerableArtifact)]) == 1 {
directDepChain = depChainMap[getGroupAndArtifact(directProject)][getGroupArtifactVersion(vulnerableArtifact)][0]
} else if len(depChainMap[getGroupAndArtifact(directProject)][getGroupArtifactVersion(vulnerableArtifact)]) > 1 {
fmt.Printf("Multiple dependency chains found from %s to %s\n", directProject, vulnerableArtifact)
panic(nil)
msg := fmt.Sprintf("Multiple dependency chains found from %s to %s\n", directProject, vulnerableArtifact)
fmt.Printf(msg)
panic(msg)
} else if len(depChainMap[getGroupAndArtifact(directProject)][getGroupArtifactVersion(vulnerableArtifact)]) == 0 {
fmt.Printf("Unable to find dependency chain from %s to %s\n", directProject, vulnerableArtifact)
panic(nil)
msg := fmt.Sprintf("Unable to find dependency chain from %s to %s\n", directProject, vulnerableArtifact)
fmt.Printf(msg)
panic(msg)
}

directProject := &DirectProject{
Expand Down
Loading