Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 2
Message 1 of 1

How to use GitHub Actions to publish to only one repository

Hello,

I'm currently using Github Actions to publish my packages with the following action.

 

name: Publish release

on:
  release:
    types: [published]

jobs:
  publish-release:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout latest code
        uses: actions/checkout@v2

      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - name: Setup build cache
        uses: actions/cache@v1
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - name: Publish artifact
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

        # The GITHUB_REF tag comes in the format 'refs/tags/xxx'.
        # So if we split on '/' and take the 3rd value, we can get the release name.
        run: |
          NEW_VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
          echo "New version: ${NEW_VERSION}"
          echo "Github username: ${GITHUB_ACTOR}"
          ./gradlew build
          ./gradlew -Pversion=${NEW_VERSION} publish --stacktrace 

 

Let's assume my Java Library is managed under:

https://github.com/myCompany/myJavaLibrary

 

 

publishing {
    publications {
        create("default") {
            from(components["java"])
            artifact(dokkaJar)
        }
    }

    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/myCompany/myJavaLibrary")
            credentials {
                username = project.findProperty("GITHUB_ACTOR") as String? ?: System.getenv("GITHUB_ACTOR")
                password = project.findProperty("GITHUB_TOKEN") as String? ?: System.getenv("GITHUB_TOKEN")
            }
        }
    }
}

 

Using this in my build.gradle.kts works great, and the packages get's build deployed to 

 

https://maven.pkg.github.com/myCompany/myJavaLibrary 

 

However, this forces me, that for each library, I need to add repository:

repositories {
    mavenCentral()
    jcenter()
    maven {
        url = uri("https://maven.pkg.github.com/myCompany/myJavaLibrary")
        credentials {
            username = project.findProperty("GITHUB_ACTOR") as String? ?: System.getenv("GITHUB_ACTOR")
            password = project.findProperty("GITHUB_TOKEN") as String? ?: System.getenv("GITHUB_TOKEN")
        }
    }
    maven {
        url = uri("https://maven.pkg.github.com/myCompany/myJavaLibrary2")
        credentials {
            username = project.findProperty("GITHUB_ACTOR") as String? ?: System.getenv("GITHUB_ACTOR")
            password = project.findProperty("GITHUB_TOKEN") as String? ?: System.getenv("GITHUB_TOKEN")
        }
    }
}

 

How can I solve this, so i.e. I just need https://maven.pkg.github.com/myCompany ?

 

I already tried, creating a dedicated repo like : 

 

https://maven.pkg.github.com/myCompany/packages

 

But it seems secrets.GITHUB_TOKEN is not allowed to publish to this repo then, when the action is executed within https://github.com/myCompany/myJavaLibrary