Skip to content

Commit

Permalink
SONARGO-1 Extract and build Go plugin (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ADarko22 authored Aug 13, 2024
1 parent 78ca81b commit df9252c
Show file tree
Hide file tree
Showing 803 changed files with 76,737 additions and 17 deletions.
116 changes: 103 additions & 13 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,115 @@ env:
CIRRUS_CLONE_DEPTH: "20"
CIRRUS_SHELL: bash

ARTIFACTORY_PRIVATE_USERNAME: vault-${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader
ARTIFACTORY_PRIVATE_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
ARTIFACTORY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]

GIT_SUB_MODULE: ""
GRADLE_USER_HOME: ${CIRRUS_WORKING_DIR}/.gradle

linux_image_template: &LINUX_IMAGE
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-g7-latest
cluster_name: ${CIRRUS_CLUSTER_NAME}
region: eu-central-1
namespace: default
use_in_memory_disk: true

linux_3_5_cpu_7G_template: &LINUX_3_5_CPU_7G
eks_container:
<<: *LINUX_IMAGE
cpu: 3.5
memory: 7G

linux_6_cpu_12G_java_17_template: &LINUX_6_CPU_12G_JAVA_17
eks_container:
<<: *LINUX_IMAGE
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-g7-latest
cpu: 6
memory: 12G

eks_container: &CONTAINER_DEFINITION
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:latest
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-g7-latest
cluster_name: ${CIRRUS_CLUSTER_NAME}
region: eu-central-1
namespace: default

## Build tasks

setup_gradle_cache_template: &SETUP_GRADLE_CACHE
gradle_cache:
folder: .gradle/caches
create_gradle_directory_script:
- mkdir -p "${CIRRUS_WORKING_DIR}/.gradle"

cleanup_gradle_cache_script_template: &CLEANUP_GRADLE_CACHE_SCRIPT
cleanup_gradle_script:
- /usr/bin/find "${CIRRUS_WORKING_DIR}/.gradle/caches/" -name "*.lock" -type f -delete
- rm -rf "${CIRRUS_WORKING_DIR}/.gradle/caches/4.10.2/"
- rm -rf "${CIRRUS_WORKING_DIR}/.gradle/caches/journal-1/"
- rm -rf "${CIRRUS_WORKING_DIR}/.gradle/caches/build-cache-1/"

build_task:
eks_container:
<<: *CONTAINER_DEFINITION
cpu: 1
memory: 1G
<<: *LINUX_3_5_CPU_7G
<<: *SETUP_GRADLE_CACHE
env:
# Possible values for ARTIFACTORY_DEPLOY_REPO: sonarsource-private-qa, sonarsource-public-qa
ARTIFACTORY_DEPLOY_REPO: FIXME
ARTIFACTORY_DEPLOY_REPO: sonarsource-public-qa
ARTIFACTORY_DEPLOY_USERNAME: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer username]
ARTIFACTORY_DEPLOY_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
DEPLOY_PULL_REQUEST: "true"
build_script:
- source cirrus-env BUILD
- regular_build_...
- ./gradlew build
<<: *CLEANUP_GRADLE_CACHE_SCRIPT

### QA tasks

only_if_sonarsource_qa_template: &ONLY_IF_SONARSOURCE_QA
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == "master" || $CIRRUS_BRANCH =~ "branch-.*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")

qa_task_filter_template: &QA_TASK_FILTER
depends_on:
- build
<<: *ONLY_IF_SONARSOURCE_QA

gradle_its_template: &GRADLE_ITS_TEMPLATE
<<: *SETUP_GRADLE_CACHE
run_its_script:
- |
if [ -n "${GIT_SUB_MODULE}" ]; then
git submodule update --init --depth 1 "${GIT_SUB_MODULE}"
fi
- source cirrus-env QA
- ./gradlew build -x test
- ./gradlew "${GRADLE_TASK}" "-P${ITS_PROJECT}"
"-Dsonar.runtimeVersion=${SQ_VERSION}"
"-Dorchestrator.artifactory.accessToken=${ARTIFACTORY_ACCESS_TOKEN}"
-I "${GRADLE_HOME}/init.d/repoxAuth.init.gradle.kts"
-Pqa --info --stacktrace --console plain --no-daemon --build-cache
<<: *CLEANUP_GRADLE_CACHE_SCRIPT

qa_plugin_task:

Check warning on line 92 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L92

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 92 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L92

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 92 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L92

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 92 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L92

task "qa_plugin" depends on task "build", but their only_if conditions are different
<<: *QA_TASK_FILTER
env:
ITS_PROJECT: "plugin"
GRADLE_TASK: ":its:plugin:test"
matrix:
- SQ_VERSION: "DEV"
- SQ_VERSION: "LATEST_RELEASE"
<<: *LINUX_6_CPU_12G_JAVA_17
<<: *GRADLE_ITS_TEMPLATE

qa_ruling_task:

Check warning on line 103 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L103

task "qa_ruling" depends on task "build", but their only_if conditions are different

Check warning on line 103 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L103

task "qa_ruling" depends on task "build", but their only_if conditions are different
<<: *QA_TASK_FILTER
env:
SQ_VERSION: "LATEST_RELEASE"
GRADLE_TASK: ":its:ruling:test"
ITS_PROJECT: "ruling"
GIT_SUB_MODULE: "its/sources"
<<: *LINUX_6_CPU_12G_JAVA_17
<<: *GRADLE_ITS_TEMPLATE

### Promote tasks

promote_task:
depends_on:
Expand All @@ -30,8 +119,9 @@ promote_task:
<<: *CONTAINER_DEFINITION
cpu: 1
memory: 1G
env:
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]
ARTIFACTS: FIXME # This was for Burgr links, is it still required?
script: cirrus_promote_...
#env:
#ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
#GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]
#ARTIFACTS: FIXME # This was for Burgr links, is it still required?
script:
- echo "Promoting artifacts"
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* text eol=lf
*.bat -text
*.jar -text
*.cls -text
*.trigger -text
its/sources/** -text
its/plugin/projects/** -text
**/src/test/resources/** -text

3 changes: 1 addition & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
.github/CODEOWNERS @sonarsource/analysis-jvm-squad
.github/CODEOWNERS @SonarSource/analysis-jvm-squad
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# --- Gradle
.gradle/
build/

# ---- Maven
target/
dependency-reduced-pom.xml

# ---- SonarQube analysis
.scannerwork/
.sonar/

# ---- IntelliJ IDEA
*.iws
*.iml
*.ipr
.idea/
out/
bin/

# ---- Eclipse
.classpath
.project
.settings

# ---- Mac OS X
.DS_Store
Icon?
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes

# ---- Windows
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini

.java-version
test-report.out

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "its/sources"]
path = its/sources
url = https://github.com/SonarSource/slang-test-sources.git
19 changes: 19 additions & 0 deletions LICENSE_HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SonarSource Go
* Copyright (C) 2018-$YEAR SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# sonar-go
# Sonar-Go

Go Analyzer
[![Build Status](https://api.cirrus-ci.com/github/SonarSource/slang.svg?branch=master)](https://cirrus-ci.com/github/SonarSource/slang)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.slang%3Aslang&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.sonarsource.slang%3Aslang)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.slang%3Aslang&metric=coverage)](https://sonarcloud.io/component_measures/domain/Coverage?id=org.sonarsource.slang%3Aslang)

This is a developer documentation. If you want to analyze source code in SonarQube read one of the following documentation:

We use the native Go parser to parse the Go language.

## Have questions or feedback?

To provide feedback (request a feature, report a bug, etc.) use the [SonarQube Community Forum](https://community.sonarsource.com/). Please do not forget to specify the language, plugin version, and SonarQube version.

## Building

### Setup

If you are on Windows, read the [sonar-go-to-slang/README.md](sonar-go-to-slang/README.md) instructions.


### Build
Build and run Unit Tests:

./gradlew build

## Integration Tests

By default, Integration Tests (ITs) are skipped during builds.
If you want to run them, you need first to retrieve the related projects which are used as input:

git submodule update --init its/sources

Then build and run the Integration Tests using the `its` property:

./gradlew build -Pits --info --no-daemon

You can also build and run only Ruling Tests using the `ruling` property:

./gradlew build -Pruling --info --no-daemon

## License headers

License headers are automatically updated by the spotless plugin but only for Java files.
Furthermore, there are files such as `package-info.java` and `module-info.java` that spotless ignores.
Also the Go source files are not handled. For those files use a manual script like below to update the license:
`find . -type f -name "*.go" -exec sed -i '' 's/2018-2023/2018-2024/' "{}" \;`
Loading

0 comments on commit df9252c

Please sign in to comment.