Is it possible to use GitHub Actions to upload to bintray?

I want to use GitHub Actions to build my java project and upload it to Bintray when creating a new release.

Now my question is: Is this even possible?

I use gradle and therefore attempted to use the gradle workflow.

The gradle.yml I setup looks like this:

name: Java CI

on:
  release:
    branches:
    - master


jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Build with Gradle
      env:
        bintrayUser: ${{ secrets.bintrayUsername }}
        bintrayApiKey: ${{ secrets.bintrayApiKey }}
      run: ./gradlew bintrayUpload

The ${{ secrets.[…] }} are setup in the Repository’s Secrets setting.

I also use the following build.gradle:

plugins{
    id 'com.jfrog.bintray' version '1.8.4'
    id 'java-library'
    id 'idea'
    id 'maven-publish'
    id 'maven'
}

group = 'com.andre601'
version = '2.3.1'

sourceCompatibility = 1.8

jar{
    baseName = 'JavaBotBlockAPI'
}

repositories{
    mavenCentral()
    jcenter()
}

dependencies{
    api group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0'
    api group: 'org.json', name: 'json', version: '20180813'
    api group: 'org.jetbrains', name: 'annotations', version: '16.0.2'
    api(group: 'net.dv8tion', name: 'JDA', version: '4.0.0_45'){
        exclude(module: 'opus-java')
    }
    api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.7.0'
}

task sourcesJar(type: Jar, dependsOn: classes){
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc){
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts{
    archives sourcesJar
    archives javadocJar
}

bintray{
    user = System.getenv("bintrayUser")
    key = System.getenv("bintrayApiKey")
    publications = ['JavaBotBlockAPIRelease']
    pkg{
        repo = 'maven'
        name = 'JavaBotBlockAPI'
        licenses = ['MIT']
        vcsUrl = 'https://github.com/botblock/JavaBotBlockAPI'
        version{
            name = project.version
            released = new Date()
        }
    }
}

publishing{
    publications{
        JavaBotBlockAPIRelease(MavenPublication){
            from components.java
            groupId group
            artifactId archivesBaseName
            version version
            artifact javadocJar
            artifact sourcesJar
        }
    }
}

The issue now is that the Action fails at the “Build with Gradle” task with the error "./gradlew: Permission denied

Is there any way I could make this work and have GitHub automatically upload (deploy?) the new files to the bintray sites or would I need to search for an alternative?

Could you try to chmod +x gradew before you run the script?  My guess is the execute bit is not set on that file in the repo.

So by that you mean changing the gradle.yml to this?

name: Java CI

on:
  release:
    branches:
    - master


jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Grant rights
      run: chmod +x build.gradle
    - name: Build with Gradle
      env:
        bintrayUser: ${{ secrets.bintrayUsername }}
        bintrayApiKey: ${{ secrets.bintrayApiKey }}
      run: ./gradlew bintrayUpload

No, it sounds like the gradlew script in your repository is not marked as executable.

If you’re on a Unix platform, run:

chmod 0755 gradlew && git add gradlew

If you’re on Windows, run:

git update-index --chmod=+x gradlew
1 Like

I’m now a little bit confused…

I did what you said and it seemed to have partially worked.

I say partially because it both uploaded files (Even tho I’m not sure if it’s all and if they are uncorrupted/completed and all) to bintray (See first image) but also did throw an error (see second image).

Image 1:

Image 2:

From the look of it you’re trying to push/tag a version that already exists?

The line saying “Could not create version 2.3.6” seems to indicate that version is conflicting. I’m not familiar with bintray nor gradle, but could it be that you already have a version 2.3.6 uploaded and it only accepts one upload per version?

It does indeed only accept one release per version.

However, I never released a version 2.3.6 before so this shouldn’t be the problem… I’ll update the version and look again.

Update: Nope. It used a separate version and it didn’t work. Same error like before.

Found the issue.

GitHub Actions triggered 3 times when I published a new release, causing the first that finished to upload the files (therefore creating the release on bintray) and the other two to fail because it’s already uploaded.

Adding the “types: [published]” check to the trigger solved this issue and the CI could finish without errors.