Skip to content

Commit

Permalink
fix(boot): 'jx upgrade boot' needs to fetch upgrade boot config SHA b…
Browse files Browse the repository at this point in the history
…efore cherrypicking

Without doing that, the cherry-pick will fail due to the commit from
the release tag not being present in the local boot repo, since it's
not on master.

fixes jenkins-x#5974

Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer committed Oct 30, 2019
1 parent 78b81f1 commit c8d3796
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ test-integration: get-test-deps## Run the integration tests
test-integration1: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration $(COVERFLAGS) -short ./... -test.v -run $(TEST)

test-integration1-pkg: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -tags=integration $(COVERFLAGS) -short $(PKG) -test.v -run $(TEST)

test-rich-integration1: make-reports-dir
@CGO_ENABLED=$(CGO_ENABLED) richgo test -tags=integration $(COVERFLAGS) -short -test.v $(TEST_PACKAGE) -run $(TEST)

Expand Down
16 changes: 12 additions & 4 deletions pkg/cmd/upgrade/upgrade_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (o *UpgradeBootOptions) updateBootConfig(versionStreamURL string, versionSt
if err != nil {
return errors.Wrapf(err, "failed to get boot config ref for version stream: %s", versionStreamRef)
}

upgradeSha, upgradeVersion, err := o.bootConfigRef(configCloneDir, versionStreamURL, upgradeVersionSha, bootConfigURL)
if err != nil {
return errors.Wrapf(err, "failed to get boot config ref for version stream ref: %s", upgradeVersionSha)
Expand All @@ -286,11 +287,18 @@ func (o *UpgradeBootOptions) updateBootConfig(versionStreamURL string, versionSt
return nil
}
log.Logger().Infof(util.ColorInfo("boot config upgrade available"))
log.Logger().Infof("Upgrading from v%s to v%s", util.ColorInfo(currentVersion), util.ColorInfo(upgradeVersion))
log.Logger().Infof("Upgrading from %s to %s", util.ColorInfo(currentVersion), util.ColorInfo(upgradeVersion))

// Fetch the tag we're upgrading from.
err = o.Git().FetchBranch(o.Dir, bootConfigURL, currentVersion)
if err != nil {
return errors.Wrapf(err, "failed to fetch current tag %s from %s", currentVersion, bootConfigURL)
}

err = o.Git().FetchBranch(o.Dir, bootConfigURL, "master")
// Fetch the tag we're upgrading to.
err = o.Git().FetchBranch(o.Dir, bootConfigURL, upgradeVersion)
if err != nil {
return errors.Wrapf(err, "failed to fetch master of %s", bootConfigURL)
return errors.Wrapf(err, "failed to fetch upgrade tag %s from %s", upgradeVersion, bootConfigURL)
}

err = o.cherryPickCommits(configCloneDir, currentSha, upgradeSha)
Expand All @@ -317,7 +325,7 @@ func (o *UpgradeBootOptions) bootConfigRef(dir string, versionStreamURL string,
if err != nil {
return "", "", errors.Wrapf(err, "failed to get commit pointed to by %s", cmtSha)
}
return cmtSha, configVersion, nil
return cmtSha, "v" + configVersion, nil
}

func (o *UpgradeBootOptions) cloneBootConfig(configURL string) (string, error) {
Expand Down
92 changes: 92 additions & 0 deletions pkg/cmd/upgrade/upgrade_boot_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// +build integration

package upgrade

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/jenkins-x/jx/pkg/cmd/opts"
"github.com/jenkins-x/jx/pkg/config"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestUpdateBootConfig(t *testing.T) {
origJxHome := os.Getenv("JX_HOME")

tmpJxHome, err := ioutil.TempDir("", "jx-test-"+t.Name())
assert.NoError(t, err)

err = os.Setenv("JX_HOME", tmpJxHome)
assert.NoError(t, err)

defer func() {
_ = os.RemoveAll(tmpJxHome)
err = os.Setenv("JX_HOME", origJxHome)
}()

o := UpgradeBootOptions{
CommonOptions: &opts.CommonOptions{},
}

// Prep the local clone with the contents of the boot config version we're going to upgrade from
tmpDir := initializeTempGitRepo(t, o.Git(), "v1.0.35")
defer func() {
err := os.RemoveAll(tmpDir)
require.NoError(t, err, "could not clean up temp boot clone")
}()

o.Dir = tmpDir

err = o.updateBootConfig(config.DefaultVersionsURL, "v1.0.161", config.DefaultBootRepository, "282fd7579ef82df408ccd2d425f99779784f75a9")
assert.NoError(t, err)
}

func initializeTempGitRepo(t *testing.T, gitter gits.Gitter, bootRef string) string {
dir, err := ioutil.TempDir("", "")
assert.NoError(t, err)

tmpCloneDir, err := ioutil.TempDir("", "update-boot-config-test-")
assert.NoError(t, err)

defer func() {
err := os.RemoveAll(tmpCloneDir)
require.NoError(t, err, "could not clean up temp boot clone")
}()

// Clone the boot config repo
err = gitter.Clone(config.DefaultBootRepository, tmpCloneDir)
assert.NoError(t, err)

// Fetch tags.
err = gitter.FetchTags(tmpCloneDir)
assert.NoError(t, err)

// Check out the boot ref.
err = gitter.Checkout(tmpCloneDir, bootRef)
assert.NoError(t, err)

// Copy the contents of the boot config repo to the temp repo.
err = util.CopyDir(tmpCloneDir, dir, true)
assert.NoError(t, err)

// Remove the .git directory
err = os.RemoveAll(filepath.Join(dir, ".git"))
assert.NoError(t, err)

err = gitter.Init(dir)
assert.NoError(t, err)

err = gitter.Add(dir, ".")
assert.NoError(t, err)

err = gitter.AddCommit(dir, "Initial Commit")
assert.NoError(t, err)

return dir
}

0 comments on commit c8d3796

Please sign in to comment.