use of com.google.copybara.config.Migration in project copybara by google.
the class Copybara method run.
/**
* Runs the migration specified by {@code migrationName}.
*/
public void run(Options options, ConfigLoader<?> configLoader, String migrationName, Path workdir, @Nullable String sourceRef) throws RepoException, ValidationException, IOException {
Config config = loadConfig(options, configLoader, migrationName);
Migration migration = config.getMigration(migrationName);
if (configLoaderProvider == null) {
this.migrationRanConsumer.accept(migration);
migration.run(workdir, sourceRef);
return;
}
// A safeguard, mirror workflows are not supported in the service anyway
if (!(migration instanceof Workflow)) {
throw new ValidationException("Flag --read-config-from-change is not supported for non-workflow migrations: %s", migrationName);
}
migrationRanConsumer.accept(migration);
@SuppressWarnings("unchecked") Workflow<? extends Revision, ? extends Revision> workflow = (Workflow<? extends Revision, ? extends Revision>) migration;
new ReadConfigFromChangeWorkflow<>(workflow, options, configLoaderProvider, configValidator).run(workdir, sourceRef);
}
use of com.google.copybara.config.Migration in project copybara by google.
the class InfoCmd method showAllMigrations.
private static void showAllMigrations(CommandEnv commandEnv, Config config) {
TablePrinter table = new TablePrinter("Name", "Origin", "Destination", "Mode", "Description");
for (Migration m : config.getMigrations().values().stream().sorted(Comparator.comparing(Migration::getName)).collect(ImmutableList.toImmutableList())) {
table.addRow(m.getName(), prettyOriginDestination(m.getOriginDescription()), prettyOriginDestination(m.getDestinationDescription()), m.getModeString(), Strings.nullToEmpty(m.getDescription()));
}
Console console = commandEnv.getOptions().get(GeneralOptions.class).console();
for (String line : table.build()) {
console.info(line);
}
console.info("To get information about the state of any migration run:\n\n" + " copybara info " + config.getLocation() + " [workflow_name]" + "\n");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class Main method getCommands.
public ImmutableSet<CopybaraCmd> getCommands(ModuleSet moduleSet, ConfigLoaderProvider configLoaderProvider, JCommander jcommander) throws CommandLineException {
ConfigValidator validator = getConfigValidator(moduleSet.getOptions());
Consumer<Migration> consumer = getMigrationRanConsumer();
return ImmutableSet.of(new MigrateCmd(validator, consumer, configLoaderProvider, moduleSet), new InfoCmd(configLoaderProvider, newInfoContextProvider()), new ValidateCmd(validator, consumer, configLoaderProvider), new HelpCmd(jcommander), new OnboardCmd(), new VersionCmd());
}
use of com.google.copybara.config.Migration in project copybara by google.
the class InfoTest method setUp.
@Before
public void setUp() throws IOException {
dummyOriginDescription = ImmutableMultimap.of("origin", "foo");
dummyDestinationDescription = ImmutableMultimap.of("dest", "bar");
console = new TestingConsole();
temp = Files.createTempDirectory("temp");
optionsBuilder = new OptionsBuilder();
optionsBuilder.setConsole(console);
optionsBuilder.setWorkdirToRealTempDir();
skylark = new SkylarkTestExecutor(optionsBuilder);
eventMonitor = new TestingEventMonitor();
optionsBuilder.general.enableEventMonitor("just testing", eventMonitor);
optionsBuilder.general.starlarkMode = StarlarkMode.STRICT.name();
migration = mock(Migration.class);
config = new Config(ImmutableMap.of("workflow", migration), temp.resolve("copy.bara.sky").toString(), ImmutableMap.of());
configWithDeps = mock(ConfigWithDependencies.class);
when(configWithDeps.getConfig()).thenAnswer(i -> config);
configInfo = "" + "core.workflow(" + " name = 'workflow'," + " origin = git.origin(url = 'https://example.com/orig', ref = 'master')," + " destination = git.destination(url = 'https://example.com/dest')," + " authoring = authoring.overwrite('Foo <foo@example.com>')" + ")\n\n" + "";
info = new InfoCmd((configPath, sourceRef) -> new ConfigLoader(skylark.createModuleSet(), skylark.createConfigFile("copy.bara.sky", configInfo), optionsBuilder.general.getStarlarkMode()) {
@Override
protected Config doLoadForRevision(Console console, Revision revision) throws ValidationException {
try {
return skylark.loadConfig(configPath);
} catch (IOException e) {
throw new AssertionError("Should not fail", e);
}
}
}, getFakeContextProvider());
}
use of com.google.copybara.config.Migration in project copybara by google.
the class WorkflowTest method reversibleCheckSymlinkError.
@Test
public void reversibleCheckSymlinkError() throws Exception {
Path someRoot = Files.createTempDirectory("someRoot");
Path originPath = someRoot.resolve("origin");
Files.createDirectories(originPath);
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(\n" + " name = 'default',\n" + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = testing.destination(),\n" + " authoring = " + authoring + ",\n" + " origin_files = glob(['included/**']),\n" + " reversible_check = True,\n" + " mode = '" + WorkflowMode.SQUASH + "',\n" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
Path included = originPath.resolve("included");
Files.createDirectory(included);
Files.write(originPath.resolve("included/foo.txt"), "a".getBytes(UTF_8));
Path fileOutsideCheckout = someRoot.resolve("file_outside_checkout");
Files.write(fileOutsideCheckout, "THE CONTENT".getBytes(UTF_8));
Files.createSymbolicLink(included.resolve("symlink"), included.relativize(fileOutsideCheckout));
origin.add().files("included/foo.txt").run();
origin.add().files("included/symlink").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "A commit");
ValidationException expected = assertThrows(ValidationException.class, () -> workflow.run(workdir, ImmutableList.of()));
assertThat(expected.getMessage()).matches("" + "Failed to perform reversible check of transformations due to symlink '.*' that " + "points outside the checkout dir. Consider removing this symlink from your " + "origin_files or, alternatively, set reversible_check = False in your " + "workflow.");
}
Aggregations