Skip to content
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: 1 addition & 1 deletion docs/user/reference/cli/azldev_component_build.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/app/azldev/cmds/component/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ComponentBuildOptions struct {

ContinueOnError bool
NoCheck bool
WithGitRepo bool
WithoutGitRepo bool
SourcePackageOnly bool
BuildEnvPolicy BuildEnvPreservePolicy

Expand Down Expand Up @@ -131,8 +131,8 @@ builds can consume.`,
cmd.Flags().BoolVarP(&options.ContinueOnError, "continue-on-error", "k", false,
"Continue building when some components fail")
cmd.Flags().BoolVar(&options.NoCheck, "no-check", false, "Skip package %check tests")
cmd.Flags().BoolVar(&options.WithGitRepo, "with-git", false,
"Create a dist-git repository with synthetic commit history (requires a project git repository)")
cmd.Flags().BoolVar(&options.WithoutGitRepo, "without-git", false,
"Skip creating a dist-git repository with synthetic commit history")
cmd.Flags().BoolVar(&options.SourcePackageOnly, "srpm-only", false, "Build SRPM (source RPM) *only*")
cmd.Flags().Var(&options.BuildEnvPolicy, "preserve-buildenv",
fmt.Sprintf("Preserve build environment {%s, %s, %s}",
Expand Down Expand Up @@ -252,7 +252,7 @@ func BuildComponent(
}, &err)

var preparerOpts []sources.PreparerOption
if options.WithGitRepo {
if !options.WithoutGitRepo {
preparerOpts = append(preparerOpts, sources.WithGitRepo(env, env.LockReader()))
}

Expand Down
9 changes: 9 additions & 0 deletions internal/app/azldev/cmds/component/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func TestNewBuildCommand(t *testing.T) {
assert.Equal(t, "build", cmd.Use)
assert.NotNil(t, cmd.RunE)
}

withoutGitFlag := cmd.Flags().Lookup("without-git")
require.NotNil(t, withoutGitFlag, "--without-git flag should be registered")
assert.Equal(t, "false", withoutGitFlag.DefValue, "dist-git flow should be enabled by default")
assert.Contains(t, withoutGitFlag.Usage, "dist-git")

// Legacy --with-git flag must NOT exist.
withGitFlag := cmd.Flags().Lookup("with-git")
assert.Nil(t, withGitFlag, "--with-git flag must not be registered")
}

func TestNewBuildCommand_MockConfigOptFlag(t *testing.T) {
Expand Down
20 changes: 10 additions & 10 deletions internal/app/azldev/cmds/component/preparesources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
type PrepareSourcesOptions struct {
ComponentFilter components.ComponentFilter

OutputDir string
SkipOverlays bool
WithGitRepo bool
Force bool
AllowNoHashes bool
OutputDir string
SkipOverlays bool
WithoutGitRepo bool
Force bool
AllowNoHashes bool
}

func prepareOnAppInit(_ *azldev.App, sourceCmd *cobra.Command) {
Expand Down Expand Up @@ -68,8 +68,8 @@ Only one component may be selected at a time.`,
_ = cmd.MarkFlagDirname("output-dir")

cmd.Flags().BoolVar(&options.SkipOverlays, "skip-overlays", false, "skip applying overlays to prepared sources")
cmd.Flags().BoolVar(&options.WithGitRepo, "with-git", false,
"Create a dist-git repository with synthetic commit history (requires a project git repository)")
cmd.Flags().BoolVar(&options.WithoutGitRepo, "without-git", false,
"Disable dist-git repository creation (enabled by default)")
cmd.Flags().BoolVar(&options.Force, "force", false, "delete and recreate the output directory if it already exists")
cmd.Flags().BoolVar(&options.AllowNoHashes, "allow-no-hashes", false,
"compute missing hashes by downloading source files from their origin")
Expand Down Expand Up @@ -121,13 +121,13 @@ func PrepareComponentSources(env *azldev.Env, options *PrepareSourcesOptions) er
return err
}

if options.SkipOverlays && options.WithGitRepo {
slog.Warn("--with-git has no effect when --skip-overlays is set; " +
if options.SkipOverlays && !options.WithoutGitRepo {
slog.Warn("dist-git flow has no effect when '--skip-overlays' is set; " +
"synthetic history requires overlays to be applied")
}

var preparerOpts []sources.PreparerOption
if options.WithGitRepo {
if !options.WithoutGitRepo && !options.SkipOverlays {
preparerOpts = append(preparerOpts, sources.WithGitRepo(env, env.LockReader()))
}
Comment thread
Tonisal-byte marked this conversation as resolved.

Expand Down
9 changes: 9 additions & 0 deletions internal/app/azldev/cmds/component/preparesources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func TestNewPrepareSourcesCmd(t *testing.T) {
require.NotNil(t, allowNoHashesFlag, "--allow-no-hashes flag should be registered")
assert.Equal(t, "false", allowNoHashesFlag.DefValue)
assert.Contains(t, allowNoHashesFlag.Usage, "compute missing hashes")

withoutGitFlag := cmd.Flags().Lookup("without-git")
require.NotNil(t, withoutGitFlag, "--without-git flag should be registered")
assert.Equal(t, "false", withoutGitFlag.DefValue, "dist-git flow should be enabled by default")
assert.Contains(t, withoutGitFlag.Usage, "dist-git")

// Legacy --with-git flag must NOT exist.
withGitFlag := cmd.Flags().Lookup("with-git")
assert.Nil(t, withGitFlag, "--with-git flag must not be registered")
}

func TestPrepareSourcesCmd_NoMatch(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions scenario/component_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestBuildingLocalComponent(t *testing.T) {
project := projecttest.NewDynamicTestProject(
projecttest.AddSpec(spec),
projecttest.UseTestDefaultConfigs(),
projecttest.WithGitRepo(),
)

// Run the build with test default configs copied into the container.
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestBuildingLocalComponentFromCheckedInFiles(t *testing.T) {
// Include test default configs to get distro and mock configurations.
project := projecttest.NewTemplatedTestProject(t, "testdata/simple",
projecttest.TemplatedUseTestDefaultConfigs(),
projecttest.TemplatedWithGitRepo(),
)

// Run the build with test default configs copied into the container.
Expand Down Expand Up @@ -121,6 +123,7 @@ func TestBuildingUpstreamComponent(t *testing.T) {
project := projecttest.NewDynamicTestProject(
projecttest.AddComponent(&projectconfig.ComponentConfig{Name: testComponentName}),
projecttest.UseTestDefaultConfigs(),
projecttest.WithGitRepo(),
)

// Run the build with test default configs copied into the container.
Expand Down
15 changes: 15 additions & 0 deletions scenario/internal/projecttest/templatetestproject.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type TemplatedTestProjectOption func(*templatedTestProject)
type templatedTestProject struct {
templateDir string
useTestDefaultConfigs bool
initGitRepo bool
}

// TemplatedUseTestDefaultConfigs configures the templated project to include the test default configs.
Expand All @@ -35,6 +36,15 @@ func TemplatedUseTestDefaultConfigs() TemplatedTestProjectOption {
}
}

// TemplatedWithGitRepo initializes the project directory as a git repository with an
// initial commit containing all project files. Required for commands that use synthetic
// history (e.g., [component build], [component render]).
func TemplatedWithGitRepo() TemplatedTestProjectOption {
return func(p *templatedTestProject) {
p.initGitRepo = true
}
}

func NewTemplatedTestProject(
t *testing.T,
templateDir string,
Expand Down Expand Up @@ -97,6 +107,11 @@ func (p *templatedTestProject) Serialize(t *testing.T, projectDir string) {
require.NoError(t, afero.WriteFile(osFS, configFilePath, modifiedBytes, fileperms.PublicFile),
"failed to write config file with test default configs")
}

// Initialize a git repo if requested.
if p.initGitRepo {
initProjectGitRepo(t, projectDir)
}
}

type notDryRun struct{}
Expand Down
Loading