Skip to content

ci: Add GitHub Actions CI/CD with SonarCloud integration #5

ci: Add GitHub Actions CI/CD with SonarCloud integration

ci: Add GitHub Actions CI/CD with SonarCloud integration #5

Workflow file for this run

name: Pull Request Checks
on:
pull_request:
types: [opened, synchronize, reopened]
env:
JAVA_VERSION: '21'
MAVEN_OPTS: -Xmx3072m
jobs:
pr-validation:
name: PR Validation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: 'maven'
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
requireScope: false
- name: Check code formatting
run: mvn spotless:check
continue-on-error: true
- name: Run quick tests
run: mvn test -pl openespi-common,openespi-datacustodian
- name: Check for security vulnerabilities
run: mvn org.owasp:dependency-check-maven:check -DfailBuildOnCVSS=8
continue-on-error: true
sonarcloud-pr:
name: SonarCloud PR Analysis
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Analyze with SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mvn clean verify sonar:sonar \
-Dsonar.projectKey=GreenButtonAlliance_OpenESPI-GreenButton-Java \
-Dsonar.organization=greenbuttonalliance \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}