zio / zio

ZIO — A type-safe, composable library for async and concurrent programming in Scala
https://zio.dev
Apache License 2.0
4.09k stars 1.29k forks source link

Release publishing may be significantly improved by using Sonatype Nexus-specific APIs #1442

Closed pshirshov closed 5 years ago

pshirshov commented 5 years ago

Right now we publish all our projects using native SBT functionality and sbt-sonatype plugin. And releases take quite a lot of time. Also release repositories may get fragmented so in some cases it may be not possible to promote a release.

I've found that using Nexus Bundles may significantly speed the process up.

Right now my flow is:

  1. I've set publishTo to a local directory (publishTo := Some(Resolver.file("file", new File("target/repo"))))
  2. Once publishSinged finishes I have my release with proper Maven layout in my local directory
  3. Then I use a simple ANT script to publish my bundle and release the repository.

We may adopt this approach. Ideally we may implement an SBT plugin doing this (I've opened a ticket for that: https://github.com/sbt/sbt/issues/4958), though we may benefit a lot even from my dirty ANT script.

The script:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:staging="antlib:org.sonatype.nexus.ant.staging">
    <property environment="env"/>
    <!-- https://oss.sonatype.org/ -->
    <property name="nexus.uri" value="${env.NEXUS_URI}" />
    <property name="nexus.user" value="${env.NEXUS_USER}" />
    <property name="nexus.pass" value="${env.NEXUS_PASS}" />
    <property name="dir.repo" value="${env.DIR_REPO}" />
    <property name="nexus.profile" value="${env.NEXUS_PROFILE}" />

    <taskdef uri="antlib:org.sonatype.nexus.ant.staging"
            resource="org/sonatype/nexus/ant/staging/antlib.xml">
    <classpath>
        <fileset dir="tasks" includes="nexus-staging-ant-tasks-*uber.jar" />
    </classpath>
    </taskdef>

    <staging:nexusStagingInfo id="target-nexus" stagingDirectory="target/staging">
        <staging:projectInfo
                groupId="org.sonatype.nexus.ant"
                artifactId="nexus-staging-ant-tasks"
                stagingProfileId="${nexus.profile}"
                version="1.0" />
        <staging:connectionInfo
            baseUrl="${nexus.uri}">
            <staging:authentication
            username="${nexus.user}"
            password="${nexus.pass}" />
        </staging:connectionInfo>
    </staging:nexusStagingInfo>

    <target name="deploy" description="Deploy: Local and Remote Staging">
        <staging:stageLocally>
            <staging:nexusStagingInfo refid="target-nexus" />
            <fileset dir="${dir.repo}" includes="**/*.*" />
        </staging:stageLocally>

        <staging:stageRemotely>
            <staging:nexusStagingInfo refid="target-nexus" />
        </staging:stageRemotely>

        <staging:releaseStagingRepository>
            <staging:nexusStagingInfo refid="target-nexus" />
        </staging:releaseStagingRepository>

        <staging:dropStagingRepository>
            <staging:nexusStagingInfo refid="target-nexus" />
        </staging:dropStagingRepository>
    </target>

</project>

The environment:

export NEXUS_URI="https://oss.sonatype.org/"
export NEXUS_USER="NEXUS-USER@gmail.com"
export NEXUS_PASS="NEXUS-PASSWORD"
# Nexus profile ID can be obtained with sbt-sonatype commands or through Nexus UI
export NEXUS_PROFILE="xxxxxxxxx"
export DIR_REPO="target/repo"

Short summary:

  1. Instead of publishing directly to Sonatype we should publish to a local directory
  2. Once we have the project published we should set the environment variables and run ant script from above
  3. Project may be released in parallel - e.g. it's fine to build, upload and release 2.12 and 2.13 artifacts independently

You may find more details here: https://github.com/sbt/sbt/issues/4958 and here: https://github.com/xerial/sbt-sonatype/issues/83

You may use this project as reference: https://github.com/7mind/izumi and ask me any questions.

Also there was a plugin allowing to run ANT tasks directly from SBT. It's unmaintained though it may be relatively easy to port it to 1.0.

NeQuissimus commented 5 years ago

hmm, is this a good idea? Private APIs are usually private for a reason...

pshirshov commented 5 years ago

I meant "nexus-specific".

NeQuissimus commented 5 years ago

Aahhhh!

pshirshov commented 5 years ago

Seems like this issue may be eventually resolved by sbt-sonatype: https://github.com/xerial/sbt-sonatype/issues/89

pshirshov commented 5 years ago

I'll open a new ticket instead of this, sbt-sonatype can publish bundles now: https://twitter.com/taroleo/status/1169777599360331776?s=21