From 18a882517149a72d289fd6c3fd0351bfc5232086 Mon Sep 17 00:00:00 2001 From: Nathan Martins Date: Thu, 3 Feb 2022 10:10:46 -0300 Subject: [PATCH] magefile:bugfix - fixing error with update version functions For some reason both functions responsable for updating the project version stopped working. This pull request removes the update specific for json since the tool don't seens to work while being executed by mage. Also fixed an error in UpdateHorusecVersionInProject wich was reporting file not found. Now just this function will update all necessary files. Signed-off-by: Nathan Martins --- .github/workflows/release.yml | 8 ++------ deployments/mage/magefile.go | 36 ++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c099bf58..84ff61d2f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -87,13 +87,9 @@ jobs: - name: Checkout release candidate branch run: ./mage -v checkoutReleaseBranch ${{ steps.updated-version.outputs.nextReleaseBranchName }} - - name: Update versions on package.json - run: ./mage -v updatePackageJson ${{ steps.updated-version.outputs.nextReleaseVersionStripped }} - - name: Update versions on rest of the project - run: | - find . -type f -not -path "./.git/*" -not -path "./manager/cypress/*" -not -name "*.sum" -not -name "*.mod"| - xargs sed -i "s/${{ steps.updated-version.outputs.actualReleaseVersion }}/${{ steps.updated-version.outputs.nextReleaseVersion }}/g" + - name: Update all Horusec versions in project + run: ./mage UpdateHorusecVersionInProject ${{ steps.updated-version.outputs.actualReleaseVersion }} ${{ steps.updated-version.outputs.nextReleaseVersion }} - name: Commit changes uses: EndBug/add-and-commit@v7.5.0 diff --git a/deployments/mage/magefile.go b/deployments/mage/magefile.go index e38d886d2..629d981c6 100644 --- a/deployments/mage/magefile.go +++ b/deployments/mage/magefile.go @@ -15,31 +15,37 @@ //go:build mage // +build mage -// Horusec-Plaform mage file. +// Horusec-Platform mage file. package main import ( "fmt" - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" "os" + "strings" + // mage:import _ "github.com/ZupIT/horusec-devkit/pkg/utils/mageutils" + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" ) -//UpdatePackageJson updates packge.json lock horusec version -func UpdatePackageJson(version string) error { - if err := sh.RunV("npm", "install", "-g", "json"); err != nil { +// UpdateHorusecVersionInProject update project version in all files +func UpdateHorusecVersionInProject(actualReleaseVersion, nextReleaseVersion string) error { + output, err := sh.Output("find", "./", "-type", "f", "-not", "-path", "'./.git/*'", "-not", "-path", + "'./Makefile'", "-not", "-path", "./Manager/cypress/*", "-not", "-name", "'*.sum'", "-not", "-name", + "'*.mod'") + if err != nil { return err } - return sh.RunV(fmt.Sprintf("json", "-I", "-f", "./manager/package.json", "-e", `'this.version="%s"'`, version)) -} -func UpdateHorusecVersionInProject(actualVersion, releaseVersion string) error { - return sh.RunV(fmt.Sprintf( - `find ./ -type f -not -path "./.git/*" -not -path "./Makefile" -not -path "./manager/cypress/*" -not -name "*.sum" -not -name "*.mod"| xargs sed -t -i "s/%s/%s/g"`, - actualVersion, releaseVersion)) + for _, path := range strings.Split(output, "\n") { + expression := fmt.Sprintf("s/%s/%s/g", actualReleaseVersion, nextReleaseVersion) + if err := sh.RunV("sed", "-i", expression, path); err != nil { + return err + } + } + return err } func DockerPushPlatformGoProjects(tag string) error { @@ -53,11 +59,11 @@ func DockerPushPlatformGoProjects(tag string) error { func DockerSignPlatformGoProjects(tag string) error { mg.Deps(hasAllNecessaryEnvs, isCosignInstalled) - err := os.MkdirAll("./tmp", 0700) + err := os.MkdirAll("./tmp", 0o700) if err != nil { return err } - err = os.WriteFile("./tmp/cosign.key", []byte(os.Getenv("COSIGN_KEY")), 0700) + err = os.WriteFile("./tmp/cosign.key", []byte(os.Getenv("COSIGN_KEY")), 0o700) if err != nil { return err } @@ -92,6 +98,7 @@ func getImages() []string { ImageApi, } } + func isCosignInstalled() error { return sh.RunV("cosign", "version") } @@ -120,5 +127,4 @@ func getConsingEnvs() map[string]string { "COSIGN_PWD": os.Getenv("COSIGN_PWD"), "COSIGN_KEY": os.Getenv("COSIGN_KEY"), } - }