Giter Site home page Giter Site logo

gradle / wrapper-upgrade-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW
43.0 14.0 17.0 1001 KB

Gradle plugin that detects and updates Gradle and Maven wrappers to the latest Gradle and Maven version.

License: Apache License 2.0

Java 56.25% Groovy 43.75%
gradle maven wrapper gradle-bt gradle-bt-core-runtime

wrapper-upgrade-gradle-plugin's Introduction

Wrapper Upgrade Gradle Plugin

Verify Build Plugin Portal Revved up by Gradle Enterprise

The Wrapper Upgrade Gradle Plugin creates tasks to upgrade the Gradle Wrapper for target projects hosted on GitHub.

Usage

Apply the plugin to a dedicated project and configure which project needs to be upgraded. Example:

Kotlin DSL
plugins {
    id("base")
    id("org.gradle.wrapper-upgrade") version "0.11.1"
}

wrapperUpgrade {
    gradle {
        register("some-gradle-project") {
            repo.set("my-org/some-gradle-project")
            baseBranch.set("release")
        }
        register("some-samples-gradle-project") {
            repo.set("my-org/some-samples-gradle-project")
            dir.set("samples")
        }
    }

    maven {
        register("some-maven-project") {
            repo.set("my-org/some-maven-project")
            baseBranch.set("release")
        }
        register("some-samples-maven-project") {
            repo.set("my-org/some-samples-maven-project")
            baseBranch.set("samples")
        }
    }
}
Groovy DSL
plugins {
    id 'base'
    id 'org.gradle.wrapper-upgrade' version '0.11.4'
}

wrapperUpgrade {
    gradle {
        'some-gradle-project' {
            repo = 'my-org/some-gradle-project'
            baseBranch = 'release'
        }
        'some-samples-gradle-project' {
            repo = 'my-org/some-samples-gradle-project'
            dir = 'samples'
        }
    }

    maven {
        'some-maven-project' {
            repo = 'my-org/some-maven-project'
            baseBranch = 'release'
        }
        'some-samples-maven-project' {
            repo = 'my-org/some-samples-maven-project'
            dir = 'samples'
        }
    }
}

This will create one task per configured project and 2 aggregating tasks: upgradeGradleWrapperAll and upgradeMavenWrapperAll that will run all the specific tasks.

Running ./gradlew upgradeGradleWrapperXXX will:

  • clone the project XXX in build/git-clones
  • run in the cloned project ./gradlew wrapper --gradle-version=<latest_gradle_version>
  • run a second time ./gradlew wrapper --gradle-version=<latest_gradle_version>
  • If changes occurred
    • create a specific branch
    • commit and push the branch
    • create a pull request on GitHub, it requires a GitHub personal access token (PAT), passed with WRAPPER_UPGRADE_GIT_TOKEN environment variable. This token is used to get the existing PRs on the repo and create one if needed, hence it requires:
      • the repo scope for a classic PAT
      • read-write permissions for "Pull requests" on the relevant repos for a fine-grained PAT

Note that a check is done first to make sure the branch does not exist yet. That way you can run upgradeGradleWrapperAll and upgradeMavenWrapperAll periodically with a cron, CI job... a bit like dependabot does for upgrading libs.

Running upgradeMavenWrapperXXX will do the same, executing ./mvnw wrapper:wrapper -Dmaven=<latest_maven_version> instead.

Configuration

wrapperUpgrade {
    <gradle|maven> {
        name {
            repo = ...
            baseBranch = ...
            dir = ...
            options {
                gitCommitExtraArgs = [...]
                allowPreRelease = [...]
            }
        }
    }
}
Field description
name A name identifying the upgrade, it can be different from the project name, for example when you need to upgrade multiple gradle projects in the same git project
repo The GitHub repository to clone, format 'organization/project`
dir The directory inside the project base directory to run the gradle or maven upgrade in
baseBranch The git branch to checkout and that the pull request will target
options.gitCommitExtraArgs List of additional git commit arguments
options.allowPreRelease Boolean: true will get the latest Maven/Gradle version even if it's a pre-release. Default is false.

License

The Wrapper Upgrade Gradle Plugin is open-source software released under the Apache 2.0 License.

wrapper-upgrade-gradle-plugin's People

Contributors

alextu avatar bigdaz avatar bot-githubaction avatar c00ler avatar cdsap avatar clayburn avatar dependabot[bot] avatar erichaagdev avatar etiennestuder avatar github-actions[bot] avatar guylabs avatar jprinet avatar runningcode avatar stefma avatar tylerbertrand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wrapper-upgrade-gradle-plugin's Issues

Delete the branch when PR is merged

Is it possible to somehow make the plugin delete the created branch when the PR gets merged? I have a suspicion that it can only be achieved with a GitHub App.

What permissions are required for the `WRAPPER_UPGRADE_GIT_TOKEN`

The Readme states:

create a pull request on Github, it requires a Github access token, passed with WRAPPER_UPGRADE_GIT_TOKEN environment variable.

As users don't want to give the token more permissions as needed it make sense to document which exact permissions are needed for the PAT (personal access token)

Running locally produces "fatal: could not read Username"

Good work on this plugin! I'm just taking it for a spin...

When I setup the plugin in a project.

plugins {
    id 'base'
    id 'org.gradle.wrapper-upgrade' version '0.10.1'
}
wrapperUpgrade {
    gradle {
        'spring-boot-api-example' {
            repo = 'tkgregory/spring-boot-api-example'
            baseBranch = 'master'
        }
    }
}

And run on Ubuntu:

WRAPPER_UPGRADE_GIT_TOKEN=<my-secret-here> ./gradlew clean upgradeGradleWrapperAll --info --stacktrace

I get this error:

Starting process 'command 'git''. Working directory: /mnt/c/workspace/gradle-wrapper-update-example/build/git-clones/spring-boot-api-example Command: git push --quiet -u origin wrapperbot/spring-boot-api-example/gradle-wrapper-7.4.2
Successfully started process 'command 'git''
fatal: could not read Username for 'https://github.com/tkgregory/spring-boot-api-example.git': No such device or address

When I run git push myself from the directory and enter username/token combo it works as expected. I think the error is because Git doesn't know the username.

Should there be a way to specify username as well as token? 🤔

Task configuration in `README` is missleading

Hello togehter 👋

in your readme you have the section "Task configuration":
Screenshot 2023-05-16 at 8 06 30 AM

IMHO this is a bit of missleading. As consumers don't get in touch with any task here, right?
Instead, they setup the plugin extension.
So it would be rather Extension configuration.
But I think this is also not good.
I thought more into the direction of Configure the plugin or just Configuration...

What do you think? 🤔

User can read release notes in the plugin portal

We should use the description field of the plugin declaration to specify release notes. Currently, it is always a static string.

The description field is shown on the plugin portal for each published version. Setting the description field to release notes means they can be seen directly in the plugin portal, rather than only on GitHub. This makes release notes and changes much more discoverable for users wanting to update.

An example of this can be seen on the plugin portal page for com.gradle.plugin-publish: https://plugins.gradle.org/plugin/com.gradle.plugin-publish

Wrapper upgrades PRs doesn't run any tests

See for example this PR:
#188

It checks only the DCO but don't execute other tests.

This is because the PR were created by an GH Action using the build in secrets.GITHUB_TOKEN.
See

and
WRAPPER_UPGRADE_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I guess it make sense that also the bump wrapper PRs run all of the existing tests.

To do this, one option is to provide another secret (from another user) and invite them to this repository as a collaborator with write access. Then using this secret inside the action.
The user will then create the pull requests, instead of the "GitHub Action Bot".

You might want to use your bot-githubaction user for that? 😁

`register` does not work. But `create` works.

This is also in the readme:

wrapperUpgrade {
    gradle {
        register("some-gradle-project") {
            repo.set("my-org/some-gradle-project")
            baseBranch.set("release")
        }
        register("some-samples-gradle-project") {
            repo.set("my-org/some-samples-gradle-project")
            dir.set("samples")
        }
    }
}

But register will not work. It seems the plugin is too late to catch it.
However, create will work.

I'm not sure if this needs to be fixed in the plugin itself or in the readme 🤔

I also ask myself, why does this not matter in the Groovy version 🙃

PRs that would replace another PR are not automatically closed.

Given:

  • An already existing bump wrapper PR from version 8.4 to 8.5
  • A new bump wrapper PR got open from version 8.4 to 8.6

The first PR stay open and will not automatically closed (and the branch deleted).

I guess it would be nice if this is supported 🙃

Do not run `wrapper` task in case there is no upgrade available

I noticed that this plugin will always running the wrapper tasks, regarding of if there is an upgrade available.
However, the plugin nows already if there is an upgrade available.

private static VersionInfo getLatestBuildToolVersion(BuildToolStrategy buildToolStrategy, boolean allowPreRelease, VersionInfo usedBuildToolVersion) throws IOException {
VersionInfo latestBuildToolVersion = buildToolStrategy.lookupLatestVersion(allowPreRelease);
if (VersionNumber.parse(usedBuildToolVersion.version)
.compareTo(VersionNumber.parse(latestBuildToolVersion.version)) >= 0) {
return usedBuildToolVersion;
} else {
return latestBuildToolVersion;
}
}

Here it checks for the current release. If there is no upgrade available, it just returns *the * version (that is, usedBuildToolVersion).

Then it will only use that version to run the wrapper task. Whether if it is the same version or not.

Params params = Params.create(upgrade, buildToolStrategy, allowPreRelease, layout.getProjectDirectory(), getCheckoutDir().get(), gitHub, execOperations);
if (!prExists(params)) {
createPrIfWrapperUpgradeAvailable(params);

private void createPrIfWrapperUpgradeAvailable(Params params) throws IOException {
runWrapperWithLatestBuildToolVersion(params);
createPrIfWrapperChanged(params);
}
private void runWrapperWithLatestBuildToolVersion(Params params) {
buildToolStrategy.runWrapper(execOperations, params.rootProjectDir, params.latestBuildToolVersion);
buildToolStrategy.runWrapper(execOperations, params.rootProjectDir, params.latestBuildToolVersion);
}

I guess it makes sense to avoid this. It is an unnecessary waste of resources.
Especially since you also recommend running this periodically in the readme:

Note that a check is done first to make sure the branch does not exist yet. That way you can run `upgradeGradleWrapperAll` and `upgradeMavenWrapperAll` periodically with a cron, CI job... a bit like dependabot does for upgrading libs.

In case there is no higher version than the current version, just skip the task execution and thats it 🤷

Created tasks doesn't show up in `tasks` overview

When you run gradle tasks, only the aggregated tasks will show up:
Screenshot 2023-05-16 at 8 11 18 AM

This is because you don't set the group and description:

TaskProvider<UpgradeWrapper> upgradeTask = project.getTasks().register("upgradeGradleWrapper" + taskNameSuffix, UpgradeWrapper.class, upgrade, BuildToolStrategy.GRADLE);

Maybe this is intended 🤷
But I think it make sense that you show all created tasks in the overview 🙃

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.