開発覚書はてな版

個人的な開発関連の備忘録

【Github Actions】SonarCloud と連携させる(2019/09/15現在)

概要

  • Github Actions(2019/09/15現在のβ版)と SonarCloud を連携させたサンプルを作成する。
  • TSLint + Jest実行後に Github Actions上でSonarCloud Scan を実行して、SonarCloud側に保存する。

参考URL

github.com

github.com

参考過去記事

kakkoyakakko2.hatenablog.com

実行環境

  • Github Actions
  • SonarCloud
  • yarn

使用ライブラリ

  • jest - 24.9.x
  • ts-jest - 24.0.x
  • tslint - 5.20.x

サンプルソース

.github/workflows/ci.yml

name: CI

on: [push]
    
jobs:
  check:

    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: yarn install
      run:  sudo apt-get update && sudo apt-get install yarn
    - name: package install
      run:  yarn
    - name: lint
      run:  yarn lint:output
    - name: test
      run:  yarn test:cov
    - name: SonarCloudScan
      uses: sonarsource/sonarcloud-github-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties

sonar.host.url=https://sonarcloud.io
sonar.organization=yasu-s
sonar.projectKey=github-actions-and-sonarcloud
  • organization/projectKey は各環境ごとの値を設定してください。

SONAR_TOKENについて

  • SonarCloudの MyAccount -> Security -> Generate Tokens からトークンを発行する。
  • Githubの該当リポジトリSettings -> SecretsAdd a new secret から SONAR_TOKEN を登録しておく。

実行結果

f:id:kakkoya:20190914182048p:plain

https://sonarcloud.io/dashboard?id=github-actions-and-sonarcloud

サンプルソース一式

github.com

Github Actionsについて

  • 気軽にCIを始めるには簡単なので良いかと思います。
  • メトリクス周りをレポート化したい場合は、現状は他のサービスと連携する必要があるのがネックです。
  • CIがスロー問題の解決をどうしていこう・・・。Bazelでビルド結果をリモートキャッシュとかを検討した方がいいのかな・・・