SonarCloud #215
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the CI Action for SonarQuest to automatically build Docker images on master push and release. | |
name: SonarQuest-CI | |
# Controls when the action will run. | |
on: | |
push: | |
release: | |
types: [ released, prereleased, edited ] | |
workflow_dispatch: | |
jobs: | |
backend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Cache Maven packages | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Build backend with Maven | |
run: mvn -f ./sonarQuest-backend/pom.xml --batch-mode --update-snapshots verify | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image - Release | |
uses: docker/build-push-action@v2 | |
if: ${{ github.event_name == 'release' }} | |
with: | |
context: ./sonarQuest-backend | |
push: true | |
tags: | | |
ghcr.io/viadee/sonarquest-backend:latest | |
ghcr.io/viadee/sonarquest-backend:${{ github.event.release.tag_name }} | |
- name: Build and push Docker image - Nightly | |
uses: docker/build-push-action@v2 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
with: | |
context: ./sonarQuest-backend | |
push: true | |
tags: ghcr.io/viadee/sonarquest-backend:nightly | |
frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: '10.9.0' | |
- name: Install dependencies | |
run: | | |
cd sonarQuest-frontend | |
npm i | |
- name: Build Angular app | |
run: | | |
cd sonarQuest-frontend | |
npm run build:prod | |
- name: Test | |
run: | | |
cd sonarQuest-frontend | |
npm test | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image - Release | |
uses: docker/build-push-action@v2 | |
if: ${{ github.event_name == 'release' }} | |
with: | |
context: ./sonarQuest-frontend | |
push: true | |
tags: | | |
ghcr.io/viadee/sonarquest-frontend:latest | |
ghcr.io/viadee/sonarquest-frontend:${{ github.event.release.tag_name }} | |
- name: Build and push Docker image - Nightly | |
uses: docker/build-push-action@v2 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
with: | |
context: ./sonarQuest-frontend | |
push: true | |
tags: ghcr.io/viadee/sonarquest-frontend:nightly | |
analyze: | |
name: SonarCloud Analysis | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'zulu' # Alternative distribution options are available. | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Cache Maven packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Build and analyze | |
env: | |
#GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: mvn -f ./sonarQuest-backend/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=viadee_sonarQuest | |