Skip to content

Commit c727ce4

Browse files
committed
feat: add function to check if artifact is available on repo.
1 parent cce1cd9 commit c727ce4

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

README.org

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
** Features
55
*** automating releases
6+
*** check if artifact is available on repo.
67

78
** Automating Releases
89

@@ -30,3 +31,30 @@
3031
| --staging-profile-id | false | The staging profile id (as seen in the nexus console) |
3132
| --nexus-rul | false | The nexus server url |
3233
| --dry-run | false | Dry run. No release will take place |
34+
35+
** Checking if artifact is available on repository.
36+
37+
When automating a release process its often desirable to wait until the release is available and synchronization of artifacts to the target repository has been completed.
38+
For this purpose *is_release_available* has been created. This function accepts two arguments (groupId, artifactId and version) and optionally the repository url and return true or false.
39+
40+
41+
| Option | Required | Description |
42+
|------------+----------+--------------------------------------------------------------|
43+
| --repo-url | true | The url of the target repository (including the path prefix) |
44+
| | | |
45+
46+
This function is meant to be used along with a polling mechanism.
47+
48+
For example it can play nicely with [[https://github.com/shellib/wait][shellib's wait utility]].
49+
50+
#+BEGIN_SRC shell
51+
#!/bin/bash
52+
source $(grab github.com/shellib/maven)
53+
source $(grab github.com/shellib/wait)
54+
55+
is_on_central() {
56+
is_release_available my.group.id my-artifact-id 1.0.0
57+
}
58+
59+
wait_for --function is_on_central --backoff-multiplier 3 --max-wait-time 7200
60+
#+END_SRC

library.sh

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ DEFAULT_NEXUS_URL="https://oss.sonatype.org"
66
DEFAULT_NEXUS_STAGING_PLUGIN_VERSION="1.6.8"
77
DEFAULT_NEXUS_SERVER_ID="oss-sonatype-staging"
88

9+
DEFAULT_REPO_URL="http://repo1.maven.org/maven2"
10+
911
REPO_ANNOUNCEMENT_PREFIX="OpenedStagingProfile"
1012

1113

@@ -62,6 +64,26 @@ drop_staging_repository() {
6264
with_staging_repository "drop" $*
6365
}
6466

67+
#
68+
# Check if maven release is available
69+
is_release_available() {
70+
local groupId=$1
71+
local artifactId=$2
72+
local version=$3
73+
74+
if [ -z "$groupId" ] || [ -z "$artifactId" ] || [ -z "$version" ]; then
75+
exit 1
76+
fi
77+
78+
local repo_url=$(or $(readopt --repo-url $*) $DEFAULT_REPO_URL)
79+
local group_path=`echo $groupId | sed "s/\./\//g"`
80+
local artifact_url="$repo_url/$group_path/$artifactId/$version/"
81+
local status_code=`curl -o /dev/null -sw '%{http_code}' $artifact_url`
82+
if [ $status_code -eq 200 ]; then
83+
echo "true"
84+
fi
85+
}
86+
6587
#
6688
# Performs the actual release
6789
maven_release() {

library_test.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
source ./library.sh
4+
5+
# Test Cases
6+
should_succeed() {
7+
result=`is_release_available io.fabric8 kubernetes-client 3.1.12`
8+
if [ "$result" != "true" ]; then
9+
echo "FAIL: Release for groupId: io.fabric8 artfactId: kubernetes-client version: 3.1.12 exist, but got negative response: $result!"
10+
exit 1
11+
fi
12+
}
13+
14+
15+
should_fail() {
16+
result=`is_release_available this artifact does not exist`
17+
if [ "$result" == "true" ]; then
18+
echo "FAIL: Release doesn't exist but got positive response: $result!"
19+
exit 1
20+
fi
21+
}
22+
23+
24+
should_succeed
25+
should_fail

0 commit comments

Comments
 (0)