Use env.AWS_ROLE_ARN for publishing
This commit is contained in:
parent
1ecf0558a0
commit
235f0c9b28
1 changed files with 40 additions and 3 deletions
43
build.gradle
43
build.gradle
|
@ -1,4 +1,6 @@
|
||||||
import groovy.io.FileType
|
import groovy.io.FileType
|
||||||
|
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider
|
||||||
|
import com.amazonaws.services.s3.AmazonS3Client
|
||||||
|
|
||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
@ -10,6 +12,19 @@ task wrapper(type: Wrapper) {
|
||||||
gradleVersion = '4.0'
|
gradleVersion = '4.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url "https://libraries.minecraft.net"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.amazonaws:aws-java-sdk:1.11.33'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url "https://libraries.minecraft.net"
|
url "https://libraries.minecraft.net"
|
||||||
|
@ -79,6 +94,18 @@ task report {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def publishDir = file("$buildDir/repo")
|
||||||
|
|
||||||
|
|
||||||
|
def uploadFile(s3, bucket, path, filename) {
|
||||||
|
println "Uploading $filename to $bucket as $path"
|
||||||
|
s3.putObject(bucket, path, filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
clean.doLast {
|
||||||
|
delete publishDir
|
||||||
|
}
|
||||||
|
|
||||||
if (version.endsWith("SNAPSHOT")) {
|
if (version.endsWith("SNAPSHOT")) {
|
||||||
publishing.repositories {
|
publishing.repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
@ -86,9 +113,19 @@ if (version.endsWith("SNAPSHOT")) {
|
||||||
} else {
|
} else {
|
||||||
publishing.repositories {
|
publishing.repositories {
|
||||||
maven {
|
maven {
|
||||||
url "s3://minecraft-libraries/"
|
url "$buildDir/repo"
|
||||||
authentication {
|
}
|
||||||
awsIm(AwsImAuthentication)
|
}
|
||||||
|
|
||||||
|
publish.doLast {
|
||||||
|
def AWSRoleARN = (System.getenv("AWS_ROLE_ARN") != null && System.getenv("AWS_ROLE_ARN") != "" ? System.getenv("AWS_ROLE_ARN") : null)
|
||||||
|
if (AWSRoleARN == null) throw new GradleException("AWS Role has not been configured, use the `AWS_ROLE_ARN` environment variable")
|
||||||
|
def auth = new STSAssumeRoleSessionCredentialsProvider.Builder(AWSRoleARN, "JavaBrigadierPublish").build()
|
||||||
|
def s3 = new AmazonS3Client(auth)
|
||||||
|
publishDir.eachFileRecurse {
|
||||||
|
if (!it.name.contains(".xml") && it.isFile()) {
|
||||||
|
def relPath = publishDir.toPath().relativize(it.toPath()).toFile().toString().replaceAll('\\\\', '/')
|
||||||
|
uploadFile(s3, "minecraft-libraries", relPath, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue