apply plugin: 'maven-publish' // Apply this plugin at the top of your library build.gradle
apply plugin: "io.freefair.git-version"

def githubProperties = new Properties()
//githubProperties.load(new FileInputStream(rootProject.file("github.properties"))) //Set env variable GPR_USER & GPR_API_KEY if not adding a properties file


def getArtificatId = { ->
 return System.getenv("MAVEN_ARTIFACT_ID")
}

def getArtifactName = { ->
 return System.getenv("MAVEN_ARTIFACT_NAME")
}

def getArtifactVersion = { ->
 return System.getenv("MAVEN_ARTIFACT_VERSION")
}

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "io.freefair.gradle:git-plugin:6.2.0"
  }
}


publishing {
 publications {
   bar(MavenPublication) {
      groupId 'io.anyproto' // Replace with group ID
      artifactId getArtificatId()
      artifact getArtifactName()
      version getArtifactVersion()
    }
 }

repositories {
        maven {
               name = "GitHubPackages"
        /** Configure path of your package repository on Github
         ** Replace GITHUB_USERID with your/organisation Github userID
         ** and REPOSITORY with the repository name on GitHub
        */
 url = uri("https://maven.pkg.github.com/anyproto/anytype-heart")
credentials {
        /** Create github.properties in root project folder file with
         ** gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN
         ** Set env variable GPR_USER & GPR_API_KEY if not adding a properties file**/

         username = githubProperties['gpr.usr'] ?: System.getenv("GITHUB_USER")
         password = githubProperties['gpr.key'] ?: System.getenv("GITHUB_TOKEN")
      }
    }
  }
}
