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
4 changes: 3 additions & 1 deletion build-maven/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ build_maven() {
export_built_artifacts() {
local installed_artifacts deployed build_dir artifacts

installed_artifacts=$(grep Installing "$mvn_output" | sed 's,.*\.m2/repository/,,' || true)
# Strip the local repo prefix (Linux uses '/', Windows uses '\') and normalize
# remaining separators to '/' so downstream org/* vs com/* matching is consistent.
installed_artifacts=$(grep Installing "$mvn_output" | sed -e 's,.*\.m2[/\\]repository[/\\],,' -e 's,\\,/,g' || true)
{
echo "installed-artifacts<<EOF"
echo "$installed_artifacts"
Expand Down
5 changes: 4 additions & 1 deletion build-maven/deploy-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ echo "::endgroup::"

echo "::group::Deploy private artifacts"
echo "Deploying private artifacts..."
jf config edit deploy --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PRIVATE_DEPLOY_ACCESS_TOKEN"
# jf config edit runs non-interactively in CI ($CI=true) and silently clears any field not
# re-passed here (https://github.com/jfrog/jfrog-cli/issues/2478), so --url must be repeated.
jf config edit deploy --url "${ARTIFACTORY_URL%/artifactory*}" --artifactory-url "$ARTIFACTORY_URL" \
--access-token "$ARTIFACTORY_PRIVATE_DEPLOY_ACCESS_TOKEN"
for artifact in "${private_artifacts[@]}"; do
jf rt u --build-name "$build_name" --build-number "$BUILD_NUMBER" "$artifact" "${ARTIFACTORY_PRIVATE_DEPLOY_REPO}"
done
Expand Down
2 changes: 1 addition & 1 deletion spec/build-maven_deploy-artifacts_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ com/sonarsource/private/app/1.0/app-1.0.jar"
The line 10 of output should equal "::endgroup::"
The line 11 of output should equal "::group::Deploy private artifacts"
The line 12 of output should equal "Deploying private artifacts..."
The line 13 of output should equal "jf config edit deploy --artifactory-url https://dummy.repox --access-token private-token"
The line 13 of output should equal "jf config edit deploy --url https://dummy.repox --artifactory-url https://dummy.repox --access-token private-token"
The line 14 of output should include "com/sonarsource/private/app/1.0/app-1.0.pom private-repo-qa"
The line 15 of output should include "com/sonarsource/private/app/1.0/app-1.0.jar private-repo-qa"
The line 16 of output should equal "::endgroup::"
Expand Down
34 changes: 34 additions & 0 deletions spec/build-maven_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,40 @@ Describe 'export_built_artifacts()'
rm -rf target "$GITHUB_OUTPUT"
End

It "normalizes Windows-style backslash paths from mvn Installing lines"
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
echo "$DEPLOYED_OUTPUT_KEY=true" >> "$GITHUB_OUTPUT"

Mock mvn
case "$*" in
*"help:evaluate -Dexpression=maven.deploy.skip -q -DforceStdout"*) echo "false" ;;
*"help:evaluate -Dexpression=project.build.directory -q -DforceStdout"*) echo "target" ;;
*) echo "mvn $*" ;;
esac
End
mvn_output=$(mktemp)
{
printf '[INFO] Installing C:\\a\\work\\test-repo\\pom.xml to C:\\Users\\runneradmin\\.m2\\repository\\org\\sonarsource\\app\\1.0\\app-1.0.pom\n'
printf '[INFO] Installing C:\\a\\work\\test-repo\\target\\app-1.0.jar to C:\\Users\\runneradmin\\.m2\\repository\\org\\sonarsource\\app\\1.0\\app-1.0.jar\n'
} > "$mvn_output"
mkdir -p target
touch target/app-1.0.jar

When call export_built_artifacts
The status should be success
The lines of stdout should equal 5
The line 1 should equal "::group::Capturing built artifacts for attestation"
The line 2 should equal "Scanning for artifacts in: */target/*"
The line 3 should equal "Found artifacts for attestation:"
The line 4 should equal "./target/app-1.0.jar"
The line 5 should equal "::endgroup::"
The line 3 of contents of file "$GITHUB_OUTPUT" should equal "org/sonarsource/app/1.0/app-1.0.pom"
The line 4 of contents of file "$GITHUB_OUTPUT" should equal "org/sonarsource/app/1.0/app-1.0.jar"

rm -rf target "$GITHUB_OUTPUT"
End

It 'reports no artifacts found when build directory is empty'
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
Expand Down
Loading