5959 - name : Check credentials
6060 run : |
6161 set -e
62- echo "Checking SonaType SONATYPE_BASIC_AUTH_CREDENTIALS "
63- curl --fail -X GET - H "Content-Type :application/xml " -u " ${{ secrets.SONATYPE_BASIC_AUTH_CREDENTIALS }}" https://oss. sonatype.org/service/local/staging/profiles/b39883a429024e > /dev/null
62+ echo "Checking SonaType PORTAL_ACCESS_TOKEN "
63+ curl --fail -H "Accept :application/json " -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" ' https://ossrh-staging-api.central. sonatype.com/manual/search/repositories?state=open'
6464 echo "Checking GitHub ACCESS_TOKEN"
6565 curl -f -H "Authorization: Bearer ${{ secrets.ACCESS_TOKEN }}" -H 'Accept: application/vnd.github.v3.raw' -s https://api.github.com/repos/$REPO > /dev/null
6666 - name : Configure GPG key
@@ -139,7 +139,7 @@ jobs:
139139 mkdir unpacked
140140 cd unpacked
141141 unzip -q ../asset.zip
142- head CHANGELOG.md
142+ head CHANGELOG.md
143143 - name : GPG sign all Maven files
144144 run : |
145145 cd unpacked/maven
@@ -155,10 +155,11 @@ jobs:
155155 # Code mostly by mezzargh
156156 set -e
157157 WD=`pwd`
158+ # we use the description field for cross identification between APIs (I could not find an alternative yet), so we can fetch correct repo for promotion.
158159 START_XML=$(cat << EOF
159160 <promoteRequest>
160161 <data>
161- <description>Publish ${GITHUB_REPOSITORY} ${RELEASE} Artifacts </description>
162+ <description>${{github.repository}}-${{github.run_id}}-${{github.run_attempt}} </description>
162163 </data>
163164 </promoteRequest>
164165 EOF
@@ -169,18 +170,43 @@ jobs:
169170 cd unpacked/maven/repository
170171 cp $WD/start.xml start.xml
171172 cat start.xml
172- curl -- fail -v -X POST -d @start.xml -H "Content-Type:application/xml" -u " ${{ secrets.SONATYPE_BASIC_AUTH_CREDENTIALS }}" https://oss. sonatype.org /service/local/staging/profiles/b39883a429024e/start -o $WD/finish.xml
173+ curl -sS -- fail -v -X POST -d @start.xml -H "Content-Type:application/xml" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" https://ossrh-staging-api.central. sonatype.com /service/local/staging/profiles/b39883a429024e/start -o $WD/finish.xml
173174 rm start.xml
175+ curl --fail -H "Accept:application/json" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" 'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?state=open' -o results.json
176+ SELECTOR="${{github.repository}}-${{github.run_id}}-${{github.run_attempt}}"
177+ repository_namespace=`cat results.json | jq -jr --arg SELECTOR $SELECTOR ".repositories[] | select(.description == \"$SELECTOR\").key" | jq -jRrs "@uri"`
178+ echo $repository_namespace
179+ rm results.json
174180 ls -lahn $WD
175181 cat $WD/finish.xml
176182 staging_dir=$(echo $(awk -F '[<>]' '/stagedRepositoryId/{print $3}' $WD/finish.xml))
183+ rm $WD/finish.xml
177184 echo "Staging dir is '${staging_dir}'"
178185 find . -type f | sed -E s'@./@@' | grep -v start.xml > $WD/artifacts.list
179186 ls -lahn $WD
180187 echo "Uploading $(wc -l $WD/artifacts.list | sed "s/^ *\([0-9]*\) .*$/\1/") artifacts"
181188 awk '{printf "%5d\t%s\n", NR, $0}' < $WD/artifacts.list
182- cat $WD/artifacts.list | xargs -n 1 -I {} curl --fail -u "${{ secrets.SONATYPE_BASIC_AUTH_CREDENTIALS }}" --upload-file {} https://oss.sonatype.org/service/local/staging/deployByRepositoryId/${staging_dir}/{}
183- cp $WD/finish.xml finish.xml
184- cat finish.xml
185- curl --fail -X POST -d @finish.xml -H "Content-Type:application/xml" -u "${{ secrets.SONATYPE_BASIC_AUTH_CREDENTIALS }}" -H "Content-Type:application/xml" https://oss.sonatype.org/service/local/staging/profiles/b39883a429024e/finish
186- echo https://oss.sonatype.org/content/repositories/${staging_dir}
189+ cat $WD/artifacts.list | xargs -n 1 -I {} curl -sS --fail -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" --upload-file {} https://ossrh-staging-api.central.sonatype.com/service/local/staging/deployByRepositoryId/${staging_dir}/{}
190+ curl -s -X POST -H "Accept:application/json" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/${repository_namespace}?publishing_type=user_managed
191+ while [[ $(curl -sS --fail -H "Accept:application/json" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" 'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories' | jq -r ".repositories[] | select(.description == \"$SELECTOR\").portal_deployment_id") == "null" ]]; do
192+ echo "Waiting for deployment ID...";
193+ curl -s -X POST -H "Accept:application/json" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$repository_namespace?publishing_type=user_managed;
194+ sleep 5;
195+ done
196+ curl -sS --fail -H "Accept:application/json" -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" 'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories' -o final_result.json
197+ portal_id=`cat final_result.json | jq -jr ".repositories[] | select(.description == \"$SELECTOR\").portal_deployment_id"`
198+ echo "Closing OSSRH staging repo $repository_namespace, and continueing with Portal APIs"
199+ echo "Promotion to Portal deployment staging '$portal_id' is pending ...";
200+ while [[ $(curl -sS -X 'POST' -H 'Accept:application/json' -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" "https://central.sonatype.com/api/v1/publisher/status?id=$portal_id" | jq -r '.deploymentState') == "PENDING" ]]; do
201+ echo "..."
202+ sleep 5;
203+ done
204+ echo "Validing Portal deployement ...";
205+ while [[ $(curl -sS -X 'POST' -H 'Accept:application/json' -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" "https://central.sonatype.com/api/v1/publisher/status?id=$portal_id" | jq -r '.deploymentState') == "VALIDATING" ]]; do
206+ echo "..."
207+ sleep 5;
208+ done
209+ echo "Dropping OSSRH staging repo: $repository_namespace"
210+ curl -sS -X 'DELETE' -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" https://ossrh-staging-api.central.sonatype.com/manual/drop/repository/$repository_namespace
211+ curl -sS -X 'POST' -H 'Accept:application/json' -H "Authorization: Bearer ${{ secrets.PORTAL_ACCESS_TOKEN }}" "https://central.sonatype.com/api/v1/publisher/status?id=$portal_id" | jq -e 'if .deploymentState == "FAILED" then error(.errors | tostring) else .deploymentState end'
212+ echo "Portal Staging repository: https://central.sonatype.com/api/v1/publisher/deployment/$portal_id/download/"
0 commit comments