Skip to content

Ability to set the source version to 'latest-snapshot' #34

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion assets/check
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
release_url=$(jq -r '.source.url //empty' < $payload)
snapshot_url=$(jq -r '.source.snapshot_url //empty' < $payload)
artifact=$(jq -r '.source.artifact //empty' < $payload)
version=$(jq -r '.version.version //empty' < $payload)
version=$(jq -r '.source.version //.version.version //empty' < $payload)
username=$(jq -r '.source.username //empty' < $payload)
password=$(jq -r '.source.password //empty' < $payload)
skip_cert_check=$(jq -r '.source.skip_cert_check //empty' < $payload)
Expand Down Expand Up @@ -69,6 +69,14 @@ if [[ "$version" = *-SNAPSHOT ]]; then
[ -n "$snapshot_url" ] && url=$snapshot_url
metadataUrl="$url/${groupId//.//}/$artifactId/$version/maven-metadata.xml"
else
if [ "$version" = "latest-snapshot" ]; then
if [ -n "$snapshot_url" ]; then
url=$snapshot_url
else
printf '\e[91m[ERROR]\e[0m invalid payload (must specify snapshot_url)\n'
exit 1
fi
fi
metadataUrl="$url/${groupId//.//}/$artifactId/maven-metadata.xml"
fi

Expand All @@ -88,6 +96,12 @@ if [[ "$version" = *-SNAPSHOT ]]; then
else
versions[1]=$(echo $metadata | xmllint --xpath "/metadata/versioning/snapshotVersions/snapshotVersion[extension='$packaging' and classifier='$classifier']/value/text()" - 2>/dev/null)
fi
elif [ "$version" = "latest-snapshot" ]; then
version=$(echo $metadata | xmllint --xpath "/metadata/versioning/versions/version[last()]/text()" - 2>/dev/null)
#The latest snapshot version is now known, so the script may be re-entered with an updated payload to get the unique version.
jq --arg version "$version" '.source.version=$version' < $payload | $0 >&3
#Second invocation of the script would have written the output, so we are done here.
exit $?
elif [ "$version" = "latest" ] || [ -z "$version" ]; then
versions[1]=$(echo $metadata | xmllint --xpath "/metadata/versioning/versions/version[last()]/text()" - 2>/dev/null)
else
Expand Down
3 changes: 0 additions & 3 deletions itest/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ source $BASE_DIR/test/helpers.sh
: "${MVN_REPO_CERT:=}"
: "${MVN_DISABLE_REDEPLOY:=false}"

# 1.0.0-20170328.031519-19
readonly UNIQUE_SNAPSHOT_PATTERN="\-[0-9]{8}\.[0-9]{6}-[0-9]{1,}"

it_can_deploy_snapshot_using_url() {

local project=$BASE_DIR/test/fixtures/project
Expand Down
46 changes: 46 additions & 0 deletions test/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,53 @@ it_can_check_latest_from_three_versions() {
'
}

it_can_check_latest_unique_version_of_particular_snapshot_from_three_versions() {

local src=$(mktemp -d $TMPDIR/check-src.XXXXXX)

local repository=$src/remote-repository
mkdir -p $repository

local url=file://$repository
local artifact=ci.concourse.maven:maven-resource:jar:standalone

local version1=$(deploy_artifact $url $artifact '1.0.0-SNAPSHOT' $src)
local version2=$(deploy_artifact $url $artifact '1.0.0-SNAPSHOT' $src)
local version3=$(deploy_artifact $url $artifact '2.0.0-SNAPSHOT' $src)

check_artifact $url $artifact '1.0.0-SNAPSHOT' $src | \
jq -e \
--arg version $version2 \
'
. == [{version: $version}]
'
}

it_can_check_latest_unique_version_of_latest_snapshot_from_three_versions() {

local src=$(mktemp -d $TMPDIR/check-src.XXXXXX)

local repository=$src/remote-repository
mkdir -p $repository

local url=file://$repository
local artifact=ci.concourse.maven:maven-resource:jar:standalone

local version1=$(deploy_artifact $url $artifact '3.0.0-SNAPSHOT' $src)
local version2=$(deploy_artifact $url $artifact '4.0.0-SNAPSHOT' $src)
local version3=$(deploy_artifact $url $artifact '4.0.0-SNAPSHOT' $src)

check_artifact $url $artifact 'latest-snapshot' $src | \
jq -e \
--arg version $version3 \
'
. == [{version: $version}]
'
}

run it_can_check_from_one_version
run it_can_check_from_three_versions
run it_can_check_latest_from_one_version
run it_can_check_latest_from_three_versions
run it_can_check_latest_unique_version_of_particular_snapshot_from_three_versions
run it_can_check_latest_unique_version_of_latest_snapshot_from_three_versions
13 changes: 12 additions & 1 deletion test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ increment_unique_id() {
UNIQUE_ID=$((UNIQUE_ID + 1))
}

# 1.0.0-20170328.031519-19
readonly UNIQUE_SNAPSHOT_PATTERN="\-[0-9]{8}\.[0-9]{6}-[0-9]{1,}"

to_filename() {
local artifact=$1
local version=$2
Expand Down Expand Up @@ -79,7 +82,14 @@ deploy_artifact() {
# cleanup dummy file
rm $file

echo $version
if [[ "$version" = *-SNAPSHOT ]]; then
#Find the unique version of what was just deployed
artifactDir=${url#*file://}/$(echo $groupId | sed 's/\./\//g')/$artifactId/$version
uniqueVersion=$(ls -t $artifactDir/*.pom | head -n 1 | grep -oE "$UNIQUE_SNAPSHOT_PATTERN")
echo "${version%-SNAPSHOT*}${uniqueVersion}"
else
echo $version
fi
}

deploy_artifact_to_manager_with_pom() {
Expand Down Expand Up @@ -146,6 +156,7 @@ check_artifact() {
'{
source: {
url: $url,
snapshot_url: $url,
artifact: $artifact
},
version: {
Expand Down