Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .shellspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kcov (coverage) options
--kcov-options "--include-pattern=build-poetry,get-build-number,pr_cleanup,promote,build-gradle,config-maven,build-maven,config-npm,build-npm,build-yarn,shared"
--kcov-options "--include-pattern=build-poetry,get-build-number,pr_cleanup,promote,build-gradle,config-maven,build-maven,config-npm,build-npm,build-yarn,shared,config-gradle"
# --kcov-options "--exclude-pattern=.github,.idea,.git"

# define minimum coverage (fail otherwise)
Expand Down
2 changes: 1 addition & 1 deletion build-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ inputs:
outputs:
project-version:
description: The release version set as Gradle project version in gradle.properties
value: ${{ steps.build.outputs.project-version }}
value: ${{ steps.config-gradle.outputs.project-version }}
BUILD_NUMBER:
description: The build number, incremented or reused if already cached
value: ${{ steps.config-gradle.outputs.BUILD_NUMBER }}
Expand Down
23 changes: 2 additions & 21 deletions build-gradle/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# - SQC_EU_URL: URL of SonarQube server for sqc-eu platform
# - SQC_EU_TOKEN: Access token to send analysis reports to SonarQube for sqc-eu platform
# - RUN_SHADOW_SCANS: If true, run sonar scanner on all 3 platforms. If false, run on the platform provided by SONAR_PLATFORM.
# - CURRENT_VERSION: Current project version as in gradle.properties
# - ARTIFACTORY_ACCESS_TOKEN: Access token to read Repox repositories
# - ARTIFACTORY_DEPLOY_REPO: Name of deployment repository
# - ARTIFACTORY_DEPLOY_USERNAME: Username to deploy to Artifactory
Expand Down Expand Up @@ -52,6 +53,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/../shared/common-functions.sh"
: "${GITHUB_OUTPUT:?}"
: "${PULL_REQUEST?}" "${DEFAULT_BRANCH:?}"
: "${RUN_SHADOW_SCANS:?}"
: "${CURRENT_VERSION:?}"
if [[ "${SONAR_PLATFORM:?}" != "none" ]]; then
: "${NEXT_URL:?}" "${NEXT_TOKEN:?}" "${SQC_US_URL:?}" "${SQC_US_TOKEN:?}" "${SQC_EU_URL:?}" "${SQC_EU_TOKEN:?}"
fi
Expand Down Expand Up @@ -82,26 +84,6 @@ set_build_env() {
git_fetch_unshallow
}

set_project_version() {
current_version=$($GRADLE_CMD properties --no-scan --no-daemon --console plain | grep 'version:' | tr -d "[:space:]" | cut -d ":" -f 2)
if [[ -z "$current_version" || "$current_version" == "unspecified" ]]; then
echo "ERROR: Could not get valid version from Gradle properties. Got: '$current_version'" >&2
exit 1
fi
export CURRENT_VERSION=$current_version
release_version="${current_version/-SNAPSHOT/}"
if [[ "${release_version}" =~ ^[0-9]+\.[0-9]+$ ]]; then
release_version="${release_version}.0"
fi
release_version="${release_version}.${BUILD_NUMBER}"
echo "Replacing version $current_version with $release_version"
sed -i.bak "s/$current_version/$release_version/g" gradle.properties
echo "project-version=$release_version" >> "$GITHUB_OUTPUT"
echo "PROJECT_VERSION=$release_version" >> "$GITHUB_ENV"
echo "PROJECT_VERSION=$release_version"
export PROJECT_VERSION=$release_version
}

should_deploy() {
# Disable deployment when explicitly requested
if [[ "${DEPLOY}" != "true" ]]; then
Expand Down Expand Up @@ -300,7 +282,6 @@ main() {
check_tool java -version
set_gradle_cmd
set_build_env
set_project_version
gradle_build
}

Expand Down
1 change: 1 addition & 0 deletions build-maven/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# - ARTIFACTORY_DEPLOY_REPO: Deployment repository name
# - ARTIFACTORY_DEPLOY_USERNAME: Username used by artifactory-maven-plugin
# - ARTIFACTORY_DEPLOY_PASSWORD: Access token to deploy to the repository
# - CURRENT_VERSION: Current project version as in pom.xml
# - DEFAULT_BRANCH: Default branch name (e.g. main)
# - PULL_REQUEST: Pull request number (e.g. 1234) or empty string
#
Expand Down
41 changes: 35 additions & 6 deletions config-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ inputs:
outputs:
BUILD_NUMBER:
description: The build number, incremented or reused if already cached
value: ${{ steps.get_build_number.outputs.BUILD_NUMBER }}
value: ${{ steps.get-build-number.outputs.BUILD_NUMBER }}
current-version:
description: The project version set in the gradle.properties (before replacement). Also set as environment variable CURRENT_VERSION
value: ${{ steps.set-version.outputs.current-version }}
project-version:
description: The project version with build number (after replacement). Also set as environment variable PROJECT_VERSION
value: ${{ steps.set-version.outputs.project-version }}

runs:
using: composite
Expand Down Expand Up @@ -63,12 +69,20 @@ runs:
echo "::endgroup::"

- name: Get build number
id: get_build_number
id: get-build-number
uses: ./.actions/get-build-number
with:
host-actions-root: ${{ steps.set-path.outputs.host_actions_root }}

- id: config-gradle-completed
if: env.CONFIG_GRADLE_COMPLETED != ''
shell: bash
run: |
echo "Action already called by $CONFIG_GRADLE_COMPLETED, execution skipped."
echo "skip=true" >> $GITHUB_OUTPUT

- name: Set parameter for Vault
if: steps.config-gradle-completed.outputs.skip != 'true'
shell: bash
env:
ARTIFACTORY_READER_ROLE: ${{ inputs.artifactory-reader-role != '' && inputs.artifactory-reader-role ||
Expand All @@ -78,6 +92,7 @@ runs:

- name: Get secrets from Vault
id: secrets
if: steps.config-gradle-completed.outputs.skip != 'true'
uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
with:
secrets: |
Expand All @@ -86,6 +101,7 @@ runs:
${{ inputs.use-develocity == 'true' && 'development/kv/data/develocity token | DEVELOCITY_TOKEN;' || '' }}

- name: Set environment variables for Artifactory authentication
if: steps.config-gradle-completed.outputs.skip != 'true'
shell: bash
env:
ARTIFACTORY_URL:
Expand Down Expand Up @@ -117,14 +133,15 @@ runs:

# Configure Gradle for comprehensive caching and build summary reporting. It does not install Gradle.
- name: Configure Gradle
if: steps.config-gradle-completed.outputs.skip != 'true'
uses: gradle/actions/setup-gradle@748248ddd2a24f49513d8f472f81c3a07d4d50e1 # v4.4.4
with:
develocity-injection-enabled: ${{ inputs.use-develocity == 'true' }}
cache-disabled: true
develocity-plugin-version: '4.0'

- name: Generate Gradle Cache Key
if: ${{ inputs.disable-caching != 'true' }}
if: steps.config-gradle-completed.outputs.skip != 'true' && inputs.disable-caching != 'true'
shell: bash
run: |
# Generate cache key from all Gradle files
Expand All @@ -139,7 +156,7 @@ runs:
rm -f gradle-md5-sums.txt

- name: Restore Gradle Cache
if: ${{ inputs.disable-caching != 'true' }}
if: steps.config-gradle-completed.outputs.skip != 'true' && inputs.disable-caching != 'true'
uses: SonarSource/gh-action_cache@v1
id: gradle-cache-restore
with:
Expand All @@ -150,22 +167,34 @@ runs:

# $GRADLE_USER_HOME is typically set to ~/.gradle/ by gradle/actions/setup-gradle
- name: Configure Gradle Authentication
if: steps.config-gradle-completed.outputs.skip != 'true'
shell: bash
run: |
GRADLE_INIT_DIR="$GRADLE_USER_HOME/init.d"
mkdir -p "$GRADLE_INIT_DIR"
cp "${GITHUB_ACTION_PATH}/resources/repoxAuth.init.gradle.kts" "$GRADLE_INIT_DIR/"

- name: Update project version and set current-version and project-version variables
id: set-version
if: steps.config-gradle-completed.outputs.skip != 'true'
shell: bash
run: ${GITHUB_ACTION_PATH}/set_gradle_project_version.sh

- name: Extract Develocity hostname
id: develocity-hostname
if: ${{ inputs.use-develocity == 'true' }}
if: steps.config-gradle-completed.outputs.skip != 'true' && inputs.use-develocity == 'true'
shell: bash
run: echo "hostname=$(echo '${{ inputs.develocity-url }}' | sed 's|https://||' | sed 's|/$||')" >> $GITHUB_OUTPUT

- name: Deactivate UseContainerSupport on github-ubuntu-* runners
if: runner.os == 'Linux' && runner.environment == 'github-hosted'
if: steps.config-gradle-completed.outputs.skip != 'true' && runner.os == 'Linux' && runner.environment == 'github-hosted'
shell: bash
run: |
echo "::warning title=Deactivating UseContainerSupport::The GitHub-hosted Ubuntu runners have an issue with Java's" \
"UseContainerSupport feature."
echo "JAVA_TOOL_OPTIONS=${JAVA_TOOL_OPTIONS:=-XX:-UseContainerSupport}" >> "$GITHUB_ENV"

- name: Set Config Gradle completed
if: steps.config-gradle-completed.outputs.skip != 'true'
shell: bash
run: echo "CONFIG_GRADLE_COMPLETED=$GITHUB_ACTION" >> "$GITHUB_ENV"
69 changes: 69 additions & 0 deletions config-gradle/set_gradle_project_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Config script for SonarSource Maven projects.
#
# Required environment variables (must be explicitly provided):
# - BUILD_NUMBER: Build number for versioning
#
# GitHub Actions auto-provided:
# - GITHUB_OUTPUT: Path to GitHub Actions output file
# - GITHUB_ENV: Path to GitHub Actions environment file
#
# Optional user customization:
# - CURRENT_VERSION and PROJECT_VERSION: If both are set, they will be used as-is and no version update will be performed.

set -euo pipefail

: "${BUILD_NUMBER:?}"
: "${GITHUB_OUTPUT:?}" "${GITHUB_ENV:?}"

# shellcheck source=SCRIPTDIR/../shared/common-functions.sh
source "$(dirname "${BASH_SOURCE[0]}")/../shared/common-functions.sh"

set_gradle_cmd() {
if [[ -f "./gradlew" ]]; then
export GRADLE_CMD="./gradlew"
elif check_tool gradle; then
export GRADLE_CMD="gradle"
else
echo "Neither ./gradlew nor gradle command found!" >&2
exit 1
fi
}

set_project_version() {
local current_version
current_version=$($GRADLE_CMD properties --no-scan --no-daemon --console plain | grep 'version:' | tr -d "[:space:]" | cut -d ":" -f 2)
if [[ -z "$current_version" || "$current_version" == "unspecified" ]]; then
echo "ERROR: Could not get valid version from Gradle properties. Got: '$current_version'" >&2
return 1
fi

# Saving the snapshot version to the output and environment variables
# This is used by the sonar-scanner to set the value of sonar.projectVersion without the build number
echo "CURRENT_VERSION=$current_version"
echo "CURRENT_VERSION=$current_version" >> "$GITHUB_ENV"
export CURRENT_VERSION=$current_version

release_version="${current_version/-SNAPSHOT/}"
if [[ "${release_version}" =~ ^[0-9]+\.[0-9]+$ ]]; then
release_version="${release_version}.0"
fi
release_version="${release_version}.${BUILD_NUMBER}"
echo "Replacing version $current_version with $release_version"
sed -i.bak "s/$current_version/$release_version/g" gradle.properties
echo "project-version=$release_version" >> "$GITHUB_OUTPUT"
echo "PROJECT_VERSION=$release_version" >> "$GITHUB_ENV"
echo "PROJECT_VERSION=$release_version"
export PROJECT_VERSION=$release_version
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [[ -n "${CURRENT_VERSION:-}" && -n "${PROJECT_VERSION:-}" ]]; then
echo "Using provided CURRENT_VERSION $CURRENT_VERSION and PROJECT_VERSION $PROJECT_VERSION without changes."
echo "current-version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "project-version=$PROJECT_VERSION" >> "$GITHUB_OUTPUT"
else
set_gradle_cmd
set_project_version
fi
fi
10 changes: 5 additions & 5 deletions config-maven/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ inputs:
outputs:
BUILD_NUMBER:
description: The current build number. Also set as environment variable BUILD_NUMBER
value: ${{ steps.get_build_number.outputs.BUILD_NUMBER }}
value: ${{ steps.get-build-number.outputs.BUILD_NUMBER }}
current-version:
description: The project version set in the pom.xml (before replacement). Also set as environment variable CURRENT_VERSION
value: ${{ steps.config.outputs.current-version }}
value: ${{ steps.set-version.outputs.current-version }}
project-version:
description: The project version with build number (after replacement). Also set as environment variable PROJECT_VERSION
value: ${{ steps.config.outputs.project-version }}
value: ${{ steps.set-version.outputs.project-version }}

runs:
using: composite
Expand Down Expand Up @@ -74,7 +74,7 @@ runs:
echo "::endgroup::"

- uses: ./.actions/get-build-number
id: get_build_number
id: get-build-number
with:
host-actions-root: ${{ steps.set-path.outputs.host_actions_root }}

Expand Down Expand Up @@ -173,7 +173,7 @@ runs:
restore-keys: maven-${{ runner.os }}-${{ github.workflow }}-

- name: Update project version and set current-version and project-version variables
id: config
id: set-version
if: steps.from-env.outputs.skip != 'true'
shell: bash
working-directory: ${{ inputs.working-directory }}
Expand Down
17 changes: 8 additions & 9 deletions config-maven/set_maven_project_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ get_current_version() {
# Update current_version variable with the current project version.
# Then remove the -SNAPSHOT suffix if present, complete with '.0' if needed, and append the build number at the end.
set_project_version() {
if [[ -n "${CURRENT_VERSION:-}" && -n "${PROJECT_VERSION:-}" ]]; then
echo "Using provided CURRENT_VERSION $CURRENT_VERSION and PROJECT_VERSION $PROJECT_VERSION without changes."
echo "current-version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "project-version=$PROJECT_VERSION" >> "$GITHUB_OUTPUT"
return 0
fi

local current_version
if ! current_version=$(get_current_version 2>&1); then
echo -e "::error file=pom.xml,title=Maven project version::Could not get 'project.version' from Maven project\nERROR: $current_version"
Expand Down Expand Up @@ -79,6 +72,12 @@ set_project_version() {
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
check_tool mvn --version
set_project_version
if [[ -n "${CURRENT_VERSION:-}" && -n "${PROJECT_VERSION:-}" ]]; then
echo "Using provided CURRENT_VERSION $CURRENT_VERSION and PROJECT_VERSION $PROJECT_VERSION without changes."
echo "current-version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "project-version=$PROJECT_VERSION" >> "$GITHUB_OUTPUT"
else
check_tool mvn --version
set_project_version
fi
fi
Loading
Loading