Skip to content

Instantly share code, notes, and snippets.

@KiyonoKara
Last active December 24, 2023 01:18
Show Gist options
  • Save KiyonoKara/76a84ec9c9c436c6aee1dd62a6ab4e77 to your computer and use it in GitHub Desktop.
Save KiyonoKara/76a84ec9c9c436c6aee1dd62a6ab4e77 to your computer and use it in GitHub Desktop.
A guide for publishing Scala packages to GitHub's Apache Maven registry.

Publishing Scala Packages to the GitHub Package Registry

Steps

  1. Configure your package naming and organization (generally optional).
   org  
    ⤷ name
       ⤷ package
 
  1. Set up the package information in your build.sbt file. Complete the fields with your repository's information. The GitHub token is provided in the Actions environment so this sbt file will assume it exists upon execution.
name := "PACKAGE_NAME"

version := "1.0.0"

scalaVersion := "2.13.6"

organization := "org.name"

versionScheme := Some("semver-spec")

homepage := Some(url("https://github.com/USERNAME/PACKAGE"))
licenses := Seq("LICENSE" -> url("LICENSE_URL"))
publishMavenStyle := true
pomIncludeRepository := { _ => false }

publishTo := Some("GitHub USERNAME Apache Maven Packages" at "https://maven.pkg.github.com/USERNAME/PACKAGE")
credentials += Credentials(
  "GitHub Package Registry",
  "maven.pkg.github.com",
  "USERNAME",
  System.getenv("GITHUB_TOKEN")
)
  1. Test your package and make sure it's functional.

  2. Upload your repository to GitHub to prepare it for publishing as a package.

  3. Visit Actions tab of the repository and look for the Scala workflow set up.

    • The workflow's title should say Scala by GitHub Actions and have sbt test as the default code in the workflow.
    • Once you find configuration, click the Set up this workflow button.
  4. In the workflow editor, use the YAML code and replace the name with your Scala package's name.

name: Scala Package
on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'
    - name: Run tests
      run: sbt test
  publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'
    - name: Publish package
      run: sbt test publish
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  • You may also change the workflow run event to be prompted by created releases instead of pushes.
     on:
       release:
         types: [created]
         branches: [main]
  1. Commit and push the file.

    • If the workflow was configured for created releases, create a release for the action to run.
  2. Visit the workflow run.

  3. If the workflow passes all checks and publishing is successful, a packages tab will on the repository's homepage and you can manage its packages from there. You may add a description to the package as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment