Search in sources :

Example 1 with JReleaserGpgSigner

use of org.jreleaser.sdk.git.JReleaserGpgSigner in project jreleaser by jreleaser.

the class ArticleAnnouncer method publishToRepository.

private void publishToRepository(Path prepareDirectory) throws AnnounceException {
    context.getLogger().info(RB.$("repository.setup"), article.getRepository().getCanonicalRepoName());
    if (context.isDryrun()) {
        return;
    }
    GitService gitService = context.getModel().getRelease().getGitService();
    try {
        // get the repository
        context.getLogger().debug(RB.$("repository.locate"), article.getRepository().getCanonicalRepoName());
        Repository repository = context.getReleaser().maybeCreateRepository(article.getRepository().getOwner(), article.getRepository().getResolvedName(), resolveGitToken(gitService));
        UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(resolveGitUsername(gitService), resolveGitToken(gitService));
        // clone the repository
        context.getLogger().debug(RB.$("repository.clone"), repository.getHttpUrl());
        Path directory = Files.createTempDirectory("jreleaser-" + article.getRepository().getResolvedName());
        Git git = Git.cloneRepository().setCredentialsProvider(credentialsProvider).setBranch(article.getRepository().getBranch()).setDirectory(directory.toFile()).setURI(repository.getHttpUrl()).call();
        copyFiles(prepareDirectory, directory);
        // add everything
        git.add().addFilepattern(".").call();
        Map<String, Object> props = context.fullProps();
        context.getModel().getRelease().getGitService().fillProps(props, context.getModel());
        // setup commit
        context.getLogger().debug(RB.$("repository.commit.setup"));
        CommitCommand commitCommand = git.commit().setAll(true).setMessage(article.getRepository().getResolvedCommitMessage(props)).setAuthor(article.getCommitAuthor().getName(), article.getCommitAuthor().getEmail());
        commitCommand.setCredentialsProvider(credentialsProvider);
        commitCommand = commitCommand.setSign(gitService.isSign()).setSigningKey("**********").setGpgSigner(new JReleaserGpgSigner(context, gitService.isSign()));
        commitCommand.call();
        context.getLogger().info(RB.$("repository.push"), article.getRepository().getCanonicalRepoName());
        // push commit
        context.getLogger().debug(RB.$("repository.commit.push"));
        git.push().setDryRun(false).setPushAll().setCredentialsProvider(credentialsProvider).call();
    } catch (Exception e) {
        throw new AnnounceException(RB.$("ERROR_unexpected_repository_update", article.getRepository().getCanonicalRepoName()), e);
    }
}
Also used : Path(java.nio.file.Path) Repository(org.jreleaser.model.releaser.spi.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Git(org.eclipse.jgit.api.Git) GitService(org.jreleaser.model.GitService) CommitCommand(org.eclipse.jgit.api.CommitCommand) JReleaserGpgSigner(org.jreleaser.sdk.git.JReleaserGpgSigner) IOException(java.io.IOException) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with JReleaserGpgSigner

use of org.jreleaser.sdk.git.JReleaserGpgSigner in project jreleaser by jreleaser.

the class AbstractRepositoryPackagerProcessor method doPublishDistribution.

protected void doPublishDistribution(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
    RepositoryTap tap = packager.getRepositoryTap();
    if (!tap.isEnabled()) {
        context.getLogger().info(RB.$("repository.disabled"), tap.getCanonicalRepoName());
        return;
    }
    context.getLogger().info(RB.$("repository.setup"), tap.getCanonicalRepoName());
    if (context.isDryrun()) {
        return;
    }
    GitService gitService = context.getModel().getRelease().getGitService();
    try {
        // get the repository
        context.getLogger().debug(RB.$("repository.locate"), tap.getCanonicalRepoName());
        Repository repository = context.getReleaser().maybeCreateRepository(tap.getOwner(), tap.getResolvedName(), resolveGitToken(gitService));
        UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(resolveGitUsername(gitService), resolveGitToken(gitService));
        // clone the repository
        context.getLogger().debug(RB.$("repository.clone"), repository.getHttpUrl());
        Path directory = Files.createTempDirectory("jreleaser-" + tap.getResolvedName());
        Git git = Git.cloneRepository().setCredentialsProvider(credentialsProvider).setBranch(tap.getBranch()).setDirectory(directory.toFile()).setURI(repository.getHttpUrl()).call();
        prepareWorkingCopy(props, directory, distribution);
        // add everything
        git.add().addFilepattern(".").call();
        props.putAll(distribution.props());
        context.getModel().getRelease().getGitService().fillProps(props, context.getModel());
        // setup commit
        context.getLogger().debug(RB.$("repository.commit.setup"));
        CommitCommand commitCommand = git.commit().setAll(true).setMessage(packager.getRepositoryTap().getResolvedCommitMessage(props)).setAuthor(packager.getCommitAuthor().getName(), packager.getCommitAuthor().getEmail());
        commitCommand.setCredentialsProvider(credentialsProvider);
        boolean signingEnabled = gitService.isSign();
        String signingKey = "**********";
        JReleaserGpgSigner signer = new JReleaserGpgSigner(context, signingEnabled);
        commitCommand = commitCommand.setSign(signingEnabled).setSigningKey(signingKey).setGpgSigner(signer);
        commitCommand.call();
        String tagName = tap.getResolvedTagName(props);
        context.getLogger().debug(RB.$("git.releaser.repository.tag"), tagName);
        git.tag().setSigned(signingEnabled).setSigningKey(signingKey).setGpgSigner(signer).setName(tagName).setForceUpdate(true).call();
        context.getLogger().info(RB.$("repository.push"), tap.getCanonicalRepoName());
        // push commit
        context.getLogger().debug(RB.$("repository.commit.push"));
        git.push().setDryRun(false).setPushAll().setCredentialsProvider(credentialsProvider).setPushTags().call();
    } catch (Exception e) {
        throw new PackagerProcessingException(RB.$("ERROR_unexpected_repository_update", tap.getCanonicalRepoName()), e);
    }
}
Also used : RepositoryTap(org.jreleaser.model.RepositoryTap) Path(java.nio.file.Path) Repository(org.jreleaser.model.releaser.spi.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) GitService(org.jreleaser.model.GitService) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) CommitCommand(org.eclipse.jgit.api.CommitCommand) JReleaserGpgSigner(org.jreleaser.sdk.git.JReleaserGpgSigner) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 CommitCommand (org.eclipse.jgit.api.CommitCommand)2 Git (org.eclipse.jgit.api.Git)2 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)2 GitService (org.jreleaser.model.GitService)2 Repository (org.jreleaser.model.releaser.spi.Repository)2 JReleaserGpgSigner (org.jreleaser.sdk.git.JReleaserGpgSigner)2 RepositoryTap (org.jreleaser.model.RepositoryTap)1 AnnounceException (org.jreleaser.model.announcer.spi.AnnounceException)1 PackagerProcessingException (org.jreleaser.model.packager.spi.PackagerProcessingException)1 JReleaserException (org.jreleaser.util.JReleaserException)1