mirror of
https://github.com/actions/setup-java.git
synced 2026-07-02 18:41:53 +00:00
Compare commits
3 Commits
30a1792946
...
8d131b74d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d131b74d6 | ||
|
|
d0351b4837 | ||
|
|
bfbdaa62d8 |
42
.github/workflows/e2e-publishing.yml
vendored
42
.github/workflows/e2e-publishing.yml
vendored
@ -151,3 +151,45 @@ jobs:
|
||||
if (-not (Test-Path $path)) {
|
||||
throw "settings.xml file is not found in expected location"
|
||||
}
|
||||
test-publishing-multiple-repositories-with-gpg-passphrase:
|
||||
name: Validate settings.xml
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '11'
|
||||
mvn-repositories-len: 2
|
||||
server-id-0: maven-0
|
||||
server-username-0: MAVEN_USERNAME-0
|
||||
server-password-0: MAVEN_CENTRAL_TOKEN-0
|
||||
server-id-1: maven-1
|
||||
server-username-1: MAVEN_USERNAME-1
|
||||
server-password-1: MAVEN_CENTRAL_TOKEN-1
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
||||
- name: Validate settings.xml
|
||||
run: |
|
||||
$xmlPath = Join-Path $HOME ".m2" "settings.xml"
|
||||
Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
|
||||
|
||||
[xml]$xml = Get-Content $xmlPath
|
||||
$servers = $xml.settings.servers.server
|
||||
if (($servers[0].id -ne 'maven-0') -or ($servers[0].username -ne '${env.MAVEN_USERNAME-0}') -or ($servers[0].password -ne '${env.MAVEN_CENTRAL_TOKEN-0}')) {
|
||||
throw "Generated XML file is incorrect"
|
||||
}
|
||||
|
||||
if (($servers[1].id -ne 'maven-1') -or ($servers[0].username -ne '${env.MAVEN_PASSWORD-1}') -or ($servers[1].password -ne '${env.MAVEN_CENTRAL_TOKEN-1}')) {
|
||||
throw "Generated XML file is incorrect"
|
||||
}
|
||||
|
||||
if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
|
||||
throw "Generated XML file is incorrect"
|
||||
}
|
||||
|
||||
36
README.md
36
README.md
@ -23,6 +23,8 @@ This action allows you to work with Java and Scala projects.
|
||||
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK.
|
||||
- V2 requires you to specify distribution along with the version. V1 defaults to Azul Zulu OpenJDK, only version input is required. Follow [the migration guide](docs/switching-to-v2.md) to switch from V1 to V2.
|
||||
|
||||
For information about the latest releases, recent updates, and newly supported distributions, please refer to the `setup-java` [Releases](https://github.com/actions/setup-java/releases).
|
||||
|
||||
## Usage
|
||||
|
||||
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
|
||||
@ -69,8 +71,8 @@ This action allows you to work with Java and Scala projects.
|
||||
#### Eclipse Temurin
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||
java-version: '21'
|
||||
@ -80,8 +82,8 @@ steps:
|
||||
#### Azul Zulu OpenJDK
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'zulu' # See 'Supported distributions' for available options
|
||||
java-version: '21'
|
||||
@ -136,8 +138,8 @@ The cache input is optional, and caching is turned off by default.
|
||||
#### Caching gradle dependencies
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -151,8 +153,8 @@ steps:
|
||||
#### Caching maven dependencies
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -165,8 +167,8 @@ steps:
|
||||
#### Caching sbt dependencies
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -185,8 +187,8 @@ Usually, cache gets downloaded in multiple segments of fixed sizes. Sometimes, a
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -205,8 +207,8 @@ For Java distributions that are not cached on Hosted images, `check-latest` alwa
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -224,9 +226,9 @@ jobs:
|
||||
java: [ '8', '11', '17', '21' ]
|
||||
name: Java ${{ matrix.Java }} sample
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: ${{ matrix.java }}
|
||||
@ -239,7 +241,7 @@ All versions are added to the PATH. The last version will be used and available
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
|
||||
@ -43,9 +43,7 @@ describe('auth tests', () => {
|
||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||
|
||||
await auth.createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
[{id, username, password}],
|
||||
altHome,
|
||||
true
|
||||
);
|
||||
@ -56,7 +54,7 @@ describe('auth tests', () => {
|
||||
expect(fs.existsSync(altHome)).toBe(true);
|
||||
expect(fs.existsSync(altSettingsFile)).toBe(true);
|
||||
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
|
||||
auth.generate(id, username, password)
|
||||
auth.generate([{id, username, password}])
|
||||
);
|
||||
|
||||
await io.rmRF(altHome);
|
||||
@ -68,9 +66,7 @@ describe('auth tests', () => {
|
||||
const password = 'TOKEN';
|
||||
|
||||
await auth.createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
[{id, username, password}],
|
||||
m2Dir,
|
||||
true
|
||||
);
|
||||
@ -78,7 +74,7 @@ describe('auth tests', () => {
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||
auth.generate(id, username, password)
|
||||
auth.generate([{id, username, password}])
|
||||
);
|
||||
}, 100000);
|
||||
|
||||
@ -89,18 +85,15 @@ describe('auth tests', () => {
|
||||
const gpgPassphrase = 'GPG';
|
||||
|
||||
await auth.createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
[{id, username, password, gpgPassphrase}],
|
||||
m2Dir,
|
||||
true,
|
||||
gpgPassphrase
|
||||
true
|
||||
);
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||
auth.generate(id, username, password, gpgPassphrase)
|
||||
auth.generate([{id, username, password, gpgPassphrase}])
|
||||
);
|
||||
}, 100000);
|
||||
|
||||
@ -115,9 +108,7 @@ describe('auth tests', () => {
|
||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||
|
||||
await auth.createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
[{id, username, password}],
|
||||
m2Dir,
|
||||
true
|
||||
);
|
||||
@ -125,7 +116,7 @@ describe('auth tests', () => {
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
||||
auth.generate(id, username, password)
|
||||
auth.generate([{id, username, password}])
|
||||
);
|
||||
}, 100000);
|
||||
|
||||
@ -140,9 +131,7 @@ describe('auth tests', () => {
|
||||
expect(fs.existsSync(settingsFile)).toBe(true);
|
||||
|
||||
await auth.createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
[{id, username, password}],
|
||||
m2Dir,
|
||||
false
|
||||
);
|
||||
@ -169,7 +158,7 @@ describe('auth tests', () => {
|
||||
</servers>
|
||||
</settings>`;
|
||||
|
||||
expect(auth.generate(id, username, password)).toEqual(expectedSettings);
|
||||
expect(auth.generate([{id, username, password}])).toEqual(expectedSettings);
|
||||
});
|
||||
|
||||
it('generates valid settings.xml with additional configuration', () => {
|
||||
@ -194,8 +183,50 @@ describe('auth tests', () => {
|
||||
</servers>
|
||||
</settings>`;
|
||||
|
||||
expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
|
||||
expectedSettings
|
||||
);
|
||||
expect(
|
||||
auth.generate([
|
||||
{id, username, password},
|
||||
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
|
||||
])
|
||||
).toEqual(expectedSettings);
|
||||
});
|
||||
|
||||
it('generates valid settings.xml for multiple repositories', () => {
|
||||
const id0 = 'packages0';
|
||||
const username0 = 'USER0';
|
||||
const password0 = '&<>"\'\'"><&0';
|
||||
const id1 = 'packages1';
|
||||
const username1 = 'USER1';
|
||||
const password1 = '&<>"\'\'"><&1';
|
||||
const gpgPassphrase = 'PASSPHRASE';
|
||||
|
||||
const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<servers>
|
||||
<server>
|
||||
<id>${id0}</id>
|
||||
<username>\${env.${username0}}</username>
|
||||
<password>\${env.&<>"''"><&0}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>${id1}</id>
|
||||
<username>\${env.${username1}}</username>
|
||||
<password>\${env.&<>"''"><&1}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>gpg.passphrase</id>
|
||||
<passphrase>\${env.${gpgPassphrase}}</passphrase>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>`;
|
||||
|
||||
expect(
|
||||
auth.generate([
|
||||
{id: id0, username: username0, password: password0},
|
||||
{id: id1, username: username1, password: password1},
|
||||
{id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase}
|
||||
])
|
||||
).toEqual(expectedSettings);
|
||||
});
|
||||
});
|
||||
|
||||
27
action.yml
27
action.yml
@ -39,6 +39,33 @@ inputs:
|
||||
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
|
||||
required: false
|
||||
default: 'GITHUB_TOKEN'
|
||||
mvn-repositories-len:
|
||||
description: 'Number of Maven repositories being configured - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-id-0:
|
||||
description: 'ID of the first distributionManagement repository in the pom.xml
|
||||
file - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-username-0:
|
||||
description: 'Environment variable name for the username for authentication
|
||||
to the first Maven repository - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-password-0:
|
||||
description: 'Environment variable name for password or token for
|
||||
authentication to the first Maven repository - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-id-1:
|
||||
description: 'ID of the second distributionManagement repository in the pom.xml
|
||||
file - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-username-1:
|
||||
description: 'Environment variable name for the username for authentication
|
||||
to the second Maven repository - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
server-password-1:
|
||||
description: 'Environment variable name for password or token for
|
||||
authentication to the second Maven repository - Only applicable if more than one Maven repository is being configured'
|
||||
required: false
|
||||
settings-path:
|
||||
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
|
||||
required: false
|
||||
|
||||
3
dist/cleanup/index.js
vendored
3
dist/cleanup/index.js
vendored
@ -94435,7 +94435,7 @@ else {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_NUM_MVN_REPOS = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
@ -94444,6 +94444,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||
exports.INPUT_NUM_MVN_REPOS = 'mvn-repositories-len';
|
||||
exports.INPUT_SERVER_ID = 'server-id';
|
||||
exports.INPUT_SERVER_USERNAME = 'server-username';
|
||||
exports.INPUT_SERVER_PASSWORD = 'server-password';
|
||||
|
||||
8678
dist/setup/index.js
vendored
8678
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load Diff
@ -31,8 +31,8 @@ Inputs `java-version` and `distribution` are mandatory and needs to be provided.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
@ -44,8 +44,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'adopt-hotspot'
|
||||
java-version: '11'
|
||||
@ -56,8 +56,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '21'
|
||||
@ -69,8 +69,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'liberica'
|
||||
java-version: '21'
|
||||
@ -82,8 +82,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'microsoft'
|
||||
java-version: '21'
|
||||
@ -97,7 +97,7 @@ steps:
|
||||
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||
|
||||
```yaml
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||
distribution: 'microsoft'
|
||||
@ -111,8 +111,8 @@ If the runner is not able to access github.com, any Java versions requested duri
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'corretto'
|
||||
java-version: '21'
|
||||
@ -124,8 +124,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'oracle'
|
||||
java-version: '21'
|
||||
@ -137,8 +137,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'dragonwell'
|
||||
java-version: '8'
|
||||
@ -149,8 +149,8 @@ steps:
|
||||
**NOTE:** An OpenJDK release maintained and supported by SAP
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'sapmachine'
|
||||
java-version: '21'
|
||||
@ -162,8 +162,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'graalvm'
|
||||
java-version: '21'
|
||||
@ -181,8 +181,8 @@ For example, `11.0.24` is not available but `11.0.16` is.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jetbrains'
|
||||
java-version: '11'
|
||||
@ -194,8 +194,8 @@ GitHub token to the action to increase the rate limit. Set the `GITHUB_TOKEN` en
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jetbrains'
|
||||
java-version: '17'
|
||||
@ -219,8 +219,8 @@ The available package types are:
|
||||
## Installing custom Java package type
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
@ -232,8 +232,8 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
@ -249,7 +249,7 @@ steps:
|
||||
- run: |
|
||||
download_url="https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
@ -275,7 +275,7 @@ If your use-case requires a custom distribution (in the example, alpine-linux is
|
||||
latest_semver_version=$(curl -sL $latest_jdk_json_url | jq -r 'version.semver')
|
||||
echo "java_version=$latest_semver_version" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
@ -296,9 +296,9 @@ jobs:
|
||||
java: [ '8', '11' ]
|
||||
name: Java ${{ matrix.Java }} (${{ matrix.distribution }}) sample
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
java-version: ${{ matrix.java }}
|
||||
@ -316,9 +316,9 @@ jobs:
|
||||
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ]
|
||||
name: Java ${{ matrix.Java }} (${{ matrix.os }}) sample
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
@ -333,9 +333,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
@ -349,7 +349,7 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
|
||||
|
||||
- name: Set up Apache Maven Central
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with: # running setup-java again overwrites the settings.xml
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
@ -411,6 +411,85 @@ The two `settings.xml` files created from the above example look like the follow
|
||||
|
||||
If you don't want to overwrite the `settings.xml` file, you can set `overwrite-settings: false`
|
||||
|
||||
### Multiple repositories
|
||||
|
||||
There might be instances where you will need to change the version to/from release/snapshot. That will require specifying two maven repositories - one for release versions, one for snapshot versions.
|
||||
|
||||
#### Yaml example
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
- name: Publish to GitHub Packages Apache Maven
|
||||
run: mvn deploy
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
|
||||
|
||||
- name: Set up Apache Maven Central
|
||||
uses: actions/setup-java@v4
|
||||
with: # running setup-java again overwrites the settings.xml
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
mvn-repositories-len: 2
|
||||
server-id-0: artifactory # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username-0: ARTIFACTORY_USERNAME # env variable for username in deploy
|
||||
server-password-0: ARTIFACTORY_TOKEN # env variable for token in deploy
|
||||
server-id-1: snapshot-artifactory # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username-1: SNAPSHOT_ARTIFACTORY_USERNAME # env variable for username in deploy
|
||||
server-password-1: SNAPSHOT_ARTIFACTORY_TOKEN # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: Publish to Apache Maven Central
|
||||
run: mvn deploy
|
||||
env:
|
||||
ARTIFACTORY_USERNAME: maven_username123
|
||||
ARTIFACTORY_TOKEN: ${{ secrets.ARTIFACTORY_USERNAME }}
|
||||
SNAPSHOT_ARTIFACTORY_USERNAME: snapshot_maven_username123
|
||||
SNAPSHOT_ARTIFACTORY_TOKEN: ${{ secrets.SNAPSHOT_ARTIFACTORY_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
```
|
||||
|
||||
Here `mvn-repositories-len` specifies how many artifactories we're configuring here. In this example, the value is 2. In this case, the action will look for `server-id-0`, `server-username-0`, `server-password-0`, `server-id-1`, `server-username-1` and `server-password-1`.
|
||||
Depending on the value of `mvn-repositories-len`, the number of entries that will be looked for will vary. But it is looking for 0 based indexing with the max value less than the value of `mvn-repositories-len`.
|
||||
|
||||
`settings.xml` file created for the deployment to the Maven Artifactory
|
||||
```xml
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<servers>
|
||||
<server>
|
||||
<id>artifactory</id>
|
||||
<username>${env.ARTIFACTORY_USERNAME}</username>
|
||||
<password>${env.ARTIFACTORY_TOKEN}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>snapshot-artifactory</id>
|
||||
<username>${env.SNAPSHOT_ARTIFACTORY_USERNAME}</username>
|
||||
<password>${env.SNAPSHOT_ARTIFACTORY_TOKEN}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>gpg.passphrase</id>
|
||||
<passphrase>${env.MAVEN_GPG_PASSPHRASE}</passphrase>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
```
|
||||
|
||||
|
||||
### Extra setup for pom.xml:
|
||||
|
||||
The Maven GPG Plugin configuration in the pom.xml file should contain the following structure to avoid possible issues like `Inappropriate ioctl for device` or `gpg: signing failed: No such file or directory`:
|
||||
@ -446,9 +525,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Set up JDK 11 for Shared Runner
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
@ -472,10 +551,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
@ -509,14 +588,14 @@ Subsequent calls to `setup-java` with distinct distribution and version paramete
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
8
|
||||
11
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '15'
|
||||
@ -528,7 +607,7 @@ The result is a Toolchain with entries for JDKs 8, 11 and 15. You can even combi
|
||||
- run: |
|
||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
@ -545,7 +624,7 @@ Each JDK provider will receive a default `vendor` using the `distribution` input
|
||||
- run: |
|
||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
@ -560,7 +639,7 @@ In case you install multiple versions of Java at once with multi-line `java-vers
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
@ -574,8 +653,8 @@ Each JDK provider will receive a default `id` based on the combination of `distr
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
@ -587,7 +666,7 @@ In case you install multiple versions of Java at once you can use the same synta
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: |
|
||||
|
||||
123
src/auth.ts
123
src/auth.ts
@ -9,11 +9,11 @@ import {create as xmlCreate} from 'xmlbuilder2';
|
||||
import * as constants from './constants';
|
||||
import * as gpg from './gpg';
|
||||
import {getBooleanInput} from './util';
|
||||
import {MvnSettingDefinition} from './mvn.setting.definition';
|
||||
|
||||
export async function configureAuthentication() {
|
||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||
const numMvnRepos = core.getInput(constants.INPUT_NUM_MVN_REPOS);
|
||||
const mvnSettings: Array<MvnSettingDefinition> = [];
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
@ -21,24 +21,19 @@ export async function configureAuthentication() {
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
const gpgPrivateKey =
|
||||
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
|
||||
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
const gpgPassphrase =
|
||||
core.getInput(constants.INPUT_GPG_PASSPHRASE) ||
|
||||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
|
||||
|
||||
if (gpgPrivateKey) {
|
||||
core.setSecret(gpgPrivateKey);
|
||||
let gpgPrivateKey;
|
||||
if (numMvnRepos === '' || core.getInput(constants.INPUT_GPG_PRIVATE_KEY)) {
|
||||
gpgPrivateKey = populateMvnSettings(mvnSettings);
|
||||
} else {
|
||||
for (let i = 0; i < parseInt(numMvnRepos); i++) {
|
||||
populateMvnSettings(mvnSettings, i);
|
||||
}
|
||||
}
|
||||
|
||||
await createAuthenticationSettings(
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
mvnSettings,
|
||||
settingsDirectory,
|
||||
overwriteSettings,
|
||||
gpgPassphrase
|
||||
overwriteSettings
|
||||
);
|
||||
|
||||
if (gpgPrivateKey) {
|
||||
@ -48,32 +43,61 @@ export async function configureAuthentication() {
|
||||
}
|
||||
}
|
||||
|
||||
function populateMvnSettings(
|
||||
mvnSettings: Array<MvnSettingDefinition>,
|
||||
idx = -1
|
||||
): string | undefined {
|
||||
const id = core.getInput(getIndexedInputName(constants.INPUT_SERVER_ID, idx));
|
||||
const username = core.getInput(
|
||||
getIndexedInputName(constants.INPUT_SERVER_USERNAME, idx)
|
||||
);
|
||||
const password = core.getInput(
|
||||
getIndexedInputName(constants.INPUT_SERVER_PASSWORD, idx)
|
||||
);
|
||||
if (username !== '' && password !== '') {
|
||||
mvnSettings.push({id: id, username: username, password: password});
|
||||
}
|
||||
|
||||
if (idx === -1) {
|
||||
const gpgPrivateKey =
|
||||
core.getInput(
|
||||
getIndexedInputName(constants.INPUT_GPG_PRIVATE_KEY, idx)
|
||||
) || constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
const gpgPassphrase =
|
||||
core.getInput(getIndexedInputName(constants.INPUT_GPG_PASSPHRASE, idx)) ||
|
||||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
|
||||
|
||||
if (gpgPrivateKey) {
|
||||
core.setSecret(gpgPrivateKey);
|
||||
}
|
||||
|
||||
if (gpgPassphrase) {
|
||||
mvnSettings.push({id: 'gpg.passphrase', gpgPassphrase: gpgPassphrase});
|
||||
return gpgPrivateKey;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getIndexedInputName(inputName: string, idx: number): string {
|
||||
return inputName + (idx >= 0 ? '-' + idx : '');
|
||||
}
|
||||
|
||||
export async function createAuthenticationSettings(
|
||||
id: string,
|
||||
username: string,
|
||||
password: string,
|
||||
mvnSettings: Array<MvnSettingDefinition>,
|
||||
settingsDirectory: string,
|
||||
overwriteSettings: boolean,
|
||||
gpgPassphrase: string | undefined = undefined
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE}`);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
await io.mkdirP(settingsDirectory);
|
||||
await write(
|
||||
settingsDirectory,
|
||||
generate(id, username, password, gpgPassphrase),
|
||||
overwriteSettings
|
||||
);
|
||||
await write(settingsDirectory, generate(mvnSettings), overwriteSettings);
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function generate(
|
||||
id: string,
|
||||
username: string,
|
||||
password: string,
|
||||
gpgPassphrase?: string | undefined
|
||||
) {
|
||||
export function generate(mvnSettings: Array<MvnSettingDefinition>) {
|
||||
const xmlObj: {[key: string]: any} = {
|
||||
settings: {
|
||||
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
||||
@ -81,24 +105,27 @@ export function generate(
|
||||
'@xsi:schemaLocation':
|
||||
'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
||||
servers: {
|
||||
server: [
|
||||
{
|
||||
id: id,
|
||||
username: `\${env.${username}}`,
|
||||
password: `\${env.${password}}`
|
||||
}
|
||||
]
|
||||
server: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (gpgPassphrase) {
|
||||
const gpgServer = {
|
||||
id: 'gpg.passphrase',
|
||||
passphrase: `\${env.${gpgPassphrase}}`
|
||||
};
|
||||
xmlObj.settings.servers.server.push(gpgServer);
|
||||
}
|
||||
mvnSettings.forEach(mvnSetting => {
|
||||
if (mvnSetting.username && mvnSetting.password) {
|
||||
xmlObj.settings.servers.server.push({
|
||||
id: mvnSetting.id,
|
||||
username: `\${env.${mvnSetting.username}}`,
|
||||
password: `\${env.${mvnSetting.password}}`
|
||||
});
|
||||
}
|
||||
|
||||
if (mvnSetting.gpgPassphrase) {
|
||||
xmlObj.settings.servers.server.push({
|
||||
id: mvnSetting.id,
|
||||
passphrase: `\${env.${mvnSetting.gpgPassphrase}}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return xmlCreate(xmlObj).end({
|
||||
headless: true,
|
||||
|
||||
@ -6,6 +6,7 @@ export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
export const INPUT_JDK_FILE = 'jdkFile';
|
||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||
export const INPUT_NUM_MVN_REPOS = 'mvn-repositories-len';
|
||||
export const INPUT_SERVER_ID = 'server-id';
|
||||
export const INPUT_SERVER_USERNAME = 'server-username';
|
||||
export const INPUT_SERVER_PASSWORD = 'server-password';
|
||||
|
||||
6
src/mvn.setting.definition.ts
Normal file
6
src/mvn.setting.definition.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export interface MvnSettingDefinition {
|
||||
id: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
gpgPassphrase?: string;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user