func CopyRpmPackageTemplates()

in pkg/util/template.go [165:213]


func CopyRpmPackageTemplates(ctx context.Context, templatesDest, assetsDir string, config *model.ConfigGoTemplating) error {
	l := ctrl.LoggerFrom(ctx)
	l.Info("Start handling RPM Package templates")

	// Define template paths
	makefileTemplatePath := path.Join(assetsDir, "templates/applications/rpm-package/Makefile.tmpl")
	rpmlintTemplatePath := path.Join(assetsDir, "templates/applications/rpm-package/.rpmlintrc.toml")

	specTemplatePath := path.Join(assetsDir, fmt.Sprintf("templates/applications/rpm-package/%s/spec.tmpl", config.Lang))
	serviceTemplatePath := path.Join(assetsDir, fmt.Sprintf("templates/applications/rpm-package/%s/service.tmpl", config.Lang))

	if _, err := os.Stat(specTemplatePath); os.IsNotExist(err) {
		specTemplatePath = path.Join(assetsDir, "templates/applications/rpm-package/default/spec.tmpl")
		serviceTemplatePath = path.Join(assetsDir, "templates/applications/rpm-package/default/service.tmpl")
	} else if err != nil {
		return fmt.Errorf("failed to check if %q exists: %w", specTemplatePath, err)
	}

	// Define destination paths
	makefileDestPath := path.Join(templatesDest, "Makefile")
	if _, err := os.Stat(makefileDestPath); err == nil {
		makefileDestPath = path.Join(templatesDest, "Makefile.kuberocketci")
	}

	specDestPath := path.Join(templatesDest, fmt.Sprintf("%s.spec", config.Name))
	serviceDestPath := path.Join(templatesDest, fmt.Sprintf("%s.service", config.Name))
	rpmlintDestPath := path.Join(templatesDest, ".rpmlintrc.toml")

	// Create and render templates
	if err := createAndRenderTemplate(makefileDestPath, makefileTemplatePath, "Makefile.tmpl", config); err != nil {
		return err
	}

	if err := createAndRenderTemplate(specDestPath, specTemplatePath, "spec.tmpl", config); err != nil {
		return err
	}

	if err := createAndRenderTemplate(serviceDestPath, serviceTemplatePath, "service.tmpl", config); err != nil {
		return err
	}

	if err := CopyFile(rpmlintTemplatePath, rpmlintDestPath); err != nil {
		return err
	}

	l.Info("RPM Package templates have been copied and rendered")

	return nil
}