Skip to content

Feature/ssh #20

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

Merged
merged 7 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ spotlessChangelog { // all defaults
commitMessage 'Published release/{{version}}' // {{version}} will be replaced
remote 'origin'
branch 'main'
// default value is false, but if you set it to true, then it will
// disable ssh host key checking (.ssh/known_hosts).
// Can also set by command line arg `-PsshDisableStrictHostKeyChecking`.
sshDisableStrictHostKeyChecking false
}

// last version parsed from changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void checkCanPush() throws GitAPIException, IOException {
}
push(cfg.branch, RemoteRefUpdate.Status.UP_TO_DATE);
} catch (GitAPIException e) {
throw new IllegalArgumentException("You can set user/pass with any of these environment variables: " + envVars(), e);
throw new IllegalArgumentException("You can set user/pass with any of these environment variables: " + envVars() + ", or try -PsshDisableStrictHostKeyChecking on ssh remotes", e);
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ private void push(Consumer<PushCommand> cmd, RemoteRefUpdate.Status expected) th
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("StrictHostKeyChecking", cfg.disableStrictHostKeyChecking ? "no" : "yes");
}
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 DiffPlug
* Copyright (C) 2019-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ public class GitCfg {
public String commitMessage = "Published release/" + COMMIT_MESSAGE_VERSION;
public String remote = "origin";
public String branch = "main";
public boolean disableStrictHostKeyChecking = false;

/** Returns an api configured with this config. */
public GitActions withChangelog(File changelogFile, ChangelogAndNext model) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 DiffPlug
* Copyright (C) 2019-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,7 @@ public ChangelogExtension(Project project) {
/**
* Parses the changelog and calculates the next version. Once this
* has been done, the user can't change the configuration at all.
* Use {@link #assertNotCalculatedYet()} on every mutation to check for this.
* Use {@link #assertNotCalculatedYet()} on every mutation to check for this.
*/
ChangelogAndNext model() {
if (model == null) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public void versionSchema(Class<? extends NextVersionFunction> functionClass) th
* If any of these strings are found in the `## [Unreleased]` section, then the
* next version will bump the `added` place in `breaking.added.fixed` (unless
* overruled by `ifFoundBumpBreaking`).
*
*
* Default value is `['### Added']`
*/
public void ifFoundBumpAdded(List<String> toFind) {
Expand All @@ -139,7 +139,7 @@ public void ifFoundBumpAdded(String... toFind) {
/**
* If any of these strings are found in the `## [Unreleased]` section, then the
* next version will bump the `breaking` place in `breaking.added.fixed`.
*
*
* Default value is `['**BREAKING**']`.
*/
public void ifFoundBumpBreaking(List<String> toFind) {
Expand All @@ -163,7 +163,7 @@ public void forceNextVersion(String forceNextVersion) {
* appended to the end, unless you add `-Prelease=true` to the gradle command line.
* Essentially, it asks like a gun safety where all versions are nerfed to `-SNAPSHOT`,
* until you allow a release by adding `-Prelease`.
*
*
* Enabling this mode should look like this in your buildscript: `appendDashSnapshotUnless_dashPrelease=true`
*/
public void setAppendDashSnapshotUnless_dashPrelease(boolean appendSnapshot) {
Expand All @@ -172,6 +172,17 @@ public void setAppendDashSnapshotUnless_dashPrelease(boolean appendSnapshot) {
}
}

/**
* If you set this to true, then the ssh host key checking over ssh:// remotes will be disabled.
* By default strict host key checking is enabled. Make sure that there is an entry
* in know_hosts file for given ssh remote.
* You can also add `-PsshDisableStrictHostKeyChecking` to the gradle command.
* In your buildscript you can disable checking with `sshDisableStrictHostKeyChecking = true`
*/
public void setSshDisableStrictHostKeyChecking(boolean disableStrictHostKeyChecking) {
gitCfg.disableStrictHostKeyChecking = disableStrictHostKeyChecking;
}

// tag and push
/** Default value is `release/` */
public void tagPrefix(String tagPrefix) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 DiffPlug
* Copyright (C) 2019-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,7 @@ public void apply(Project project) {

ChangelogExtension extension = project.getExtensions().create(ChangelogExtension.NAME, ChangelogExtension.class, project);
project.getTasks().register(PrintTask.NAME, PrintTask.class, extension);
extension.gitCfg.disableStrictHostKeyChecking = project.getRootProject().findProperty("sshDisableStrictHostKeyChecking") != null;

TaskProvider<CheckTask> check = project.getTasks().register(CheckTask.NAME, CheckTask.class, extension);
TaskProvider<BumpTask> bump = project.getTasks().register(BumpTask.NAME, BumpTask.class, extension);
Expand Down