Skip to content

Commit

Permalink
ci: generate rpoert for lint and test jobs (#791)
Browse files Browse the repository at this point in the history
Add sonar project configuration file.
  • Loading branch information
jack0pan authored Feb 18, 2021
1 parent 7de7637 commit 704670b
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 26 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Cache lint reports
uses: actions/cache@v2
with:
path: |
stylelint-report.json
eslint-report.json
key: lint-reports-${{ github.sha }}
- name: StyleLint
run: yarn stylelint
run: yarn stylelint && yarn stylelint -f json -o stylelint-report.json
- name: ESLint
run: yarn eslint
run: yarn eslint && yarn eslint -f json -o eslint-report.json
test:
name: Test Coverage
needs: install
Expand All @@ -60,6 +67,11 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Cache test report
uses: actions/cache@v2
with:
path: coverage/lcov.info
key: test-report-${{ github.sha }}
- name: Test
run: yarn test --coverage
- name: Upload coverage to Codecov
Expand Down Expand Up @@ -131,3 +143,29 @@ jobs:
body_path: VERSION.md
draft: false
prerelease: false
sonar:
name: Sonar scan
needs: [lint, test]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Restore lint reports
uses: actions/cache@v2
with:
path: |
stylelint-report.json
eslint-report.json
key: lint-reports-${{ github.sha }}
- name: Restore test report
uses: actions/cache@v2
with:
path: coverage/lcov.info
key: test-report-${{ github.sha }}
- name: Upload reports to SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
84 changes: 61 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install
lint:
name: Lint Checks
name: Lint codes
needs: install
runs-on: ubuntu-latest
steps:
Expand All @@ -38,12 +38,53 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Cache lint reports
uses: actions/cache@v2
with:
path: |
stylelint-report.json
eslint-report.json
key: lint-reports-${{ github.sha }}
- name: Lint pull request title
run: echo "${{ github.event.pull_request.title }}" | npx commitlint
- name: StyleLint
run: yarn stylelint
run: yarn stylelint && yarn stylelint -f json -o stylelint-report.json
- name: ESLint
run: yarn eslint
run: yarn eslint && yarn eslint -f json -o eslint-report.json
test:
name: Test coverage
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2.1.4
with:
node-version: 14
- name: Restore Node.js modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Restore package from cache
uses: actions/cache@v2
with:
path: |
dist
es
key: packages-${{ github.sha }}
- name: Cache test report
uses: actions/cache@v2
with:
path: coverage/lcov.info
key: test-report-${{ github.sha }}
- name: Test
run: yarn test --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
directory: ./coverage/
build:
name: Build Package
needs: install
Expand All @@ -66,32 +107,29 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Build
run: yarn build
test:
name: Test Coverage
needs: build
sonar:
name: Sonar scan
needs: [lint, test]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2.1.4
with:
node-version: 14
- name: Restore Node.js modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- name: Restore package from cache
fetch-depth: 0
- name: Restore lint reports
uses: actions/cache@v2
with:
path: |
dist
es
key: packages-${{ github.sha }}
- name: Test
run: yarn test --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
stylelint-report.json
eslint-report.json
key: lint-reports-${{ github.sha }}
- name: Restore test report
uses: actions/cache@v2
with:
directory: ./coverage/
path: coverage/lcov.info
key: test-report-${{ github.sha }}
- name: Upload reports to SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ coverage
.importjs.js
storybook-static
.idea
.history
.history
*-report.json
*-report.xml
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
'<rootDir>/__mocks__/fileMock.js',
'iconfont.js': '<rootDir>/__mocks__/iconMock.js',
},
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/index.{ts,tsx}',
Expand Down
10 changes: 10 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sonar.organization=growingio
sonar.projectKey=growingio_gio-design
sonar.sources=src

# lint
sonar.css.stylelint.reportPaths=stylelint-report.json
sonar.eslint.reportPaths=eslint-report.json

# test coverage
sonar.javascript.lcov.reportPaths=coverage/lcov.info

1 comment on commit 704670b

@vercel
Copy link

@vercel vercel bot commented on 704670b Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.