Skip to content

Instantly share code, notes, and snippets.

@romainbsl
Last active March 9, 2021 09:27
Show Gist options
  • Save romainbsl/4ab6d8c1e92d3f916eaacf77eb27e361 to your computer and use it in GitHub Desktop.
Save romainbsl/4ab6d8c1e92d3f916eaacf77eb27e361 to your computer and use it in GitHub Desktop.
Sonatype: create a staging repository and pass it as a Github Action output.
#!/usr/bin/env bash
username=
password=
profileId=
description="Creating staging repository."
while [ "$1" != "" ]; do
case $1 in
-u | --username)
shift
username="$1"
;;
-p | --password)
shift
password="$1"
;;
-id | --profileId)
shift
profileId="$1"
;;
-d | --description)
shift
description="$1"
;;
*)
echo "Unknown command $1"
exit 1
;;
esac
shift
done
if test -z "$username" || test -z "$password" || test -z "$profileId"
then
echo "Missing parameter(s) for sonatype 'username' | 'password' | 'profileId'."
exit 1
fi
jsonOutput=$(
curl -s --request POST -u "$username:$password" \
--url https://oss.sonatype.org/service/local/staging/profiles/"$profileId"/start \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{ "data": {"description" : "'"$description"'"} }'
)
stagedRepositoryId=$(echo "$jsonOutput" | jq -r '.data.stagedRepositoryId')
if [ -z "$stagedRepositoryId" ]; then
echo "Error while creating the staging repository."
exit 1
else
echo "::set-output name=repository-id::$stagedRepositoryId"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment