Skip to content

Commit

Permalink
magefile:bugfix - fixing error with update version functions (#547)
Browse files Browse the repository at this point in the history
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 <nathan.martins@zup.com.br>
  • Loading branch information
nathanmartinszup authored Feb 3, 2022
1 parent c06306c commit a6859ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions deployments/mage/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -92,6 +98,7 @@ func getImages() []string {
ImageApi,
}
}

func isCosignInstalled() error {
return sh.RunV("cosign", "version")
}
Expand Down Expand Up @@ -120,5 +127,4 @@ func getConsingEnvs() map[string]string {
"COSIGN_PWD": os.Getenv("COSIGN_PWD"),
"COSIGN_KEY": os.Getenv("COSIGN_KEY"),
}

}

0 comments on commit a6859ae

Please sign in to comment.