Skip to content

Commit

Permalink
Merge pull request #177 from TokenScript/TKS-809-Add-Sonar-Cloud-check
Browse files Browse the repository at this point in the history
ci: 🎡 add sonar cloud scan in CI
  • Loading branch information
nicktaras authored Mar 7, 2023
2 parents b223c0b + 59c9553 commit 9c742d3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 38 deletions.
96 changes: 58 additions & 38 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ name: Build examples
#description: Build all examples

on:
push:
branches:
- main
- staging
pull_request:
branches: [ main, staging ]
branches:
- "*"
workflow_dispatch:
inputs:
negotiatorBranch:
Expand All @@ -23,41 +28,56 @@ jobs:
strategy:
matrix:
node-version: [16.x]


steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"
registry-url: "https://npm.pkg.github.com"

- name: Build
run: |
echo "Github base ref: $GITHUB_BASE_REF"
echo "Requested branch: $NEGOTIATOR_BRANCH"
npm install
if [[ $GITHUB_BASE_REF == "staging" ]]; then
echo "This is a staging branch PR, updating package.json files to use negotiator staging branch"
scripts/use_negotiator_branch.js staging
fi
if [[ ! -z $NEGOTIATOR_BRANCH && $NEGOTIATOR_BRANCH != "none" ]]; then
echo "Negotiator branch $NEGOTIATOR_BRANCH requested, updating package.json files"
scripts/use_negotiator_branch.js $NEGOTIATOR_BRANCH
fi
export BASE_PATH=/token-negotiator-examples/ecommerce-store-website
export MAX_PROCESSES=5
npm run install-examples
npm run clean
npm run build
npm run copy-artifacts
env:
NEGOTIATOR_BRANCH: ${{ inputs.negotiatorBranch }}
NODE_AUTH_TOKEN: ${{ github.token }}

sonarcloud:
needs:
- build
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
registry-url: 'https://npm.pkg.github.com'

- name: Build
run: |
echo "Github base ref: $GITHUB_BASE_REF"
echo "Requested branch: $NEGOTIATOR_BRANCH"
npm install
if [[ $GITHUB_BASE_REF == "staging" ]]; then
echo "This is a staging branch PR, updating package.json files to use negotiator staging branch"
scripts/use_negotiator_branch.js staging
fi
if [[ ! -z $NEGOTIATOR_BRANCH && $NEGOTIATOR_BRANCH != "none" ]]; then
echo "Negotiator branch $NEGOTIATOR_BRANCH requested, updating package.json files"
scripts/use_negotiator_branch.js $NEGOTIATOR_BRANCH
fi
export BASE_PATH=/token-negotiator-examples/ecommerce-store-website
export MAX_PROCESSES=5
npm run install-examples
npm run clean
npm run build
npm run copy-artifacts
env:
NEGOTIATOR_BRANCH: ${{ inputs.negotiatorBranch }}
NODE_AUTH_TOKEN: ${{ github.token }}
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
14 changes: 14 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=TokenScript_token-negotiator-examples
sonar.organization=tokenscript

sonar.exclusions=e2e-test-suite/**

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=token-negotiator-examples
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

0 comments on commit 9c742d3

Please sign in to comment.