# Update the GitHub Actions in a Gradle Build's Workflow

Yes. An agent moves a Gradle workflow off retired checkout, setup-java and cache releases onto gradle/actions and current majors, runs the build and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/update-github-actions/gradle/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the workflow and the build it drives before changing a version, because a Gradle workflow's actions and its JDK have to agree with `build.gradle`. In a project laid out like gothinkster/spring-boot-realworld-example-app, `.github/workflows/gradle.yml` runs on every branch push, on `v*` tags and on pull requests, with one `build` job: `actions/checkout@v2`, `actions/setup-java@v2` with the `zulu` distribution and Java 11, `actions/cache@v2` over `~/.gradle/caches` and `~/.gradle/wrapper` keyed on `hashFiles('**/*.gradle*')`, then `./gradlew clean test`. `build.gradle` applies `org.springframework.boot` 2.6.3, `io.spring.dependency-management` 1.0.11.RELEASE, the DGS codegen plugin 5.0.6 and `com.diffplug.spotless` 6.2.1 with `googleJavaFormat()`, sets `sourceCompatibility` to 11, and its `clean` task deletes the `dev.db` SQLite file the tests write. `gradle/wrapper/gradle-wrapper.properties` points at Gradle 7.4, and `src/test` holds 23 JUnit classes including `DbTestBase`, `ArticleQueryServiceTest` and `MyBatisCommentRepositoryTest`. `README.md` says Java 11 is required and lists `./gradlew test` and `./gradlew spotlessJavaApply`.

The agent then checks each action against its repository with `gh api`. `actions/checkout` is at v7, `actions/setup-java` at v6 and `actions/cache` at v6, and the v2 releases of all three run on Node.js runtimes GitHub's hosted runners have retired. `gradle/actions` is at v6 and carries `setup-gradle`, `wrapper-validation` and `dependency-submission` as sub-actions, while the older `gradle/wrapper-validation-action` repository is archived. The `setup-gradle` action caches Gradle's user home by default, writes to the cache only from jobs on the default branch unless `cache-read-only` says otherwise, and works with an existing `./gradlew` run step, so it replaces the hand-written `actions/cache` block rather than sitting beside it.

The new `gradle.yml` keeps the triggers and the one job. `actions/checkout@v7` with `persist-credentials: false`; `actions/setup-java@v6` with `distribution: zulu` and `java-version: '11'` unchanged, because moving the JDK vendor or version is a build change and not an actions update; `gradle/actions/wrapper-validation@v6` before anything runs the wrapper, so a tampered `gradle-wrapper.jar` fails the job; `gradle/actions/setup-gradle@v6` in place of the cache step; and the same `./gradlew clean test`. A `permissions: contents: read` block is added at the top, since the workflow writes nothing. Each `uses` line is pinned to the release's commit SHA with the tag in a trailing comment, read from the tag with `gh api`, so Dependabot can bump it. A new `.github/dependabot.yml` with the `github-actions` ecosystem on a weekly schedule keeps the pins moving after the pull request, and a `gradle` ecosystem entry is offered in the description but not added.

Proof comes from running what the job runs. The agent installs a Java 11 JDK in its sandbox, runs `./gradlew --version` to confirm the 7.4 wrapper starts on it, then `./gradlew clean test` and keeps the test summary, and runs `./gradlew spotlessJavaCheck` to show the formatting task the README names still passes, without adding it to the workflow. It runs `actionlint` on the new file to catch a misspelt input or an expression error before GitHub does, and `gh api` once more on each pinned SHA to show it resolves to the tag in the comment. The old `actions/cache` keys are gone, so the first run on the default branch after merging warms the new cache; the pull request says so.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Update the GitHub Actions used by this Gradle project's workflow. Read .github/workflows/gradle.yml, build.gradle, gradle/wrapper/gradle-wrapper.properties and README.md first, and check each action's current major with gh api. Move actions/checkout, actions/setup-java and actions/cache to their current majors, replace the hand-written Gradle cache step with gradle/actions/setup-gradle, add gradle/actions/wrapper-validation before the build, keep the JDK distribution and version the build declares, add a read-only permissions block, pin every action to its release commit SHA with the tag in a comment, and add a dependabot.yml for the github-actions ecosystem. Install the JDK the build needs, run ./gradlew --version, ./gradlew clean test and ./gradlew spotlessJavaCheck, run actionlint on the workflow, then open a pull request that lists each action's old and new version and says the Gradle cache will warm on the first default-branch run.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that changes `.github/workflows/gradle.yml` and adds `.github/dependabot.yml`. The description has a table of each action with the version the workflow had and the one it has now, the `./gradlew clean test` summary from the sandbox, the `spotlessJavaCheck` result and the `actionlint` output, and a note that the first run on the default branch rebuilds the Gradle cache under the new action's keys.

Because the workflow runs on pull requests, the updated job runs on the pull request itself, so a reviewer sees `wrapper-validation`, `setup-gradle` and the test step pass on GitHub's runner with the new pins before merging. The run's record keeps the `gh api` calls that resolved each tag, the JDK install and the three Gradle runs, so a reviewer can trace every version in the table to the call that produced it.

Before merging, a reviewer decides whether to accept Dependabot's weekly cadence, whether to add the `gradle` ecosystem to it, and whether a later pull request should move the JDK to a supported release, which the agent leaves out on purpose. The agent changes nothing under `src` and nothing in `build.gradle`.

## Run it on every Monday morning

An automation in the Project with a `schedule` trigger, a `cron` of `0 8 * * 1` in your `timezone` and this prompt starts one run a week on each repository with a Gradle workflow. A run that finds every action already on its current major ends without opening a pull request and says so in its result, so a quiet week costs one short run and no review. The automation's `max_runs_per_hour` bounds how many repositories it touches at once.

A team that wants the check at the moment a release lands instead starts the run from its own server: one `POST /o/{org}/sessions` with the repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name and the week, so a retried call returns the run already started rather than a second pull request.

## Why run it on Rush?

An actions bump done by editing version numbers goes wrong where the diff looks right: a cache step kept beside `setup-gradle` that doubles the cache writes, a SHA pinned to the wrong tag, a `wrapper-validation` step placed after the first `./gradlew` call so it validates nothing, or a JDK quietly changed with the action. The agent resolves each tag with `gh api`, runs the real build on the JDK the project declares and lints the workflow in its sandbox before it opens the pull request.

Every command stays with the run, from each `gh api` call to the test summary, and the pull request quotes them. Updating the workflows of a dozen Gradle services at once costs no more attention than one, because each run has its own machine, its own record and its own pull request.

## Frequently asked questions

### Why replace actions/cache instead of bumping it?

The hand-written cache block keys `~/.gradle/caches` and `~/.gradle/wrapper` on every `*.gradle*` file, which invalidates the whole cache on any build change and never evicts stale entries. `gradle/actions/setup-gradle` caches Gradle's user home with its own keys, writes from the default branch only unless `cache-read-only` is changed, and needs no key expression, so the workflow gets shorter and the cache behaves better. A bumped `actions/cache` would keep the old behaviour.

### Does this change the JDK?

No. `build.gradle` sets `sourceCompatibility` to 11 and the README says Java 11, so the agent keeps `distribution: zulu` and `java-version: '11'` on `actions/setup-java@v6`, which still installs that release. Moving to a newer JDK would also need a newer Spring Boot and Gradle, which is a separate pull request the description points to.

### Why pin to commit SHAs when the tags work?

A tag can be moved and a SHA cannot, so a pinned SHA guarantees the job runs the code that was reviewed. The tag stays in a trailing comment on each `uses` line, which is the format Dependabot reads to propose the next bump, so pinning costs nothing in maintenance once `dependabot.yml` is in place.

### What does wrapper validation add?

It checks the checksum of `gradle/wrapper/gradle-wrapper.jar` against Gradle's published list before the job runs it, so a wrapper replaced in a pull request fails the check instead of executing. The archived `gradle/wrapper-validation-action` did the same; the agent uses the `wrapper-validation` sub-action of `gradle/actions` because that repository is maintained.

## More Gradle jobs

- [Upgrade Gradle Dependencies Weekly for a Spring Boot App](https://getrush.ai/run/upgrade-gradle-dependencies/gradle/)
- [Add CodeQL Scanning to a Gradle Project](https://getrush.ai/run/add-codeql-scanning/gradle/)
- [Enable the Gradle Configuration Cache for a Spring Boot Build](https://getrush.ai/run/add-configuration-cache/gradle/)

## The same job on other stacks

- [Update the GitHub Actions in a Helm Chart Repository](https://getrush.ai/run/update-github-actions/helm/)
- [Update the GitHub Actions in a Node.js Repository's Workflows](https://getrush.ai/run/update-github-actions/nodejs/)
- [Update Pinned GitHub Actions in a Rust Repo](https://getrush.ai/run/update-github-actions/rust/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
