Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add mysql support + restore sonar for springboot #107

Merged
merged 14 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
78 changes: 78 additions & 0 deletions .github/workflows/sonar-step-springboot-analyze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Sonar analyze with artifacts

on:
workflow_call:
inputs:
RUN_ON:
required: false
type: string
default: "zupit-agents"
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: "Container"
WORKING_DIRECTORY:
required: true
type: string
JAVA_IMAGE:
required: true
type: string
CHECK_QUALITY_GATE:
required: false
type: boolean
default: false
DOWNLOAD_ARTIFACT:
required: false
type: boolean
default: true
ARTIFACT_FILENAME:
required: false
type: string
default: ""
ARTIFACT_PATH:
required: false
type: string
default: ".coverage-reports/"
PRE_SCAN_COMMANDS:
required: false
type: string
default: ""
MAVEN_USER_HOME:
required: false
type: string
default: "./m2"
EXTRA_MAVEN_ARGS:
required: false
type: string
default: ""

env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

jobs:
sonar-analyze:
runs-on:
labels: ${{ inputs.RUN_ON }}
group: ${{ inputs.RUNNERS_CONTAINER_GROUP }}
container: ${{ inputs.JAVA_IMAGE }}
defaults:
run:
working-directory: ${{ inputs.WORKING_DIRECTORY }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download coverage artifact
if: ${{ inputs.DOWNLOAD_ARTIFACT }}
uses: actions/download-artifact@v3
with:
name: ${{inputs.ARTIFACT_FILENAME}}
path: ${{ inputs.WORKING_DIRECTORY }}/${{ inputs.ARTIFACT_PATH }}

- name: Run PRE_SCAN_COMMANDS commands
if: ${{ inputs.PRE_SCAN_COMMANDS != '' }}
run: ${{ inputs.PRE_SCAN_COMMANDS }}

- name: Run Sonar
run: ./mvnw -ntp initialize sonar:sonar -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} -Dsonar.login=${{ secrets.SONAR_TOKEN }} -Dsonar.qualitygate.wait=${{ inputs.CHECK_QUALITY_GATE }}
82 changes: 82 additions & 0 deletions .github/workflows/springboot-step-tests-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Run SpringBoot tests

on:
workflow_call:
inputs:
RUN_ON:
required: false
type: string
default: 'zupit-agents'
RUNNERS_CONTAINER_GROUP:
required: false
type: string
default: 'Container'
WORKING_DIRECTORY:
required: true
type: string
JAVA_IMAGE:
required: true
type: string
COVERAGE_ARTIFACT_NAME:
required: true
type: string
MAVEN_USER_HOME:
required: false
type: string
default: "./m2"
EXTRA_MAVEN_ARGS:
required: false
type: string
default: ""
SPRING_APPLICATION_JSON:
required: false
type: string
RUN:
required: false
type: boolean
default: true

env: "${{secrets}}"

jobs:
springboot-run-tests:
if: ${{ inputs.RUN }}
runs-on:
labels: ${{ inputs.RUN_ON }}
group: ${{ inputs.RUNNERS_CONTAINER_GROUP }}
container: ${{ inputs.JAVA_IMAGE }}

defaults:
run:
working-directory: ${{ inputs.WORKING_DIRECTORY }}

services:
mysql:
image: mysql
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run tests
run: |
./mvnw -ntp verify -Dmaven.repo.local=${{inputs.MAVEN_USER_HOME}} ${{inputs.EXTRA_MAVEN_ARGS}}
./mvnw -ntp jacoco:report -Dmaven.repo.local=${{inputs.MAVEN_USER_HOME}} ${{inputs.EXTRA_MAVEN_ARGS}}
env:
SPRING_APPLICATION_JSON: ${{ inputs.SPRING_APPLICATION_JSON || '{}' }}
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/test
SPRING_DATASOURCE_USERNAME: test
SPRING_DATASOURCE_PASSWORD: test

- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.COVERAGE_ARTIFACT_NAME }}
path: |
${{ inputs.WORKING_DIRECTORY }}/target/**/*.xml
${{ inputs.WORKING_DIRECTORY }}/target/**/*.class
retention-days: 1
2 changes: 0 additions & 2 deletions .github/workflows/springboot-step-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ on:
SPRING_APPLICATION_JSON:
required: false
type: string
default:
RUN:
required: false
type: boolean
default: true


env: "${{secrets}}"

jobs:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/springboot-workflow-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ on:
required: false
type: boolean
default: true
DATABASE:
required: false
type: string
description: 'Database to use: postgres or mysql'
default: 'postgres'

env: "${{secrets}}"

Expand All @@ -45,6 +50,7 @@ jobs:
secrets: inherit

springboot-tests:
if: ${{ inputs.DATABASE == 'postgres'}}
uses:
./.github/workflows/springboot-step-tests.yml
with:
Expand All @@ -56,3 +62,16 @@ jobs:
USE_CI_POSTGRES: ${{ inputs.USE_CI_POSTGRES }}
RUN: ${{ inputs.RUN }}
secrets: inherit

springboot-tests-mysql:
if: ${{ inputs.DATABASE == 'mysql'}}
uses:
./.github/workflows/springboot-step-tests-mysql.yml
with:
JAVA_IMAGE: ${{inputs.JAVA_IMAGE}}
WORKING_DIRECTORY: ${{inputs.WORKING_DIRECTORY}}
MAVEN_USER_HOME: ${{inputs.MAVEN_USER_HOME}}
EXTRA_MAVEN_ARGS: ${{inputs.EXTRA_MAVEN_ARGS}}
COVERAGE_ARTIFACT_NAME: ${{ inputs.COVERAGE_ARTIFACT_NAME }}
RUN: ${{ inputs.RUN }}
secrets: inherit