Add "overwrite-settings" input parameter (#136)

* add overwrite-settings parameter

* fix e2e tests

* print debug

* fix e2e tests

* add comment

* remove comment
This commit is contained in:
Maxim Lobanov 2021-03-17 11:04:00 +03:00 committed by GitHub
parent 7c88894700
commit 804a60faf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 184 additions and 37 deletions

View file

@ -11,6 +11,10 @@ on:
paths-ignore:
- '**.md'
defaults:
run:
shell: pwsh
jobs:
setup-java-publishing:
name: Validate settings.xml
@ -34,12 +38,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Validate settings.xml
run: |
$homePath = $env:USERPROFILE
if (-not $homePath) {
$homePath = $env:HOME
}
$xmlPath = Join-Path $homePath ".m2" "settings.xml"
$xmlPath = Join-Path $HOME ".m2" "settings.xml"
Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
[xml]$xml = Get-Content $xmlPath
@ -51,10 +50,82 @@ jobs:
if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
throw "Generated XML file is incorrect"
}
shell: pwsh
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@v2
- 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
- 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@v2
- 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
- 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: Validate settings.xml in custom location
name: settings.xml in custom location
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@ -79,5 +150,4 @@ jobs:
$path = Join-Path $env:RUNNER_TEMP "settings.xml"
if (-not (Test-Path $path)) {
throw "settings.xml file is not found in expected location"
}
shell: pwsh
}