djspiewak / sbt-github-packages

A simple sbt plugin for publishing to GitHub Packages, in the style of sbt-sonatype and sbt-bintray
Apache License 2.0
175 stars 27 forks source link

GitHub Actions NullPointer #23

Open ghost opened 4 years ago

ghost commented 4 years ago

Receiving this consistently using the plugin version 0.5.2 for an internal/private, org-based repository.

Actions yaml file...

name: Scala CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 1.11
      uses: actions/setup-java@v1
      with:
        java-version: 1.11
    - name: Run tests
      run: sbt test
      env:
        GITHUB_TOKEN: ${{ secrets.<ACCESS_TOKEN> }}  # tried with personal acess token for private packages and GITHUB_TOKEN
        GITHUB_ACTOR: "${{ github.actor }}"
    - name: Publish artifacts
      run: sbt publish
      env:
        GITHUB_TOKEN: ${{ secrets.<ACCESS_TOKEN> }} # tried with personal acess token for private packages and GITHUB_TOKEN
        GITHUB_ACTOR: ${{ github.actor }}

In build.sbt...

githubOwner := <orgName>
githubRepository := <repoName>
githubTokenSource := TokenSource.Environment("GITHUB_TOKEN")

Error (as much as I could copy from github actions log in the web UI)

[error] java.lang.NullPointerException
[error]     at okhttp3.JavaNetAuthenticator.authenticate(JavaNetAuthenticator.java:37)
[error]     at okhttp3.internal.http.RetryAndFollowUpInterceptor.followUpRequest(RetryAndFollowUpInterceptor.java:284)
[error]     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:152)
[error]     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
[error]     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
[error]     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
[error]     at okhttp3.RealCall.execute(RealCall.java:69)
[error]     at sbt.internal.librarymanagement.ivyint.GigahorseUrlHandler.upload(GigahorseUrlHandler.scala:186)
[error]     at org.apache.ivy.util.url.URLHandlerDispatcher.upload(URLHandlerDispatcher.java:82)
[error]     at org.apache.ivy.util.FileUtil.copy(FileUtil.java:150)
[error]     at org.apache.ivy.plugins.repository.url.URLRepository.put(URLRepository.java:84)
[error]     at sbt.internal.librarymanagement.ConvertResolver$LocalIfFileRepo.put(ConvertResolver.scala:365)
[error]     at org.apache.ivy.plugins.repository.AbstractRepository.put(AbstractRepository.java:130)
[error]     at sbt.internal.librarymanagement.ConvertResolver$ChecksumFriendlyURLResolver.put(ConvertResolver.scala:117)
[error]     at sbt.internal.librarymanagement.ConvertResolver$ChecksumFriendlyURLResolver.put$(ConvertResolver.scala:104)
[error]     at sbt.internal.librarymanagement.ConvertResolver$$anonfun$defaultConvert$lzycompute$1$PluginCapableResolver$1.put(ConvertResolver.scala:164)
[error]     at org.apache.ivy.plugins.resolver.RepositoryResolver.publish(RepositoryResolver.java:216)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$5(IvyActions.scala:499)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$5$adapted(IvyActions.scala:498)
djspiewak commented 4 years ago

I think you want GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}. The angle brackets seem like the problem here.

ghost commented 4 years ago

I think you want GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}. The angle brackets seem like the problem here.

sorry that's a bit confusing.. our actual file doesn't include them I was just obfuscating the name. We used either secrets.GITHUB_TOKEN or whatever our personal access token was named.

djspiewak commented 4 years ago

If you look in the GitHub Actions log, expand the exact step which runs sbt, and then expand the top-most expandable thingy within that step. This should be a print out of all of the environment variables which are in-scope for the run. Double check to make sure that GITHUB_TOKEN is set (its value will be obfuscated).

Also it occurs to me that we check TokenSource.Environment to ensure the value is set, so this probably isn't it. You are definitely seeing some sort of bizarre authentication problem though. Let's try to simplify this down a bit…

Let's try to get the smallest possible build in the most controlled possible environment which reproduces the problem.

ghost commented 4 years ago

@djspiewak ✅ removed the GITHUB_ACTOR variable ✅ confirmed we're not using any additional resolvers ✅ confirmed I could see the obfuscated GITHUB_TOKEN used in the sbt publish command w/in the action logs

I deleted the package from the registry as an earlier broken pipe exception seemingly left it in a partially published state... I ran the action again and it published successfully! Weird... Now when I try to push updates I get the error you mentioned requiring me to use personal access tokens with read-package scope enabled for private packages.

[error] java.io.IOException: PUT operation to URL https://maven.pkg.github.com/cahcommercial/gatling-jdbc/com/cah/commtech/jdbc-gatling_2.12/2.3.1-SNAPSHOT/jdbc-gatling_2.12-2.3.1-SNAPSHOT.pom failed with status code 422: Unprocessable Entity

When using the personal access tokens, would I want to set the GITHUB_ACTOR env var along with using the personal access token from secrets?

ghost commented 4 years ago

Still getting the 422 response from github packages... The only way I can seem to get it to publish successfully is if the artifact version is bumped (e.g. 2.3.1-SNAPSHOT -> 2.3.2-SNAPSHOT) which is strange considering SNAPSHOTs should be allowed to be updated/overwritten with changes. If I try to make changes to a SNAPSHOT version and publish I always run into the following error.

[error] java.io.IOException: Server returned HTTP response code: 422 for URL: https://maven.pkg.github.com/cahcommercial/gatling-jdbc/com/cah/commtech/jdbc-gatling/2.3.2-SNAPSHOT/jdbc-gatling-2.3.2-SNAPSHOT.pom
[error]     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error]     at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[error]     at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error]     at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1969)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1964)
[error]     at java.base/java.security.AccessController.doPrivileged(Native Method)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1963)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1531)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1507)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1505)
[error]     at java.base/java.security.AccessController.doPrivileged(Native Method)
[error]     at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:795)
[error]     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1504)
[error]     at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
[error]     at org.apache.ivy.util.url.BasicURLHandler.upload(BasicURLHandler.java:285)
[error]     at org.apache.ivy.util.url.URLHandlerDispatcher.upload(URLHandlerDispatcher.java:82)
[error]     at org.apache.ivy.util.FileUtil.copy(FileUtil.java:150)
[error]     at org.apache.ivy.plugins.repository.url.URLRepository.put(URLRepository.java:84)
[error]     at sbt.internal.librarymanagement.ConvertResolver$LocalIfFileRepo.put(ConvertResolver.scala:368)
[error]     at org.apache.ivy.plugins.repository.AbstractRepository.put(AbstractRepository.java:130)
[error]     at sbt.internal.librarymanagement.ConvertResolver$ChecksumFriendlyURLResolver.put(ConvertResolver.scala:118)
[error]     at sbt.internal.librarymanagement.ConvertResolver$ChecksumFriendlyURLResolver.put$(ConvertResolver.scala:105)
[error]     at sbt.internal.librarymanagement.ConvertResolver$$anonfun$defaultConvert$lzycompute$1$PluginCapableResolver$1.put(ConvertResolver.scala:165)
[error]     at org.apache.ivy.plugins.resolver.RepositoryResolver.publish(RepositoryResolver.java:216)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$5(IvyActions.scala:501)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$5$adapted(IvyActions.scala:500)
[error]     at scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:877)
[error]     at scala.collection.Iterator.foreach(Iterator.scala:941)
[error]     at scala.collection.Iterator.foreach$(Iterator.scala:941)
[error]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
[error]     at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error]     at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error]     at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error]     at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:876)
[error]     at sbt.internal.librarymanagement.IvyActions$.publish(IvyActions.scala:500)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$3(IvyActions.scala:142)
[error]     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error]     at sbt.internal.librarymanagement.IvyActions$.withChecksums(IvyActions.scala:156)
[error]     at sbt.internal.librarymanagement.IvyActions$.withChecksums(IvyActions.scala:149)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$1(IvyActions.scala:142)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$publish$1$adapted(IvyActions.scala:132)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:251)
[error]     at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:215)
[error]     at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:77)
[error]     at sbt.internal.librarymanagement.IvySbt$$anon$1.call(Ivy.scala:87)
[error]     at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:95)
[error]     at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:80)
[error]     at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:99)
[error]     at xsbt.boot.Using$.withResource(Using.scala:10)
[error]     at xsbt.boot.Using$.apply(Using.scala:9)
[error]     at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
[error]     at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
[error]     at xsbt.boot.Locks$.apply0(Locks.scala:31)
[error]     at xsbt.boot.Locks$.apply(Locks.scala:28)
[error]     at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:87)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:209)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:206)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:250)
[error]     at sbt.internal.librarymanagement.IvyActions$.publish(IvyActions.scala:132)
[error]     at sbt.Classpaths$.$anonfun$publishTask$4(Defaults.scala:2814)
[error]     at sbt.Classpaths$.$anonfun$publishTask$4$adapted(Defaults.scala:2814)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[error]     at sbt.Execute.work(Execute.scala:290)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]     at java.base/java.lang.Thread.run(Thread.java:834)
djspiewak commented 4 years ago

Still getting the 422 response from github packages... The only way I can seem to get it to publish successfully is if the artifact version is bumped (e.g. 2.3.1-SNAPSHOT -> 2.3.2-SNAPSHOT) which is strange considering SNAPSHOTs should be allowed to be updated/overwritten with changes. If I try to make changes to a SNAPSHOT version and publish I always run into the following error.

Ah! This is very interesting. I haven't experimented with this (I simply don't use -SNAPSHOT versions), but I wonder if GitHub Packages lacks the magic Maven snapshot version support. The majority of the system is oriented around version immutability, to the point where releases are not even deleteable on public packages, so it wouldn't at all surprise me if they simply didn't implement this. My guess is that you cannot use -SNAPSHOT versions in the way you would normally expect.

Not that this is a bad thing, IMO. :-) Unstable snapshots (i.e. versions that you overwrite) are really bad practice and result in unstable and unreproducible downstream builds. You're usually better off using something like hash snapshots.

Also sorry for losing track of this issue. It fell off my notifications for some reason. Is the -SNAPSHOT use-case the only situation where errors are arising?