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

✨ feat : added frontend project scaffolding & sonar #2

Merged
merged 13 commits into from
Jan 31, 2024
68 changes: 57 additions & 11 deletions .github/workflows/backendBuild.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,89 @@
name: SonarCloud
name: SonarCloud Backend
on:
push:
branches:
- main
paths:
- "backend/**"
- ".github/workflows/backendBuild.yml"
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build and analyze
urlservice:
if: ( startsWith(github.head_ref, 'BE_') && github.event.pull_request.merged == false ) || ( github.event_name == 'push' )
name: BE Url Service Sonar Analysis
runs-on: ubuntu-latest
timeout-minutes: 8
timeout-minutes: 8
defaults:
run:
working-directory: backend
working-directory: backend/urlShortner-service
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
distribution: "zulu"

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v3
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 -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=dev-madhurendra_short-my-url
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.URL_SERVICE_SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.verbose=true -Dsonar.projectName=short-my-url-url-service -Dsonar.projectKey=dev-madhurendra_short-my-url-url-service -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml -Pcoverage

userservice:
if: ( startsWith(github.head_ref, 'BE_') && github.event.pull_request.merged == false ) || ( github.event_name == 'push' )
name: BE User Service Sonar Analysis
runs-on: ubuntu-latest
timeout-minutes: 8
defaults:
run:
working-directory: backend/user-service
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: "zulu"

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v3
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 }}
SONAR_TOKEN: ${{ secrets.USER_SERVICE_SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.verbose=true -Dsonar.projectName=short-my-url-user-service -Dsonar.projectKey=dev-madhurendra_short-my-url-user-service -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml -Pcoverage
53 changes: 53 additions & 0 deletions .github/workflows/frontendBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: SonarCloud Frontend
on:
push:
branches:
- main
paths:
- "frontend/**"
- ".github/workflows/frontendBuild.yml"
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarscan:
if: ( startsWith(github.head_ref, 'FE_') && github.event.pull_request.merged == false ) || ( github.event_name == 'push' )
name: FE Sonar Analysis
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ${{ github.workspace }}/frontend/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Install the dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: npm install

- name: Test and coverage
run: npm run coverage

- name: SonarCloud Scan
with:
projectBaseDir: frontend
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.FRONTEND_SONAR_TOKEN }}
24 changes: 0 additions & 24 deletions .gitignore

This file was deleted.

13 changes: 13 additions & 0 deletions frontend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
testMatch: ['**/*.test.tsx'],
clearMocks: true,
collectCoverage: true,
coverageDirectory: "coverage",
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/test/jest/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/test/jest/__mocks__/styleMock.js",
}
};
Loading
Loading