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

Actually fixes publishing to maven central frfr #57

Merged
merged 6 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions .github/workflows/publish_library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Publish package
run: ./gradlew publish
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache -PRELEASE_SIGNING_ENABLED=true
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }}
36 changes: 36 additions & 0 deletions .github/workflows/stage_library.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish package to the Maven Central Repository
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Stage package on central portal
run: ./gradlew publishToMavenCentral --no-configuration-cache -PRELEASE_SIGNING_ENABLED=true
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,8 @@ build
# Ignore auto-generated WPILib stuff.
wpi_interface/src/main/java/frc/robot/BuildConstants.java

**/BuildConstants.java
**/BuildConstants.java

# Ignore gpg keys
gpg.key
gpg.pub
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# coppercore

## Using this in your project
To use this in your project, first make sure you have `mavenCentral()` included in your `repositories` block of your `build.gradle`:
```
repositories {
mavenCentral()
}
```
**Note:** if you are using the maven local distribution, make sure to include `mavenLocal()` in the repositories block as well.

Then, you can include any of the following dependencies as you need in your `dependencies` block of your `build.gradle`:
```
dependencies {
...
implementation "io.github.team401.coppercore:controls:VERSION"
implementation "io.github.team401.coppercore:geometry:VERSION"
implementation "io.github.team401.coppercore:math:VERSION"
implementation "io.github.team401.coppercore:monitors:VERSION"
implementation "io.github.team401.coppercore:parameter_tools:VERSION"
implementation "io.github.team401.coppercore:vision:VERSION"
implementation "io.github.team401.coppercore:wpilib_interface:VERSION"
...
}
```
where `VERSION` is available for selection from the GitHub releases or you can look it up [on the central portal](https://central.sonatype.com/search?q=coppercore) directly.

## Maven Central
This project is available on maven central! The instructions below outline how to set this up.

### Secret Keys

In order to publish on Maven Central, multiple secret keys must be maintained. The GPG key and the Sonatype token are independent though, and can be regenerated as needed without updating the other one.

**Note:** When creating a new GPG key, you must also publish the public key. See the section below on generating the GPG key for details.

The following secret keys are required to be configured in this repository's Github secrets in order to publish it to maven central:
- `ORG_GRADLE_PROJECT_mavenCentralUsername`: the username **generated from the Sonatype Central Portal** for the current user token, not to be confused with the username of the account.
- `ORG_GRADLE_PROJECT_mavenCentralPassword`: the password generated when the user token is generated. This is linked with the username above and can be generated from the Sonatype Central Portal.
- `ORG_GRADLE_PROJECT_signingInMemoryKey`: The private GPG signing key used for signing the package. Generating this is explained below.
- `ORG_GRADLE_PROJECT_signingInMemoryKeyPassword`: The password generated during the GPG key generation, if one is chosen.

It also works to include these as organization secrets in GitHub.

To temporarily set any of these variables locally for testing, you can do the following in VSCode powershell terminals:
```
$env.ENV_VARIABLE_NAME = "environment-variable-value"
```

More information about environment variables can be found [on the docs page of our gradle plugin of choice](https://vanniktech.github.io/gradle-maven-publish-plugin/central/#secrets) for publishing to the Central Portal.

### Generating a GPG key

To generate the GPG key, first generate a key locally:
```
gpg --full-generate-key
```

Pick RSA (default option) and then use a key with 4096 bits. The rest of the process is straightforward, just use the team email account ([email protected]) and your name for the user.

List the keys using this command and find the one you just generated:
```
gpg --list-secret-keys
```

Then to get the private key in plaintext and save it to a file called `gpg.key` (for easier copy and memory of what the key is), run the following:
```
gpg --export-secret-keys --armor KEY-ID | grep -v '\-\-' | grep -v '^=.' | tr -d '\n' > gpg.key
```
where `KEY-ID` is the long string of numbers and letters in the `sec` section of the key that you just generated.

The long string of the plaintext key is what needs to be set for the `ORG_GRADLE_PROJECT_signingInMemoryKey` environment variable. **This is the private key, so DO NOT share it with anyone or check it into the repository!!!**

**Note:** if you configure a passphrase for your key, you'll need to add that to a `ORG_GRADLE_PROJECT_signingInMemoryKeyPassword` environment variable.

Finally, you need to publish the **public** key so users can actually verify the signature. Do that with the following command:
```
gpg --keyserver keyserver.ubuntu.com KEY-ID
```

More information on generating GPG keys can be found [on the Sonatype docs](https://central.sonatype.org/publish/requirements/gpg/) or on the [GitHub docs](https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key).

### Publishing

#### Via GitHub Actions

Whenever a release is created on GitHub, the `publish_library` action will automatically publish the released version to the Central Portal. At any time this workflow can be run manually as well.

The `stage_library` GitHub action can be run manually to confirm that the library stages on the Central Portal. This can be used to preview a release to the Central Portal and also to ensure the maven central formatting is followed correctly.

#### Maven Local
To publish the package on your computer's local maven (typically `~/.m2/`), run the following command:
```
./gradlew publishToMavenLocal
```
75 changes: 5 additions & 70 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,77 +1,12 @@
plugins {
id "com.vanniktech.maven.publish" version "0.30.0" apply false
}

subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'


group = 'io.github.team401.coppercore'

java {
withJavadocJar()
withSourcesJar()
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId project.group
artifactId project.name
version project.version
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = project.name
description = 'Core library for FRC Team 401'
url = 'http://www.github.com/team401/coppercore'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/license/mit'
}
}
developers {
developer {
id = 'aidnem'
name = 'Aiden Mathai'
}
developer {
id = 'linglejack'
name = 'Jack Lingle'
}
developer {
id = 'avidraccoon'
name = 'Nathan Smith'
}
developer {
id = 'minh'
name = 'Minh Ngyuen'
}
}
}
}
}
repositories {
maven {
name = "OSSRH"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
}

// signing {
// sign publishing.publications.mavenJava
// }

javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
Expand Down
61 changes: 54 additions & 7 deletions controls/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.7/userguide/building_java_projects.html in the Gradle documentation.
*/
import com.vanniktech.maven.publish.SonatypeHost
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id "com.diffplug.spotless" version "6.24.0"

id "com.vanniktech.maven.publish" version "0.30.0"
}

repositories {
Expand Down Expand Up @@ -70,3 +67,53 @@ tasks.named('test') {
}

compileJava.dependsOn 'spotlessApply'


// Add this to each subproject separately.
mavenPublishing {

configure(new JavaLibrary(new JavadocJar.Javadoc(), true))
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

// Project release information.
coordinates(group, project.name, version)
pom {
name = project.name
inceptionYear = "2024"
description = 'FRC 401 core controls library'
url = 'http://www.github.com/team401/coppercore'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/license/mit'
}
}
developers {
developer {
id = 'aidnem'
name = 'Aiden Mathai'
}
developer {
id = 'linglejack'
name = 'Jack Lingle'
}
developer {
id = 'avidraccoon'
name = 'Nathan Smith'
}
developer {
id = 'minhngyuenbhs'
name = 'Minh Ngyuen'
}
developer {
id = 'jkleiber'
name = 'Justin Kleiber'
}
}
scm {
url = "https://github.com/team401/coppercore/"
connection = "scm:git:git://github.com/team401/coppercore.git"
developerConnection = "scm:git:ssh://[email protected]/team401/coppercore.git"
}
}
}
60 changes: 54 additions & 6 deletions geometry/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.7/userguide/building_java_projects.html in the Gradle documentation.
*/
import com.vanniktech.maven.publish.SonatypeHost
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'com.diffplug.spotless' version '6.24.0'
id "com.vanniktech.maven.publish" version "0.30.0"
}

repositories {
Expand Down Expand Up @@ -66,3 +64,53 @@ tasks.named('test') {
}

compileJava.dependsOn 'spotlessApply'


// Add this to each subproject separately.
mavenPublishing {

configure(new JavaLibrary(new JavadocJar.Javadoc(), true))
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

// Project release information.
coordinates(group, project.name, version)
pom {
name = project.name
inceptionYear = "2024"
description = 'FRC 401 geometry utilities library'
url = 'http://www.github.com/team401/coppercore'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/license/mit'
}
}
developers {
developer {
id = 'aidnem'
name = 'Aiden Mathai'
}
developer {
id = 'linglejack'
name = 'Jack Lingle'
}
developer {
id = 'avidraccoon'
name = 'Nathan Smith'
}
developer {
id = 'minhngyuenbhs'
name = 'Minh Ngyuen'
}
developer {
id = 'jkleiber'
name = 'Justin Kleiber'
}
}
scm {
url = "https://github.com/team401/coppercore/"
connection = "scm:git:git://github.com/team401/coppercore.git"
developerConnection = "scm:git:ssh://[email protected]/team401/coppercore.git"
}
}
}
Loading
Loading