Autoconfigure a Java runtime

This commit is contained in:
Andres Almiray 2022-01-02 18:49:24 +01:00
parent 1be32a4768
commit f4b19f681f
No known key found for this signature in database
GPG key ID: CCC55C5167419ADB
2 changed files with 29 additions and 20 deletions

View file

@ -34,9 +34,10 @@ jobs:
# Configure build steps as you'd normally do # Configure build steps as you'd normally do
- name: Setup Java - name: Setup Java
uses: actions/setup-java@v1 uses: actions/setup-java@v2
with: with:
java-version: 1.8 java-version: 11
distribution: 'zulu'
server-id: central server-id: central
server-username: MAVEN_USERNAME server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN server-password: MAVEN_CENTRAL_TOKEN
@ -56,17 +57,10 @@ jobs:
git config user.email "${{ github.event.head_commit.committer.email }}" git config user.email "${{ github.event.head_commit.committer.email }}"
mvn -B --file pom.xml release:prepare release:perform mvn -B --file pom.xml release:prepare release:perform
# IMPORTANT!
- name: Setup Java for JReleaser
uses: actions/setup-java@v1
with:
java-version: 11
# Create a release # Create a release
- name: Run JReleaser - name: Run JReleaser
uses: jreleaser/release-action@v1 uses: jreleaser/release-action@v2
env: env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
---- ----
@ -74,11 +68,12 @@ jobs:
WARNING: Note the `fetch-depth: 0` option on the `Checkout` workflow step. It is required for JReleaser to work properly. WARNING: Note the `fetch-depth: 0` option on the `Checkout` workflow step. It is required for JReleaser to work properly.
Without that, JReleaser might fail or behave incorrectly. Without that, JReleaser might fail or behave incorrectly.
The last step executes a `full-release` with the default `jreleaser.yml` configuration that's expected The last step executes a `full-release` with the default `jreleaser.yml` configuration that's expected to be located at
to be located at the root of the repository. the root of the repository.
IMPORTANT: This action requires Java 11+ to download and execute JReleaser. If your project already builds with Java 11+ IMPORTANT: This action requires Java 11+ to download and execute JReleaser. The action will setup a suitable Java runtime
then you can skip the second "setup" step. automatically. If you would like to use a different Java version/distribution then set the value of `setup-java` to `false`
and make sure you have a previous step with `actions/setup-java` setup as needed.
== Customizing == Customizing
@ -88,14 +83,16 @@ Following inputs can be used as `step.with` keys
[%header,cols="<2,<,<2,<3",width="100%"] [%header,cols="<2,<,<2,<3",width="100%"]
|=== |===
| Name | Type | Default | Description | Name | Type | Default | Description
| version | String | latest | The JReleaser version to use. + | version | String | latest | The JReleaser version to use. +
Should match any of the link:https://github.com/jreleaser/jreleaser/releases[published releases]. + Should match any of the link:https://github.com/jreleaser/jreleaser/releases[published releases]. +
You may use `latest` to pull the latest stable release or + You may use `latest` to pull the latest stable release or +
`early-access` to pull the latest snapshot. `early-access` to pull the latest snapshot.
| arguments | String | full-release | The JReleaser command to run. | arguments | String | full-release | The JReleaser command to run.
| working-directory | String | ${{ github.workspace }} | The directory to change into. + | working-directory | String | ${{ github.workspace }} | The directory to change into. +
Defaults to the directory the calling workflow runs in. Defaults to the directory the calling workflow runs in.
| setup-java | boolean | true | Automatically setup a Java runtime. +
Java runtime defaults to Zulu 17.
|=== |===
== Environment Variables == Environment Variables
@ -122,7 +119,7 @@ If you create a secret named `GH_PAT`, the step will look like this
[source,yaml] [source,yaml]
---- ----
- name: Run JReleaser - name: Run JReleaser
uses: jreleaser/release-action@v1 uses: jreleaser/release-action@v2
env: env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GH_PAT }} JRELEASER_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
---- ----
@ -133,7 +130,7 @@ you may apply the `GH_PAT` token as follows
[source,yaml] [source,yaml]
---- ----
- name: Run JReleaser - name: Run JReleaser
uses: jreleaser/release-action@v1 uses: jreleaser/release-action@v2
env: env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_HOMEBREW_GITHUB_TOKEN: ${{ secrets.GH_PAT }} JRELEASER_HOMEBREW_GITHUB_TOKEN: ${{ secrets.GH_PAT }}

View file

@ -23,9 +23,21 @@ inputs:
default: ${{ github.workspace }} default: ${{ github.workspace }}
description: 'The directory to change into.' description: 'The directory to change into.'
setup-java:
required: false
default: 'true'
description: 'Setup internal Java runtime.'
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- name: 'Setup Java'
uses: actions/setup-java@v2
if: ${{ inputs.setup-java }} == 'true'
with:
java-version: 17
distribution: 'zulu'
- name: 'Download JReleaser' - name: 'Download JReleaser'
shell: bash shell: bash
working-directory: ${{ inputs.working-directory }} working-directory: ${{ inputs.working-directory }}