Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: fix build and plugin execution #434

Merged
merged 1 commit into from
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 47 additions & 40 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
version: 2
jobs:
build:
build-project:
docker:
- image: checkstyle/sonarqube-maven-git:7.7-community-8c1737e
- image: cimg/openjdk:11.0.16

steps:
- checkout
- run: mvn package -Pno-validations
- persist_to_workspace:
root: /home/circleci
paths:
- project
Comment on lines +10 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need composed images, since we can build jar and generate class files in previous step, and persist the project directory for sonar execution job.


execute-sonar:
docker:
- image: sonarqube:9.0-community
working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m

steps:
- checkout
- attach_workspace:
at: /root
- run:
name: Install packages
command: apk add maven
Comment on lines +27 to +29
Copy link
Member

@nrmancuso nrmancuso Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installation of maven takes less than 5 seconds, I do not think we need custom sonar image with maven pre-installed

- run:
name: Copy jar
command: |
cp /root/project/target/checkstyle-sonar-plugin*.jar \
/opt/sonarqube/extensions/plugins/
- run:
name: Start SonarQube web service and execute maven SonarQube build
command: |
# start SonarQube web server
cd /opt/sonarqube/
./bin/run.sh &
until grep "SonarQube is up" logs/sonar.log; \
do sleep 10 && echo "Waiting for web server to come up..."; \
done

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-sonarqube-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-sonarqube
# Note that we cannot separate "start SonarQube web server" above from
# this step, as we would kill web server when step is complete.
cd /root/project
mvn sonar:sonar -Dsonar.login=admin -Dsonar.password=admin
- run:
name: Check logs for error
command: grep "ERROR" /opt/sonarqube/logs/* || test $? = 1

- run: mvn package -Pno-validations

- save_cache:
paths:
- ~/.m2
key: v1-dependencies-sonarqube-{{ checksum "pom.xml" }}
workflows:
version: 2

# run tests
- run: |-
pwd
POM_VERSION=$(grep "<version>" pom.xml | head -n 1 | sed -E "s/.*<version>//" | sed "s/<.*//")
echo "POM_VERSION="$POM_VERSION
echo "creation of jar is skipped as it was created on previous step"
#mvn package -Pno-validations
echo "coping jar to sonarqube ..."
cp target/checkstyle-sonar-plugin-$POM_VERSION.jar /opt/sonarqube/extensions/plugins/
cd /opt/sonarqube/
echo "remove existing logs ..."
rm -f logs/*.*
echo "run sonarqube web service"
./bin/run.sh &
echo "sleeping 60 to let sonar start up ..."
sleep 60
echo "check that sonar service is up ..."
grep "SonarQube is up" logs/sonar.log
echo "switching back to repository code"
cd -
pwd
echo "execution of mvn sonar:sonar ..."
mvn sonar:sonar
echo "grep for ERROR in logs ..."
grep "ERROR" /opt/sonarqube/logs/* || test $? = 1
build-sonar:
jobs:
- build-project
- execute-sonar:
requires:
- build-project