Skip to content

Commit

Permalink
feature: Publish jar automaticaly from CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed Mar 19, 2019
1 parent 87aa202 commit 57e39c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
42 changes: 16 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,37 @@ jobs:
- *clean_sbt_cache
- *save_sbt_cache

publish_lib:
publish:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Publish the library
name: Publish the library and binary
command: |
sbt ";clean;retrieveGPGKeys"
sbt ";+publishSigned;sonatypeReleaseAll"
- *clean_sbt_cache
- *save_sbt_cache
sbt ";publishSigned;sonatypeRelease"
publish_binary:
<<: *default_sbt_job
steps:
- attach_workspace:
at: ~/
- *restore_sbt_cache
- run:
name: Publish the library
command: |
./scripts/publish-native.sh -n codacy-coverage-reporter -m com.codacy.CodacyCoverageReporter -t docker $(cat .version)
mkdir -p /tmp/binary
cp ~/workdir/codacy-coverage-reporter-linux-$(cat .version) /tmp/binary/codacy-coverage-reporter-linux
cp ~/workdir/target/codacy-coverage-reporter-assembly-$(cat .version).jar /tmp/binary/codacy-coverage-reporter-assembly.jar
curl -fL https://getcli.jfrog.io | sh
./jfrog bt config --interactive=false --user codacy-ci --key $BINTRAY_API_KEY
./jfrog bt upload --user codacy-ci --key $BINTRAY_API_KEY --publish /tmp/binary/ codacy/Binaries/codacy-coverage-reporter/$(cat .version) codacy-coverage-reporter-linux
./jfrog bt upload --user codacy-ci --key $BINTRAY_API_KEY --publish /tmp/binary/ codacy/Binaries/codacy-coverage-reporter/$(cat .version)
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} -delete $(cat .version) ~/workdir/codacy-coverage-reporter-linux-$(cat .version)
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

Expand All @@ -150,20 +148,12 @@ workflows:
context: CodacyAWS
requires:
- populate_cache
- publish_lib:
filters:
branches:
only:
- master
context: CodacyAWS
requires:
- compile_and_test
- checkfmt
- publish_binary:
- publish:
filters:
branches:
only:
- master
- native-binary
context: CodacyAWS
requires:
- compile_and_test
Expand Down
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,44 @@ export CODACY_PROJECT_TOKEN=%Project_Token%

### Linux amd64

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

#### Bintray

```bash
LATEST_VERSION=$(curl -Lqs https://api.bintray.com/packages/codacy/Binaries/codacy-coverage-reporter/versions/_latest | jq -r .name)
curl -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 $(curl 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') -o codacy-coverage-reporter
chmod +x codacy-coverage-reporter
./codacy-coverage-reporter report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
```

### Others

1. Download the latest jar from https://github.com/codacy/codacy-coverage-reporter/releases/latest
* Linux x86, MacOS, Windows, ...

2. Run the command below (changing <version> for the version you just downloaded)
Download the latest jar and use it to post the coverage to Codacy

```bash
$ java -jar codacy-coverage-reporter-assembly-<version>.jar report -l Java -r jacoco.xml
#### Bintray

```sh
LATEST_VERSION=$(curl -Lqs https://api.bintray.com/packages/codacy/Binaries/codacy-coverage-reporter/versions/_latest | jq -r .name)
curl -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
```

#### GitHub

```sh
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
java -jar codacy-coverage-reporter-assembly.jar report -l Java -r jacoco.xml
```

### CommitUUID Detection
Expand Down Expand Up @@ -206,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
4 changes: 2 additions & 2 deletions scripts/publish-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if [ -n "$1" ]; then
fi

function app_classpath() {
echo $(cat /dev/null | sbt ';clean;compile;export runtime:fullClasspath' | tail -n 1)
echo $(cat /dev/null | sbt ';compile;export runtime:fullClasspath' | tail -n 1)
}

function build_cmd() {
Expand Down Expand Up @@ -115,7 +115,7 @@ case "$TARGET" in
-v $HOME/.ivy2:$HOME/.ivy2 \
-v $HOME/.sbt:$HOME/.sbt \
-v $PWD:$PWD \
oracle/graalvm-ce:1.0.0-rc13 \
oracle/graalvm-ce:1.0.0-rc14 \
-c "${BUILD_CMD}"
;;
*)
Expand Down

0 comments on commit 57e39c0

Please sign in to comment.