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

Provide an easy way to create only one repo when using multiple machines #59

Open
JavierSegoviaCordoba opened this issue Feb 15, 2021 · 6 comments

Comments

@JavierSegoviaCordoba
Copy link
Contributor

JavierSegoviaCordoba commented Feb 15, 2021

Use case

A Kotlin Multiplatform library needs two machines to generate all artifacts, Windows and macOS, so providing a way to use the same repository should be great to let us close/release that repository via CLI.

What I want to do

Using GitHub Actions with a matrix of Windows and macOS, the workflow should do:

  1. A job that creates the repository.
  2. A job that depends on the previous job and retrieves that repository, allowing publishing on it.
  3. A job that depends on o the previous job and let us close/release that repository.
@JavierSegoviaCordoba JavierSegoviaCordoba changed the title Provide an easy way to use create only repo when using multiple machines Provide an easy way to create only one repo when using multiple machines Feb 15, 2021
@JavierSegoviaCordoba
Copy link
Contributor Author

Related: #19

@vlsi
Copy link
Contributor

vlsi commented Feb 15, 2021

It might be fun if "1" was not needed:

  1. macOS job creates a repository, Windows waits for the repository to appear and publishes there (e.g. it might search for a repository with sha=... comment).

@JavierSegoviaCordoba
Copy link
Contributor Author

Should be interesting but for open source projects. But for private repositories one machine we will be spending minutes doing "nothing"

@vlsi
Copy link
Contributor

vlsi commented Feb 15, 2021

That is not minutes. "initialize staging repository" could easily be one of the first actions, so wait time would be close to zero.
Otherwise, spawning a job for the sake of "initialize repository only" looks like a significant overhead.

@martinbonnin
Copy link

martinbonnin commented Feb 23, 2021

Tentative API:

nexusPublishing {
    repositories {
        sonatype {
            username = "your-username"
            password = "your-password"

            // Will wait for a repository with the given "description" to come online before publishing
            selectRepository(pollingIntervalMillis = 10000) { 
               // here this is an instance of some NexusRepository class with id and description fields
               // this lambda gets called every 10s with the existing repositories 
               // if it returns true, publishing will start with the given one
               if (description == githubRunId) {
                 // select this repository
                 true
               } else {
                 // This lambda return style might be too Kotlin specific so maybe make something more Groovy-comatible?
                 false
               }
            }

            // Also provide an API to force a repository id and avoid looking up the repositories
            // For an example created by https://github.com/nexus-actions/create-nexus-staging-repo
            repositoryId.set("someExternalRespositoryId")
        }
    }
}

@ViliusSutkus89
Copy link

Functionality described by @JavierSegoviaCordoba is already available. Thank you devs! I'm pretty sure this is answered in other issues, but I found myself here, somehow, others might come here too, so I'll just share how it works for me.

release.yml implements (with a lot of extra stuff) a GitHub Actions workflow that is executed in 3 jobs (each of them is a separate VM):

  1. ./gradlew initializeSonatypeStagingRepository -PrepoDescription=${{ github.run_id }}-${{ github.run_attempt }}
  2. Matrix with a bunch of ./gradlew findSonatypeStagingRepository -x initializeSonatypeStagingRepository publishToMavenLocal -PrepoDescription=${{ github.run_id }}-${{ github.run_attempt }}'s
  3. ./gradlew findSonatypeStagingRepository -x initializeSonatypeStagingRepository closeSonatypeStagingRepository -PrepoDescription=${{ github.run_id }}-${{ github.run_attempt }}

All jobs from the same run share the same repository description. It doesn't even have to be the same workflow, if you can share repository description string somehow. Repository description is supplied to publish-plugins using this code:

nexusPublishing {
    project.findProperty("repoDescription")?.toString()?.let {
        if (it.isNotEmpty()) {
            repositoryDescription.set(it)
        }
    }
    repositories {
        sonatype()
    }
}

Sample run using the workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants