詳解Go言語Webアプリケーション開発を進めている。
途中、Github Actionsでmainブランチへのpush・pull requestの時にテストを実行し、その結果をコメントとして残すワークフローの作成があるのだが、途中うまくいかなかったためメモ。
octocovのインストール
$ brew install k1LoW/tap/octocov
Github Actionsワークフローの作成
# .github/workflows/ci.yml name: Test on: pull_request: jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: go-version-file: go.mod - name: Run tests with coverage report output run: go test ./... -coverprofile=coverage.out - uses: k1LoW/octocov-action@v0
.octocov.ymlの作成
以下を実行する。
$ octocov init
作成されたファイルが以下。
# generated by octocov init coverage: if: true codeToTestRatio: code: - '**/*.go' - '!**/*_test.go' test: - '**/*_test.go' testExecutionTime: if: true diff: datastores: - artifact://${GITHUB_REPOSITORY} comment: if: is_pull_request summary: if: true report: if: is_default_branch datastores: - artifact://${GITHUB_REPOSITORY}
何がうまくいかなかったか
.octocov.yml
が存在しない、というエラーがGithubActionsのログに残されていた。
おそらく、本書執筆時からのバージョンアップ等で必須ファイルとなったのではないか・・と推測。とりあえず無事にGithubActionsが動いてよかった。