1
+ name : Validate publishing functionality
2
+ on :
3
+ push :
4
+ branches :
5
+ - main
6
+ - releases/*
7
+ - v2-preview
8
+ paths-ignore :
9
+ - ' **.md'
10
+ pull_request :
11
+ paths-ignore :
12
+ - ' **.md'
13
+
14
+ defaults :
15
+ run :
16
+ shell : pwsh
17
+
18
+ jobs :
19
+ setup-java-publishing :
20
+ name : Validate settings.xml
21
+ runs-on : ${{ matrix.os }}
22
+ strategy :
23
+ fail-fast : false
24
+ matrix :
25
+ os : [macos-latest, windows-latest, ubuntu-latest]
26
+ steps :
27
+ - name : Checkout
28
+ uses : actions/checkout@v2
29
+ - name : setup-java
30
+ uses : ./
31
+ id : setup-java
32
+ with :
33
+ distribution : ' adopt'
34
+ java-version : ' 11'
35
+ server-id : maven
36
+ server-username : MAVEN_USERNAME
37
+ server-password : MAVEN_CENTRAL_TOKEN
38
+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
39
+ - name : Validate settings.xml
40
+ run : |
41
+ $xmlPath = Join-Path $HOME ".m2" "settings.xml"
42
+ Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
43
+
44
+ [xml]$xml = Get-Content $xmlPath
45
+ $servers = $xml.settings.servers.server
46
+ if (($servers[0].id -ne 'maven') -or ($servers[0].username -ne '${env.MAVEN_USERNAME}') -or ($servers[0].password -ne '${env.MAVEN_CENTRAL_TOKEN}')) {
47
+ throw "Generated XML file is incorrect"
48
+ }
49
+
50
+ if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
51
+ throw "Generated XML file is incorrect"
52
+ }
53
+
54
+ test-publishing-overwrite :
55
+ name : settings.xml is overwritten if flag is true
56
+ runs-on : ${{ matrix.os }}
57
+ strategy :
58
+ fail-fast : false
59
+ matrix :
60
+ os : [macos-latest, windows-latest, ubuntu-latest]
61
+ steps :
62
+ - name : Checkout
63
+ uses : actions/checkout@v2
64
+ - name : Create fake settings.xml
65
+ run : |
66
+ $xmlDirectory = Join-Path $HOME ".m2"
67
+ $xmlPath = Join-Path $xmlDirectory "settings.xml"
68
+ New-Item -Path $xmlDirectory -ItemType Directory
69
+ Set-Content -Path $xmlPath -Value "Fake_XML"
70
+ - name : setup-java
71
+ uses : ./
72
+ id : setup-java
73
+ with :
74
+ distribution : ' adopt'
75
+ java-version : ' 11'
76
+ server-id : maven
77
+ server-username : MAVEN_USERNAME
78
+ server-password : MAVEN_CENTRAL_TOKEN
79
+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
80
+ - name : Validate settings.xml is overwritten
81
+ run : |
82
+ $xmlPath = Join-Path $HOME ".m2" "settings.xml"
83
+ Get-Content $xmlPath | ForEach-Object { Write-Host $_ }
84
+
85
+ $content = Get-Content $xmlPath -Raw
86
+ if ($content -notlike '*maven*') {
87
+ throw "settings.xml file is not overwritten"
88
+ }
89
+
90
+ test-publishing-skip-overwrite :
91
+ name : settings.xml is not overwritten if flag is false
92
+ runs-on : ${{ matrix.os }}
93
+ strategy :
94
+ fail-fast : false
95
+ matrix :
96
+ os : [macos-latest, windows-latest, ubuntu-latest]
97
+ steps :
98
+ - name : Checkout
99
+ uses : actions/checkout@v2
100
+ - name : Create fake settings.xml
101
+ run : |
102
+ $xmlDirectory = Join-Path $HOME ".m2"
103
+ $xmlPath = Join-Path $xmlDirectory "settings.xml"
104
+ New-Item -Path $xmlDirectory -ItemType Directory
105
+ Set-Content -Path $xmlPath -Value "Fake_XML"
106
+ - name : setup-java
107
+ uses : ./
108
+ id : setup-java
109
+ with :
110
+ distribution : ' adopt'
111
+ java-version : ' 11'
112
+ server-id : maven
113
+ server-username : MAVEN_USERNAME
114
+ server-password : MAVEN_CENTRAL_TOKEN
115
+ overwrite-settings : false
116
+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
117
+ - name : Validate that settings.xml is not overwritten
118
+ run : |
119
+ $xmlPath = Join-Path $HOME ".m2" "settings.xml"
120
+ $content = Get-Content -Path $xmlPath -Raw
121
+ Write-Host $content
122
+
123
+ if ($content -notlike "*Fake_XML*") {
124
+ throw "settings.xml file was overwritten but it should not be"
125
+ }
126
+
127
+ test-publishing-custom-location :
128
+ name : settings.xml in custom location
129
+ runs-on : ${{ matrix.os }}
130
+ strategy :
131
+ fail-fast : false
132
+ matrix :
133
+ os : [macos-latest, windows-latest, ubuntu-latest]
134
+ steps :
135
+ - name : Checkout
136
+ uses : actions/checkout@v2
137
+ - name : setup-java
138
+ uses : ./
139
+ id : setup-java
140
+ with :
141
+ distribution : ' adopt'
142
+ java-version : ' 11'
143
+ server-id : maven
144
+ server-username : MAVEN_USERNAME
145
+ server-password : MAVEN_CENTRAL_TOKEN
146
+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
147
+ settings-path : ${{ runner.temp }}
148
+ - name : Validate settings.xml location
149
+ run : |
150
+ $path = Join-Path $env:RUNNER_TEMP "settings.xml"
151
+ if (-not (Test-Path $path)) {
152
+ throw "settings.xml file is not found in expected location"
153
+ }
0 commit comments