Skip to content

Instantly share code, notes, and snippets.

@Laxystem
Last active April 26, 2023 19:55
Show Gist options
  • Save Laxystem/7c40cd05904632c91a86a57a6263a92d to your computer and use it in GitHub Desktop.
Save Laxystem/7c40cd05904632c91a86a57a6263a92d to your computer and use it in GitHub Desktop.
Publishing to Modrinth & Github Packages using a Github Workflow

Layla's Website

  1. Create an env in your GitHub settings. Call it gradle.
  2. Add a variable to the env named RELEASE_TYPE, and give it a value of alpha, beta, or release.
  3. Add a secret to the env named MODRINTH_TOKEN, and give it the value of your Modrinth Token.
  4. Paste publishing.yml in .github/workflows/publishing.yml
  5. Add the following to your build.gradle.kts:
plugins {
  `maven-publish`
  // also add the minotaur plugin. See modrinth docs.
}

modrinth { // for more info see modrinth docs
  token.set(System.getenv("MODRINTH_TOKEN"))
  versionType.set(System.getenv("MODRINTH_TYPE"))
  uploadFile.set(tasks.remapJar)
  
  syncBodyFrom.set(rootProject.file("README.md").readText())
}

  publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/USERNAME/REPOSITORY") // <- replace these
            credentials {
                username = System.getenv("GITHUB_ACTOR")
                password = System.getenv("GITHUB_TOKEN")
            }
        }
    }
    
    publications {
      register<MavenPublication>("MOD_NAME") { <- replace this
          from(components["java"])
          groupId = "io.github.USERNAME" <- and this
          artifactId = "MOD_ID" <- and this
      }
    }
}
  1. That's it! you're done!

If you want to create a version, just use this handy tool!

GitHub Import

GitHub provides you the version in maven format. Example. All you need to do is to convert it to Gradle:

repositories {
    maven {
        name = "GitHub Packages"
        url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY")
    }
}

dependencies {
  modImplementation("${groupId}:${artifactId}:${version}")
}

Modrinth Import

repositories {
    exclusiveContent {
        forRepository {
            maven {
                name = "Modrinth"
                url = "https://api.modrinth.com/maven"
            }
        }
        filter {
            includeGroup "maven.modrinth"
        }
    }
}

dependencies {
    modImplementation "maven.modrinth:MOD_ID:mcMC_VERSION-MOD_VERSION"
}
name: Release
on:
release:
types: [created]
permissions:
contents: read
packages: write
jobs:
release:
name: Publish
runs-on: ubuntu-latest
environment: gradle
steps:
- uses: actions/checkout@v3
- name: Set Up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'oracle'
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build
- name: Publish to Modrinth
run: ./gradlew modrinth modrinthSyncBody # requires minotaur plugin
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MODRINTH_TYPE: ${{ vars.RELEASE_TYPE }}
- name: Publish to Github Packages
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: publish
env:
GITHUB_ACTOR: ${{ github.actor }} # see: https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-gradle#publishing-packages-to-github-packages
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment