Skip to content

Commit 5c07d35

Browse files
committed
Create a pom.xml if not exists in any sonar
1 parent 76d1455 commit 5c07d35

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

.github/workflows/any-sonar-template.yml

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ name: any-sonar-template
1111
required: false
1212
default: "."
1313
type: string
14+
sonar_host_url:
15+
description: "Sonar host url"
16+
required: false
17+
default: "https://sonarcloud.io"
18+
type: string
19+
sonar_organization:
20+
description: "Sonar organization (login)"
21+
required: true
22+
type: string
23+
sonar_project_key:
24+
description: "Sonar project key"
25+
required: true
26+
type: string
1427
secrets:
15-
GH_TOKEN:
16-
description: 'GitHub Token'
28+
github_token:
29+
description: "GitHub Token"
1730
required: true
18-
SN_TOKEN:
19-
description: 'Sonar Token'
31+
sonar_token:
32+
description: "Sonar Token"
2033
required: true
2134
defaults:
2235
run:
@@ -49,11 +62,53 @@ jobs:
4962
path: ~/.sonar/cache
5063
key: ${{ runner.os }}-sonar
5164
restore-keys: ${{ runner.os }}-sonar
65+
- name: Create pom.xml if not exists
66+
working-directory: ${{ inputs.working-directory }}
67+
run: |
68+
cat <<EOF > pom.xml
69+
<?xml version="1.0" encoding="UTF-8"?>
70+
<project xmlns="http://maven.apache.org/POM/4.0.0"
71+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
73+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
74+
<modelVersion>4.0.0</modelVersion>
75+
<groupId>com.github.fabriciofx.github.workflows</groupId>
76+
<artifactId>sonar-template</artifactId>
77+
<version>0.0.1</version>
78+
<profiles>
79+
<profile>
80+
<id>sonar</id>
81+
<properties>
82+
<sonar.host.url>${{ inputs.sonar_host_url }}</sonar.host.url>
83+
<sonar.organization>${{ inputs.sonar_organization }}</sonar.organization>
84+
<sonar.projectKey>${{ inputs.sonar_project_key }}</sonar.projectKey>
85+
</properties>
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<groupId>org.sonarsource.scanner.maven</groupId>
90+
<artifactId>sonar-maven-plugin</artifactId>
91+
<version>5.2.0.4988</version>
92+
<executions>
93+
<execution>
94+
<phase>package</phase>
95+
<goals>
96+
<goal>sonar</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</profile>
104+
</profiles>
105+
</project>
106+
EOF
52107
- name: Run Sonar
53108
working-directory: ${{ inputs.working-directory }}
54109
env:
55-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
56-
SONAR_TOKEN: ${{ secrets.SN_TOKEN }}
110+
GITHUB_TOKEN: ${{ secrets.github_token }}
111+
SONAR_TOKEN: ${{ secrets.sonar_token }}
57112
run: |
58113
[[ -x "mvnw" ]] && mvn="./mvnw" || mvn="mvn"
59114
args=(--errors --batch-mode package)

.github/workflows/any-sonar-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ jobs:
1616
with:
1717
working-directory: "."
1818
secrets:
19-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20-
SN_TOKEN: ${{ secrets.SONAR_TOKEN }}
19+
github_token: ${{ secrets.GITHUB_TOKEN }}
20+
sonar_token: ${{ secrets.SONAR_TOKEN }}
21+
sonar_organization: "fabriciofx"
22+
sonar_project_key: "fabriciofx_github-workflows"

any/any-sonar.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
any-sonar:
1515
uses: fabriciofx/github-workflows/.github/workflows/any-sonar-template.yml@main
1616
secrets:
17-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
SN_TOKEN: ${{ secrets.SONAR_TOKEN }}
17+
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
sonar_token: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)