Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a without-download flag to update-stemcell to skip release downloads #519

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions internal/acceptance/workflows/scenario/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func InitializeKiln(ctx *godog.ScenarioContext) { initializeKiln(ctx) }
func initializeKiln(ctx scenarioContext) {
ctx.Step(regexp.MustCompile(`^I invoke kiln$`), iInvokeKiln)
ctx.Step(regexp.MustCompile(`^I try to invoke kiln$`), iTryToInvokeKiln)
ctx.Step(regexp.MustCompile(`^the "([^"]*)" release tarball exists$`), theReleaseTarballExists)
ctx.Step(regexp.MustCompile(`^the "([^"]*)" release tarball does not exist$`), theReleaseTarballDoesNotExist)
}

func InitializeRegex(ctx *godog.ScenarioContext) { initializeRegex(ctx) }
Expand Down
31 changes: 31 additions & 0 deletions internal/acceptance/workflows/scenario/step_funcs_kiln.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"

Expand All @@ -18,6 +19,36 @@ func iTryToInvokeKiln(ctx context.Context, table *godog.Table) (context.Context,
return invokeKiln(ctx, false, argsFromTable(table)...)
}

func theReleaseTarballExists(ctx context.Context, tarballName string) error {
tileDir, err := tileRepoPath(ctx)
if err != nil {
return fmt.Errorf("failed to get tile repo path: %w", err)
}

releasePath := filepath.Join(tileDir, "releases", tarballName)
_, err = os.Stat(releasePath)
return err
}

func theReleaseTarballDoesNotExist(ctx context.Context, tarballName string) error {
tileDir, err := tileRepoPath(ctx)
if err != nil {
return fmt.Errorf("failed to get tile repo path: %w", err)
}

releasePath := filepath.Join(tileDir, "releases", tarballName)
_, err = os.Stat(releasePath)
if err == nil {
return fmt.Errorf("release tarball %q exists", tarballName)
}

if !os.IsNotExist(err) {
return err
}

return nil
}

func kilnValidateSucceeds(ctx context.Context) (context.Context, error) {
return invokeKiln(ctx, true, "validate", "--variable=github_access_token=banana")
}
Expand Down
24 changes: 20 additions & 4 deletions internal/acceptance/workflows/updating_releases.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,38 @@ Feature: As a dependabot, I want to update a BOSH Release

Scenario: Find a version on bosh.io
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And I set the version constraint to "1.1.18" for release "bpm"
When I invoke kiln
| find-release-version |
| --release=bpm |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then stdout contains substring: "1.1.18"

Scenario: Update a component to a new release
Scenario: Update a component to a new release with download
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And the Kilnfile.lock specifies version "0.2.3" for release "hello-release"
And GitHub repository "crhntr/hello-release" has release with tag "v0.2.3"
And GitHub repository "crhntr/hello-release" has release with tag "0.3.0"
When I invoke kiln
| update-release |
| --name=hello-release |
| --version=v0.2.3 |
| --version=0.3.0 |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then the Kilnfile.lock specifies version "0.3.0" for release "hello-release"
And kiln validate succeeds
And the "hello-release-0.3.0.tgz" release tarball exists

Scenario: Update a component to a new release without download
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And the Kilnfile.lock specifies version "1.2.12" for release "bpm"
When I invoke kiln
| update-release |
| --name=bpm |
| --version=1.2.13 |
| --without-download |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then the Kilnfile.lock specifies version "0.2.3" for release "hello-release"
Then the Kilnfile.lock specifies version "1.2.13" for release "bpm"
And kiln validate succeeds
And the "bpm-1.2.13.tgz" release tarball does not exist
37 changes: 35 additions & 2 deletions internal/acceptance/workflows/updating_stemcell.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,45 @@ Feature: As a dependabot, I want to update a stemcell
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then stdout contains substring: "1.340"

Scenario: Update the stemcell
Scenario: Update the stemcell with download
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And TanzuNetwork has product "stemcells-ubuntu-jammy" with version "1.340"
And "Kilnfile.lock" contains substring: version: "1.329"
When I invoke kiln
| update-stemcell |
| --version=1.340 |
| --version=1.340 |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then "Kilnfile.lock" contains substring: version: "1.340"
And the Kilnfile.lock specifies version "0.2.3" for release "hello-release"
And the "bpm-1.2.12.tgz" release tarball exists
And the "hello-release-0.2.3.tgz" release tarball exists

Scenario: Update the stemcell without download
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And TanzuNetwork has product "stemcells-ubuntu-jammy" with version "1.340"
And "Kilnfile.lock" contains substring: version: "1.329"
When I invoke kiln
| update-stemcell |
| --version=1.340 |
| --without-download |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then "Kilnfile.lock" contains substring: version: "1.340"
And the Kilnfile.lock specifies version "0.2.3" for release "hello-release"
And the "bpm-1.2.12.tgz" release tarball does not exist
And the "hello-release-0.2.3.tgz" release tarball does not exist

Scenario: Update the stemcell with release updates
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
And TanzuNetwork has product "stemcells-ubuntu-jammy" with version "1.340"
And "Kilnfile.lock" contains substring: version: "1.329"
When I invoke kiln
| update-stemcell |
| --version=1.340 |
| --update-releases |
| --variable=github_access_token="${GITHUB_ACCESS_TOKEN}" |
Then "Kilnfile.lock" contains substring: version: "1.340"
And the Kilnfile.lock specifies version "0.3.0" for release "hello-release"
And the "hello-release-0.3.0.tgz" release tarball exists
10 changes: 5 additions & 5 deletions internal/commands/update_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type UpdateRelease struct {
Options struct {
flags.Standard

Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
AllowOnlyPublishableReleases bool `long:"allow-only-publishable-releases" description:"include releases that would not be shipped with the tile (development builds)"`
WithoutDownload bool `long:"without-download" description:"updates releases without downloading them"`
Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
AllowOnlyPublishableReleases bool ` long:"allow-only-publishable-releases" default:"false" description:"include releases that would not be shipped with the tile (development builds)"`
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates releases without downloading them"`
}
multiReleaseSourceProvider MultiReleaseSourceProvider
filesystem billy.Filesystem
Expand Down
34 changes: 25 additions & 9 deletions internal/commands/update_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type UpdateStemcell struct {
Options struct {
flags.Standard

Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
UpdateReleases bool `short:"ur" long:"update-releases" description:"finds latest matching releases for new stemcell version"`
Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
UpdateReleases bool `short:"ur" long:"update-releases" default:"false" description:"finds latest matching releases for new stemcell version"`
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates stemcell releases without downloading releases"`
}
FS billy.Filesystem
MultiReleaseSourceProvider MultiReleaseSourceProvider
Expand Down Expand Up @@ -75,10 +76,12 @@ func (update UpdateStemcell) Execute(args []string) error {
if err != nil {
return err
}

spec.StemcellOS = kilnfileLock.Stemcell.OS
spec.StemcellVersion = trimmedInputVersion

var remote cargo.BOSHReleaseTarballLock

if update.Options.UpdateReleases {
remote, err = releaseSource.FindReleaseVersion(spec, true)
} else {
Expand All @@ -89,24 +92,37 @@ func (update UpdateStemcell) Execute(args []string) error {
if err != nil {
return fmt.Errorf("while finding release %q, encountered error: %w", rel.Name, err)
}

if component.IsErrNotFound(err) {
return fmt.Errorf("couldn't find release %q", rel.Name)
}

if remote.RemotePath == rel.RemotePath && remote.RemoteSource == rel.RemoteSource {
update.Logger.Printf("No change for release %q\n", rel.Name)
continue
}

local, err := releaseSource.DownloadRelease(update.Options.ReleasesDir, remote)
if err != nil {
return fmt.Errorf("while downloading release %q, encountered error: %w", rel.Name, err)
if update.Options.WithoutDownload {
continue
}
}

lock := &kilnfileLock.Releases[i]
lock.SHA1 = local.Lock.SHA1
lock.RemotePath = remote.RemotePath
lock.RemoteSource = remote.RemoteSource
lock.SHA1 = remote.SHA1

if update.Options.UpdateReleases {
lock.Version = remote.Version
}

if !update.Options.WithoutDownload || lock.SHA1 == "" || lock.SHA1 == "not-calculated" {
// release source needs to download.
local, err := releaseSource.DownloadRelease(update.Options.ReleasesDir, remote)
if err != nil {
return fmt.Errorf("while downloading release %s %s, encountered error: %w", lock.Name, lock.Version, err)
}

lock.SHA1 = local.Lock.SHA1
}
}

kilnfileLock.Stemcell.Version = trimmedInputVersion
Expand Down
Loading
Loading