Skip to content

[TU-13734] Add SonarCloud configuration #31

[TU-13734] Add SonarCloud configuration

[TU-13734] Add SonarCloud configuration #31

Workflow file for this run

name: Pull Request
on:
pull_request:
branches:
- main
jobs:
build-lint-test:
runs-on: ubuntu-latest
name: build-lint-test
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Get yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
~/.cache
key: ${{ runner.os }}-repo-${{ github.event.pull_request.head.repo.full_name }}-node-20-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/**.yml') }}
- name: Install Node.js dependencies
# run when cache not found or PR is external (build fails for external PRs if dependencies are not installed)
if: steps.yarn-cache.outputs.cache-hit != 'true' || github.event.pull_request.head.repo.full_name != github.repository
run: yarn install --frozen-lockfile
- run: yarn dist
- run: yarn lint
- run: yarn test --coverage
- name: Upload coverage file
uses: actions/upload-artifact@v4
with:
name: coverage
path: ./coverage/lcov.info
retention-days: 1
deploy-preview:
runs-on: ubuntu-latest
name: deploy-preview
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Get yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
~/.cache
key: ${{ runner.os }}-repo-${{ github.event.pull_request.head.repo.full_name }}-node-20-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/**.yml') }}
- name: Install Node.js dependencies
# run when cache not found or PR is external (build fails for external PRs if dependencies are not installed)
if: steps.yarn-cache.outputs.cache-hit != 'true' || github.event.pull_request.head.repo.full_name != github.repository
run: yarn install --frozen-lockfile
- run: yarn dist
# update registry and tokens with write access for releasing.
- run: rm ./.npmrc
- run: npm config set '//registry.npmjs.org/:_authToken' $NPM_TOKEN
- run: npm config set '//npm.pkg.github.com/:_authToken' $GH_TOKEN
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- run: npm config set @typeform:registry https://npm.pkg.github.com/
# install jarvis private package from github
- run: yarn add -W @typeform/jarvis
- run: git checkout HEAD -- package.json # do not save jarvis dependency to package.json because it is private (the file is committed by semantic-release to bump version)
# deploy preview version of the package
- run: yarn release:aws --preview --notify-preview
env:
AWS_ASSETS_BUCKET: 'typeform-public-assets/btn'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
JARVIS_NOTIFY_PREVIEW_TEMPLATE: ${{ secrets.JARVIS_NOTIFY_PREVIEW_TEMPLATE }}
PUBLIC_CDN_URL: 'https://btn.typeform.com'
sonarcloud:
name: Test and Code Quality Report (SonarCloud)
needs:
- build-lint-test
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download coverage file
uses: actions/download-artifact@v4
with:
name: coverage
- name: Move the coverage file to a proper location
run: |
mkdir -p coverage
mv lcov.info coverage/lcov.info
- name: Verify coverage file ready
run: ls -lah ./coverage/lcov.info
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
with:
args: >
-Dsonar.projectVersion=${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}