Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 29 additions & 38 deletions .github/workflows/maven-sonar-analysis-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ on:
workflow_call:
inputs:
SERVICE_LOCATION:
required: true
required: false
type: string
default: '.'
SONAR_URL:
required: false
type: string
default: 'https://sonarcloud.io'
PROJECT_KEY:
required: false
type: string
default: "mosip_${{ github.event.repository.name }}"
secrets:
SONAR_TOKEN:
required: true
Expand All @@ -33,68 +30,62 @@ on:
jobs:
maven-sonar-analysis:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
distribution: temurin
java-version: '21'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
server-id: ossrh
settings-path: ${{ github.workspace }}

- name: Cache local Maven repository
- name: Cache Maven
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
restore-keys: ${{ runner.os }}-maven-

- name: Setup branch and env
- name: Setup env
run: |
# Strip git ref prefix from version
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
echo "SONAR URL : ${{ inputs.SONAR_URL }}"

- name: Setup branch and GPG public key
- name: Import GPG
run: |
# Strip git ref prefix from version
echo ${{ env.BRANCH_NAME }}
echo ${{ env.GPG_TTY }}
sudo apt-get --yes install gnupg2
gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg
gpg2 --quiet --batch --passphrase=${{secrets.GPG_SECRET}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg
gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg
gpg2 --quiet --batch --passphrase=${{ secrets.GPG_SECRET }} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg

- name: Setup the settings file for ossrh server
run: echo "<settings> <servers> <server> <id>ossrh</id> <username>${{secrets.OSSRH_USER}}</username> <password>${{secrets.OSSRH_SECRET}}</password> </server> </servers> <profiles> <profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg2</gpg.executable> <gpg.passphrase>${{secrets.GPG_SECRET}}</gpg.passphrase> </properties> </profile> <profile> <id>allow-snapshots</id> <activation><activeByDefault>true</activeByDefault></activation> <repositories> <repository> <id>snapshots-repo</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>releases-repo</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> <repository> <id>danubetech-maven-public</id> <url>https://repo.danubetech.com/repository/maven-public/</url> </repository> </repositories> </profile> <profile> <id>sonar</id> <properties> <sonar.sources>.</sonar.sources> <sonar.host.url>https://sonarcloud.io</sonar.host.url> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles> </settings>" > $GITHUB_WORKSPACE/settings.xml

#- name: Build with Maven
# run: cd ${{ inputs.SERVICE_LOCATION }} && mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
- name: Setup Maven settings
run: |
echo "<settings> <servers> <server> <id>ossrh</id> <username>${{secrets.OSSRH_USER}}</username> <password>${{secrets.OSSRH_SECRET}}</password> </server> </servers> <profiles> <profile> <id>ossrh</id> <activation><activeByDefault>true</activeByDefault></activation> <properties> <gpg.executable>gpg2</gpg.executable> <gpg.passphrase>${{secrets.GPG_SECRET}}</gpg.passphrase> </properties> </profile> </profiles> </settings>" > $GITHUB_WORKSPACE/settings.xml

- name: Analyze with SonarCloud
- name: Sonar Analysis
run: |
SERVICE_KEY=$(echo "${{ inputs.SERVICE_LOCATION }}" | tr '/' '-')
FULL_PROJECT_KEY="${{ inputs.PROJECT_KEY }}-${SERVICE_KEY}"
echo "Derived Project Key: ${FULL_PROJECT_KEY}"
cd ${{ inputs.SERVICE_LOCATION }} && \
SERVICE_KEY=$(echo "${{ inputs.SERVICE_LOCATION }}" | sed 's|^\./||; s|^\.$||; s|[^a-zA-Z0-9]|-|g; s|-\\+|-|g; s|^-||; s|-$||')
Comment thread
Mahesh-Binayak marked this conversation as resolved.
FINAL_NAME="${{ github.event.repository.name }}${SERVICE_KEY:+-$SERVICE_KEY}"
FULL_PROJECT_KEY="${{ secrets.ORG_KEY }}_${FINAL_NAME}"
cd "${{ inputs.SERVICE_LOCATION || '.' }}" && \
mvn -U -B verify sonar:sonar \
-Dmaven.wagon.http.retryHandler.count=2 \
-Dsonar.projectKey=${FULL_PROJECT_KEY} \
-Dsonar.organization=${{ secrets.ORG_KEY }} \
-Dsonar.host.url=${{ inputs.SONAR_URL }} \
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
-Dsonar.projectName=${{ github.event.repository.name }} \
-Dsonar.projectName=${FINAL_NAME} \
--file pom.xml -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# - uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job # selectable (default: repo,message)
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
# if: "${{ github.event_name != 'pull_request' && failure() }}" # Pick up events even if the job fails or is canceled.
#- uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,author,commit,workflow,job
#env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
#if: "${{ github.event_name != 'pull_request' && failure() }}"