Skip to content

Commit

Permalink
Merge pull request #113 from codacy/native-binary
Browse files Browse the repository at this point in the history
Native binary
  • Loading branch information
rtfpessoa authored Mar 20, 2019
2 parents c960e9f + 80961a2 commit c68f5f7
Show file tree
Hide file tree
Showing 21 changed files with 511 additions and 289 deletions.
157 changes: 157 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# CircleCI 2.0 configuration file
version: 2

# Re-usable blocks to reduce boilerplate in job definitions.
references:

sbt_jvm_defaults: &sbt_jvm_defaults
JAVA_OPTS: -Xmx3g

default_sbt_job: &default_sbt_job
machine: true
working_directory: ~/workdir
environment:
<<: *sbt_jvm_defaults

restore_sbt_cache: &restore_sbt_cache
restore_cache:
keys:
- sbt-cache-{{ .Branch }}-{{ checksum "build.sbt" }}-{{ .Environment.CIRCLE_SHA1 }}
- sbt-cache-{{ .Branch }}-{{ checksum "build.sbt" }}
- sbt-cache-{{ .Branch }}
- sbt-cache

clean_sbt_cache: &clean_sbt_cache
run:
name: CleanCache
command: |
find $HOME/.sbt -name "*.lock" | xargs rm | true
find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm | true
save_sbt_cache: &save_sbt_cache
save_cache:
key: sbt-cache-{{ .Branch }}-{{ checksum "build.sbt" }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- "~/.ivy2/cache"
- "~/.sbt"
- "~/.m2"

jobs:

checkout_and_version:
docker:
- image: codacy/git-version:latest
working_directory: ~/workdir
steps:
- checkout
- run:
name: Set version
command: /bin/git-version > .version
- run:
name: Set Sbt version
command: echo "version in ThisBuild := \"$(cat .version)\"" > version.sbt
- run:
name: Current version
command: cat .version
- persist_to_workspace:
root: ~/
paths:
- workdir/*

checkfmt:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Check formatting
command: sbt ";scalafmt::test;test:scalafmt::test;sbt:scalafmt::test"
- *clean_sbt_cache
- *save_sbt_cache

populate_cache:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Safely populate caches
command: sbt ";set scalafmtUseIvy in ThisBuild := false;update"
- *clean_sbt_cache
- *save_sbt_cache

compile_and_test:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Coverage
command: |
sbt clean compile coverage test coverageReport coverageAggregate codacyCoverage
- *clean_sbt_cache
- *save_sbt_cache

publish:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Publish the library and binary
command: |
sbt ";clean;retrieveGPGKeys"
sbt ";publishSigned;sonatypeRelease"
./scripts/publish-native.sh -n codacy-coverage-reporter -m com.codacy.CodacyCoverageReporter -t docker $(cat .version)
curl -T ~/workdir/codacy-coverage-reporter-linux-$(cat .version) -ucodacy-ci:$BINTRAY_API_KEY -H "X-Bintray-Package:codacy-coverage-reporter" -H "X-Bintray-Version:$(cat .version)" https://api.bintray.com/content/codacy/Binaries/$(cat .version)/codacy-coverage-reporter-linux
curl -T ~/workdir/target/codacy-coverage-reporter-assembly-$(cat .version).jar -ucodacy-ci:$BINTRAY_API_KEY -H "X-Bintray-Package:codacy-coverage-reporter" -H "X-Bintray-Version:$(cat .version)" https://api.bintray.com/content/codacy/Binaries/$(cat .version)/codacy-coverage-reporter-assembly.jar
curl -X POST -ucodacy-ci:$BINTRAY_API_KEY https://api.bintray.com/content/codacy/Binaries/codacy-coverage-reporter/$(cat .version)/publish
GHR_FLAGS=""
if [ "${CIRCLE_BRANCH}" != "master" ]; then
GHR_FLAGS+="-prerelease"
fi
mkdir -p /tmp/ghr-publish
cp ~/workdir/codacy-coverage-reporter-linux-$(cat .version) /tmp/ghr-publish
cp ~/workdir/target/codacy-coverage-reporter-assembly-$(cat .version).jar /tmp/ghr-publish/codacy-coverage-reporter-$(cat .version)-assembly.jar
go get github.com/tcnksm/ghr
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${GHR_FLAGS} -delete $(cat .version) /tmp/ghr-publish
- *clean_sbt_cache
- *save_sbt_cache

workflows:
version: 2

compile_deploy:
jobs:
- checkout_and_version:
context: CodacyAWS
- populate_cache:
context: CodacyAWS
requires:
- checkout_and_version
- checkfmt:
context: CodacyAWS
requires:
- populate_cache
- compile_and_test:
context: CodacyAWS
requires:
- populate_cache
- publish:
filters:
branches:
only:
- master
- native-binary
context: CodacyAWS
requires:
- compile_and_test
- checkfmt
22 changes: 13 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
logs
project/project
project/target
target
/logs/
project/project/
project/target/
target/
tmp
.history
dist
/dist/
/.idea
/*.iml
.cache
/out
/.idea_modules
.cache/
/out/
/.idea_modules/
.classpath
.project
/RUNNING_PID
Expand All @@ -20,4 +20,8 @@ codacy.pylint.conf
npm-debug.log
config

.vscode
.metals/
.vscode/
.codacy.json
codacy-coverage-reporter-linux-*
codacy-coverage-reporter-darwin-*
24 changes: 24 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version = "1.5.1"
style = IntelliJ

align = none
assumeStandardLibraryStripMargin = false
binPack.literalArgumentLists = true
binPack.parentConstructors = false
continuationIndent.defnSite = 4
danglingParentheses = true
docstrings = ScalaDoc
includeCurlyBraceInSelectChains = true
lineEndings = unix
maxColumn = 120
newlines.alwaysBeforeTopLevelStatements = true
newlines.penalizeSingleSelectMultiArgList = false
newlines.sometimesBeforeColonInMethodReturnType = true
optIn.breakChainOnFirstMethodDot = true
project.git = true
rewrite.rules = [ SortImports, PreferCurlyFors ]
spaces.afterKeywordBeforeParen = true

project.includeFilters = [".*\\.sbt$", ".*\\.scala$"]
project.excludeFilters = [".*\\.scala.html$", "target/.*", "modules/admin/target/.*"]
onTestFailure = "To fix this, run `scalafmt` within sbt or `sbt scalafmt` on the project base directory"
50 changes: 40 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,55 @@ Multi-language coverage reporter for Codacy https://www.codacy.com
Codacy assumes that coverage is previously configured for your project.
The supported coverage formats are JaCoCo and Cobertura.

You can run the coverage reporter:

1. Download the latest jar from https://github.com/codacy/codacy-coverage-reporter/releases/latest

2. Update Codacy - to do this you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API.
1. Setup the project API token. You can find the token in Project -> Settings -> Integrations -> Project API.

Then set it in your terminal, replacing %Project_Token% with your own token:

```
export CODACY_PROJECT_TOKEN=%Project_Token%
```

3. Run the command below (changing <version> for the version you just downloaded)
### Linux amd64

Download the latest binary and use it to post the coverage to Codacy

#### Bintray

```bash
LATEST_VERSION="$(curl -Ls https://api.bintray.com/packages/codacy/Binaries/codacy-coverage-reporter/versions/_latest | jq -r .name)"
curl -Ls -o codacy-coverage-reporter "https://dl.bintray.com/codacy/Binaries/${LATEST_VERSION}/codacy-coverage-reporter-linux"
chmod +x codacy-coverage-reporter
./codacy-coverage-reporter report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
```

#### GitHub

```sh
curl -Ls -o codacy-coverage-reporter "$(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | contains("codacy-coverage-reporter-linux"))) | .[0].browser_download_url')"
chmod +x codacy-coverage-reporter
./codacy-coverage-reporter report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
```
$ java -jar codacy-coverage-reporter-assembly-<version>.jar report -l Java -r jacoco.xml

### Others

* Linux x86, MacOS, Windows, ...

Download the latest jar and use it to post the coverage to Codacy

#### Bintray

```sh
LATEST_VERSION="$(curl -Ls https://api.bintray.com/packages/codacy/Binaries/codacy-coverage-reporter/versions/_latest | jq -r .name)"
curl -Ls -o codacy-coverage-reporter-assembly.jar "https://dl.bintray.com/codacy/Binaries/${LATEST_VERSION}/codacy-coverage-reporter-assembly.jar"
java -jar codacy-coverage-reporter-assembly.jar report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
```

You can also use the option `--project-token` or `-t` to set it.
#### GitHub

```sh
curl -Ls -o codacy-coverage-reporter-assembly.jar $(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({content_type, browser_download_url} | select(.content_type | contains("java-archive"))) | .[0].browser_download_url')
java -jar codacy-coverage-reporter-assembly.jar report -l Java -r jacoco.xml
```

### CommitUUID Detection

Expand Down Expand Up @@ -199,10 +229,10 @@ If you want to use codacy with Travis CI and report coverage generated from your
```yaml
before_install:
- sudo apt-get install jq
- wget -O ~/codacy-coverage-reporter-assembly-latest.jar $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets[0].browser_download_url')
- curl $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({content_type, browser_download_url} | select(.content_type | contains("application/x-java-archive"))) | .[0].browser_download_url') -o codacy-coverage-reporter-assembly.jar

after_success:
- java -jar ~/codacy-coverage-reporter-assembly-latest.jar report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
- java -jar ~/codacy-coverage-reporter-assembly.jar report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
```
Make sure you have set `CODACY_PROJECT_TOKEN` as an environment variable in your travis job!
Expand Down
Loading

0 comments on commit c68f5f7

Please sign in to comment.