Skip to content

Instantly share code, notes, and snippets.

@sstone
Forked from romainbsl/create-repository.sh
Created March 9, 2021 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstone/e3b7aa3284a6ae57e5bb65bd59406ffc to your computer and use it in GitHub Desktop.
Save sstone/e3b7aa3284a6ae57e5bb65bd59406ffc 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