mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
* fix(auth): Update authentication logic in settings.xml, unit tests Enhanced the logic for reading authentication information in the settings.xml file to address an issue where attempts to configure a GitHub Action for fetching packages from a repository within the same organization resulted in authentication errors. Despite the correct configuration, the process failed with a 401 Unauthorized status during dependency download from GitHub's Maven package repository. The error was pinpointed to a non-resolvable parent POM due to authentication failure, with an incorrect 'parent.relativePath' exacerbating the issue. To resolve this, I made significant updates to the logic within settings.xml for better handling of authentication information. Additionally, unit tests have been updated to reflect these changes and ensure robust verification. The documentation and examples have also been revised to provide clearer guidance on configuring and utilizing this updated process successfully.
169 lines
5.3 KiB
YAML
169 lines
5.3 KiB
YAML
name: Validate publishing functionality
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- releases/*
|
|
paths-ignore:
|
|
- '**.md'
|
|
pull_request:
|
|
paths-ignore:
|
|
- '**.md'
|
|
|
|
defaults:
|
|
run:
|
|
shell: pwsh
|
|
|
|
jobs:
|
|
setup-java-publishing:
|
|
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'
|
|
server-id: maven
|
|
server-username: MAVEN_USERNAME
|
|
server-password: MAVEN_CENTRAL_TOKEN
|
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
|
env:
|
|
MAVEN_USERNAME: MAVEN_USERNAME
|
|
MAVEN_CENTRAL_TOKEN: MAVEN_CENTRAL_TOKEN
|
|
MAVEN_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') -or ($servers[0].username -ne 'MAVEN_USERNAME') -or ($servers[0].password -ne 'MAVEN_CENTRAL_TOKEN')) {
|
|
throw "Generated XML file is incorrect"
|
|
}
|
|
|
|
if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne 'MAVEN_GPG_PASSPHRASE')) {
|
|
throw "Generated XML file is incorrect"
|
|
}
|
|
|
|
test-publishing-overwrite:
|
|
name: settings.xml is overwritten if flag is true
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Create fake settings.xml
|
|
run: |
|
|
$xmlDirectory = Join-Path $HOME ".m2"
|
|
$xmlPath = Join-Path $xmlDirectory "settings.xml"
|
|
New-Item -Path $xmlDirectory -ItemType Directory
|
|
Set-Content -Path $xmlPath -Value "Fake_XML"
|
|
- name: setup-java
|
|
uses: ./
|
|
id: setup-java
|
|
with:
|
|
distribution: 'adopt'
|
|
java-version: '11'
|
|
server-id: maven
|
|
server-username: MAVEN_USERNAME
|
|
server-password: MAVEN_CENTRAL_TOKEN
|
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
|
env:
|
|
MAVEN_USERNAME: MAVEN_USERNAME
|
|
MAVEN_CENTRAL_TOKEN: MAVEN_CENTRAL_TOKEN
|
|
MAVEN_GPG_PASSPHRASE: MAVEN_GPG_PASSPHRASE
|
|
- name: Validate settings.xml is overwritten
|
|
run: |
|
|
$xmlPath = Join-Path $HOME ".m2" "settings.xml"
|
|
Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
|
|
|
|
$content = Get-Content $xmlPath -Raw
|
|
if ($content -notlike '*maven*') {
|
|
throw "settings.xml file is not overwritten"
|
|
}
|
|
|
|
test-publishing-skip-overwrite:
|
|
name: settings.xml is not overwritten if flag is false
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Create fake settings.xml
|
|
run: |
|
|
$xmlDirectory = Join-Path $HOME ".m2"
|
|
$xmlPath = Join-Path $xmlDirectory "settings.xml"
|
|
New-Item -Path $xmlDirectory -ItemType Directory
|
|
Set-Content -Path $xmlPath -Value "Fake_XML"
|
|
- name: setup-java
|
|
uses: ./
|
|
id: setup-java
|
|
with:
|
|
distribution: 'adopt'
|
|
java-version: '11'
|
|
server-id: maven
|
|
server-username: MAVEN_USERNAME
|
|
server-password: MAVEN_CENTRAL_TOKEN
|
|
overwrite-settings: false
|
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
|
env:
|
|
MAVEN_USERNAME: MAVEN_USERNAME
|
|
MAVEN_CENTRAL_TOKEN: MAVEN_CENTRAL_TOKEN
|
|
MAVEN_GPG_PASSPHRASE: MAVEN_GPG_PASSPHRASE
|
|
- name: Validate that settings.xml is not overwritten
|
|
run: |
|
|
$xmlPath = Join-Path $HOME ".m2" "settings.xml"
|
|
$content = Get-Content -Path $xmlPath -Raw
|
|
Write-Host $content
|
|
|
|
if ($content -notlike "*Fake_XML*") {
|
|
throw "settings.xml file was overwritten but it should not be"
|
|
}
|
|
|
|
test-publishing-custom-location:
|
|
name: settings.xml in custom location
|
|
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'
|
|
server-id: maven
|
|
server-username: MAVEN_USERNAME
|
|
server-password: MAVEN_CENTRAL_TOKEN
|
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE
|
|
settings-path: ${{ runner.temp }}
|
|
env:
|
|
MAVEN_USERNAME: MAVEN_USERNAME
|
|
MAVEN_CENTRAL_TOKEN: MAVEN_CENTRAL_TOKEN
|
|
MAVEN_GPG_PASSPHRASE: MAVEN_GPG_PASSPHRASE
|
|
- name: Validate settings.xml location
|
|
run: |
|
|
$path = Join-Path $env:RUNNER_TEMP "settings.xml"
|
|
if (-not (Test-Path $path)) {
|
|
throw "settings.xml file is not found in expected location"
|
|
}
|