Skip to content

Commit

Permalink
Merge pull request #157 from codacy/jose-melo/feat/circleci-orbs
Browse files Browse the repository at this point in the history
Add coverage reporter orb
  • Loading branch information
josemiguelmelo authored Feb 24, 2020
2 parents 6975d14 + ea3d74f commit 7ed98d0
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
70 changes: 66 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
version: 2.1

orbs:
codacy: codacy/[email protected]
codacy: codacy/[email protected]

references:
circleci_job: &circleci_job
docker:
- image: circleci/circleci-cli:0.1.5879
working_directory: ~/workdir

jobs:
publish_circleci_artifacts:
Expand All @@ -13,12 +19,54 @@ jobs:
- store_artifacts:
path: ~/workdir/artifacts/

pack_and_validate:
<<: *circleci_job
steps:
- attach_workspace:
at: ~/workdir
- run:
name: Pack orb
command: |
echo "" >> orbs/examples/codacy-coverage-report.yml
echo " orbs:" >> orbs/examples/codacy-coverage-report.yml
echo " coverage-reporter: codacy/coverage-reporter@$(cat .version)" >> orbs/examples/codacy-coverage-report.yml
circleci config pack orbs > orb.yml
- run:
name: Validate orb
command: circleci orb validate orb.yml
- persist_to_workspace:
root: ~/workdir
paths:
- "orb.yml"

publish_dev:
<<: *circleci_job
steps:
- attach_workspace:
at: ~/workdir
- deploy:
name: Publish orb as dev (deleted after 90 days)
command: circleci orb publish orb.yml codacy/coverage-reporter@dev:$(cat .version) --token $CIRCLE_TOKEN

publish_prod:
<<: *circleci_job
steps:
- attach_workspace:
at: ~/workdir
- deploy:
name: Publish final orb
command: circleci orb publish orb.yml codacy/coverage-reporter@$(cat .version) --token $CIRCLE_TOKEN

workflows:
version: 2
compile_test_deploy:
jobs:
- codacy/checkout_and_version:
write_sbt_version: true
- pack_and_validate:
context: CodacyCircleCI
requires:
- codacy/checkout_and_version
- codacy/sbt:
name: populate_cache
cmd: sbt ";set scalafmtUseIvy in ThisBuild := false;update"
Expand Down Expand Up @@ -83,10 +131,24 @@ workflows:
- codacy/publish_ghr:
name: publish_ghr
path: ~/workdir/artifacts/
context: CodacyGitHub
requires:
- publish
- publish_dev:
context: CodacyCircleCI
requires:
- publish_ghr
- pack_and_validate
filters:
branches:
ignore:
- master
- publish_prod:
context: CodacyCircleCI
requires:
- publish_ghr
- pack_and_validate
filters:
branches:
only:
- master
context: CodacyGitHub
requires:
- publish
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ after_success:
Make sure you have set `CODACY_PROJECT_TOKEN` as an environment variable in your travis job!

## CircleCI

If you want to use codacy with Circle CI and report coverage generated from your tests run in CircleCI, you can use our [coverage reporter orb](https://circleci.com/orbs/registry/orb/codacy/coverage-reporter):

Example:

jobs:
send-coverage-report:
steps:
- checkout
- "run commands to generate the coverage result"
- coverage-reporter/send_report
workflows:
version: 2
coverage-example:
jobs:
- send-coverage-report

## Troubleshooting

### `Failed to upload report: Not Found`
Expand Down
4 changes: 4 additions & 0 deletions orbs/@orb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 2.1

description: >
Orb to send Codacy coverage reports
12 changes: 12 additions & 0 deletions orbs/commands/send_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description: "Download Codacy's coverage reporter and run it"

parameters:
tool_version:
type: string
default: latest
description: "Specify Codacy's coverage reporter tool version"
steps:
- run:
command: |
export CODACY_REPORTER_VERSION=<< parameters.tool_version >>
bash <(curl -Ls https://coverage.codacy.com/get.sh)
11 changes: 11 additions & 0 deletions orbs/examples/codacy-coverage-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
description: Send coverage report to Codacy
usage:
jobs:
codacy-coverage-report:
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- "run commands to generate the coverage result"
- coverage-reporter/send_report
version: 2.1

0 comments on commit 7ed98d0

Please sign in to comment.