1

With gnatpro 19.1, I'm trying to add gnathub to my project and am wondering how to set dynamically Project_Version as in:

package Dashboard is
   for Project_Version use @git --describe --tags@; -- this needs to be updated.
end Dashboard;

I can't think of any simple way to do it.

A solution would be to use a Makefile that would configure a .gpr.in file but it seems contrived to change my whole buildchain just to add a version to the sonar config.

A simple, not automated solution, is to call the project with another switch:

gnathub -P Foo.gpr --plugins sonar-config,sonar-scanner\
 --targs:sonar-scanner -Dsonar.projectVersion=$(git describe --tags)

But this is not really usable.

Similar question is to add the option -Dsonar.branch.name=$(git branch). AFAICT, the package Dashboard, as per the documentation has no Switch switch.

Is there any solution other than passing the extra arguments or forking gnatdashboard?

4

1 回答 1

0

最好的解决方案似乎在于使用 Make 之类的工具自动执行此配置。

例如,可以定义以下 Makefile:

# This target runs all the plugins listed
# in the section Dashboard.plugins of your project’s gpr
# sonar-config and sonar-scanner shall not be listed therein.
analyzes:
    gnathub -P project

# This uses gnathub API to get the object dir where sonar-config file will be generated
OBJECT_DIR = $(shell gnathub -P project --exec object_dir.py 2>/dev/null | tail -n 1)
SONAR_PROPERTIES = $(OBJECT_DIR)/gnathub/sonar/sonar-project.properties

PROJECT_VERSION = $(shell git describe --tags)
BRANCH_NAME = $(shell git rev-parse --abbrev-ref HEAD)
# Uses gnathub to generate sonar properties file.
# Replaces the projectVersion and add branch name
# (notice that, on sonar, the branch name shall not be specified on your "master" branch)
$(SONAR_PROPERTIES): analyzes
    gnathub -P project --plugins sonar-config --incremental
    @sed -i "s/\(sonar.projectVersion = \).*/\1$(PROJECT_VERSION)/" $@
ifneq ($(BRANCH_NAME), master)
    @echo "sonar.branch.name = $(BRANCH_NAME)" >> $@
endif
    
sonar: $(SONAR_PROPERTIES)
    gnathub -P project --plugins sonar-scanner --incremental

.PHONY: sonar analyzes

在哪里object_dir.py

#!/usr/bin/env python
import GNAThub;
print (GNAThub.Project.object_dir());

然后:

$make sonar

将运行分析并使用正确的版本和分支名称(如有必要)将它们更新到 SonarQube 服务器。

于 2020-07-24T12:54:03.347 回答