Skip to content
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

Improve Sonatype release action #5780 #252

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
30 changes: 26 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ jobs:
# Once these changes are made, they are pushed to the main branch
create-release:
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.create-release.outputs.new-version }}
needs: check-for-release-file
if: needs.check-for-release-file.outputs.has-release == 'true'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Update CHANGELOG.md and build.sbt
id: create-release
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
python3 .github/scripts/create_release.py ${LATEST_TAG} $(pwd)

VERSION_TAG="$(cat CHANGELOG.md | grep -m1 -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')"
echo "new-version=${VERSION_TAG:1}" >> $GITHUB_OUTPUT

- name: Generate a token
id: generate-token
Expand All @@ -54,7 +60,7 @@ jobs:
private-key: ${{ secrets.WELLCOME_COLLECTION_APP_PRIVATE_KEY }}

- name: Configure git
# We need to give the GitHub action full repo privileges via a PAT so that it can push the release directly into main
# We need to give the GitHub action full repo privileges so that it can push the release directly into main
run: |
git config --global user.name "GitHub on behalf of Wellcome Collection"
git config --global user.email "[email protected]"
Expand All @@ -69,7 +75,7 @@ jobs:
git add CHANGELOG.md build.sbt
git rm RELEASE.md

NEW_TAG=$(cat CHANGELOG.md | grep -m1 -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')
NEW_TAG="v${{ steps.create-release.outputs.new-version }}"
git commit -m "$(printf "Release: Bump version to ${NEW_TAG}\n\n[skip ci]")"
git tag ${NEW_TAG}

Expand Down Expand Up @@ -124,5 +130,21 @@ jobs:
cache: sbt
- name: Publish to Sonatype
run: |
PGP_PASSPHRASE=${{ secrets.GPG_PASSPHRASE }} sbt "project ${{ matrix.service }}" publishSigned
sbt "project ${{ matrix.service }}" sonatypeBundleRelease
ARTIFACT_NAME="${{ matrix.service }}_2.12"
NEW_VERSION="${{ needs.create-release.outputs.new-version }}"

# Check if the current version already exists in Sonatype.
SONATYPE_RESPONSE=$(curl -s "https://central.sonatype.com/solrsearch/select?q=g:org.wellcomecollection%20a:$ARTIFACT_NAME%20v:$NEW_VERSION")
ARTIFACT_COUNT=$(echo $SONATYPE_RESPONSE | jq '.response | .numFound')

# To check the status of the deployment in Sonatype, visit https://central.sonatype.com/publishing/deployments.
# (Credentials are stored in AWS Secrets Manager.)
if [[ $ARTIFACT_COUNT -eq 0 ]]; then
echo "Publishing package $ARTIFACT_NAME, version $NEW_VERSION to Sonatype."
PGP_PASSPHRASE=${{ secrets.GPG_PASSPHRASE }} sbt "project ${{ matrix.service }}" publishSigned

# See https://github.com/xerial/sbt-sonatype/issues/518
sbt -Dsun.net.client.defaultReadTimeout=60000 "project ${{ matrix.service }}" sonatypeBundleRelease
else
echo "Package $ARTIFACT_NAME, version $NEW_VERSION already exists in Sonatype. Exiting."
fi
Loading