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

Switch to SSH transport #463

Merged
merged 1 commit into from
Dec 17, 2024
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
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

### Plugins Directory ###
test-plugins

### Log file ###
logs/

### IntelliJ IDEA ###
.idea/
!.idea/runConfigurations/
!.idea/.gitignore/
*.iws
*.iml
*.ipr
Expand All @@ -34,6 +33,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

!**/test/resources/**/.git

### VS Code ###
.vscode/

Expand Down
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@Library('pipeline-library@pull/893/head') _

// While this isn't a plugin, it is much simpler to reuse the pipeline code for CI
// allowing easy windows / linux testing and producing incrementals
// the only feature that buildPlugin has that relates to plugins is allowing you to test against multiple jenkins versions
buildPlugin(
useContainerAgent: false,
useArtifactCachingProxy: false,
configurations: [
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 21],
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ From there you need to save both ID of installation (found on URL)

## Global option

- `--debug` or `-d`: (optional) Enables debug mode. Defaults to false.
- `--debug`: (optional) Enables debug mode. Defaults to false.


- `--cache-path` or `-c`: (optional) Custom path to the cache directory. Defaults to `${user.home}/.cache/jenkins-plugin-modernizer-cli`.
- `--cache-path`: (optional) Custom path to the cache directory. Defaults to `${user.home}/.cache/jenkins-plugin-modernizer-cli`.


- `--maven-home` or `-m`: (optional) Path to the Maven home directory. Required if both `MAVEN_HOME` and `M2_HOME` environment variables are not set. The minimum required version is 3.9.7.
- `--maven-home`: (optional) Path to the Maven home directory. Required if both `MAVEN_HOME` and `M2_HOME` environment variables are not set. The minimum required version is 3.9.7.


- `--clean-local-data` (optional) Deletes the local plugin directory before running the tool.
Expand Down
1 change: 1 addition & 0 deletions plugin-modernizer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<include>**/*ITCase.java</include>
</includes>
<environmentVariables>
<MAVEN_LOCAL_REPO>${maven.repo.local}</MAVEN_LOCAL_REPO>
<MAVEN_HOME>${project.build.directory}/apache-maven-${maven.version}</MAVEN_HOME>
<GH_TOKEN>fake-token</GH_TOKEN>
<GH_OWNER>fake-owner</GH_OWNER>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand All @@ -27,6 +29,14 @@ public class BuildMetadataCommand implements ICommand {
@CommandLine.ArgGroup(exclusive = true, multiplicity = "1")
private PluginOptions pluginOptions;

/**
* Path to the authentication key in case of private repo
*/
@CommandLine.Option(
names = {"--ssh-private-key"},
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;

/**
* Global options for all commands
*/
Expand All @@ -44,12 +54,21 @@ public Config setup(Config.Builder builder) {
options.config(builder);
envOptions.config(builder);
pluginOptions.config(builder);
return builder.withRecipe(Settings.FETCH_METADATA_RECIPE).build();
return builder.withSshPrivateKey(sshPrivateKey)
.withRecipe(Settings.FETCH_METADATA_RECIPE)
.build();
}

@Override
public Integer call() throws Exception {
public Integer call() {
PluginModernizer modernizer = getModernizer();
try {
modernizer.validate();
} catch (ModernizerException e) {
LOG.error("Validation error");
LOG.error(e.getMessage());
return 1;
}
modernizer.start();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand Down Expand Up @@ -53,7 +55,13 @@ public Integer call() throws Exception {
try {
modernizer.validate();
LOG.info("GitHub owner: {}", modernizer.getGithubOwner());
if (Files.isRegularFile(Path.of(modernizer.getSshPrivateKeyPath()))) {
LOG.info("SSH key path: {}", modernizer.getSshPrivateKeyPath());
} else {
LOG.info("SSH key not set. Will use GitHub token for Git operation");
}
LOG.info("Maven home: {}", modernizer.getMavenHome());
LOG.info("Maven local repository: {}", modernizer.getMavenLocalRepo());
LOG.info("Maven version: {}", modernizer.getMavenVersion());
LOG.info("Java version: {}", modernizer.getJavaVersion());
LOG.info("Cache path: {}", modernizer.getCachePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
import java.nio.file.Path;
import picocli.CommandLine;

/**
Expand All @@ -15,6 +16,14 @@
commandListHeading = "%nCommands:%n")
public class GitHubOptions implements IOption {

/**
* Path to the authentication key
*/
@CommandLine.Option(
names = {"--ssh-private-key"},
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;

@CommandLine.Option(
names = {"-g", "--github-owner"},
description = "GitHub owner for forked repositories.")
Expand Down Expand Up @@ -46,6 +55,7 @@ public void config(Config.Builder builder) {
builder.withGitHubOwner(githubOwner)
.withGitHubAppId(githubAppId)
.withGitHubAppSourceInstallationId(githubAppSourceInstallationId)
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId);
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId)
.withSshPrivateKey(sshPrivateKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@
public class GlobalOptions implements IOption {

@CommandLine.Option(
names = {"-d", "--debug"},
names = {"--debug"},
description = "Enable debug logging.")
public boolean debug;

@CommandLine.Option(
names = {"-c", "--cache-path"},
names = {"--cache-path"},
description = "Path to the cache directory.")
public Path cachePath = Settings.DEFAULT_CACHE_PATH;

@CommandLine.Option(
names = {"-m", "--maven-home"},
names = {"--maven-home"},
description = "Path to the Maven Home directory.")
public Path mavenHome = Settings.DEFAULT_MAVEN_HOME;

@CommandLine.Option(
names = {"--maven-local-repo"},
description = "Path to the Maven local repository.")
public Path mavenLocalRepo = Settings.DEFAULT_MAVEN_LOCAL_REPO;

/**
* Create a new config build for the global options
*/
Expand All @@ -45,7 +50,8 @@ public void config(Config.Builder builder) {
!cachePath.endsWith(Settings.CACHE_SUBDIR)
? cachePath.resolve(Settings.CACHE_SUBDIR)
: cachePath)
.withMavenHome(mavenHome);
.withMavenHome(mavenHome)
.withMavenLocalRepo(mavenLocalRepo);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions plugin-modernizer-cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@
<logger name="java.lang.ProcessBuilder" level="WARN" />
<logger name="java.lang.Shutdown" level="WARN" />
<logger name="java.lang.Runtime" level="WARN" />
<logger name="org.eclipse.jgit.internal.storage.file" level="INFO" />
<logger name="org.eclipse.jgit.internal.util" level="INFO" />
<logger name="org.apache.mina.core" level="WARN" />
<logger name="org.apache.sshd.client" level="WARN" />
<logger name="org.apache.sshd.client.keyverifier" level="ERROR" />
<logger name="org.apache.sshd.common" level="WARN" />
<logger name="org.apache.sshd.git.transport" level="WARN" />
<logger name="org.eclipse.jgit.internal" level="WARN" />
<logger name="org.eclipse.jgit.transport" level="INFO" />
<logger name="org.eclipse.jgit.util" level="INFO" />
<logger name="sun.net.www.protocol.http" level="INFO" />
Expand Down
Loading
Loading