From a27993a1c435ab52452324e93ee3d3901341615d Mon Sep 17 00:00:00 2001 From: stewartbryson Date: Fri, 16 Sep 2022 15:48:50 -0400 Subject: [PATCH 1/3] GCS support #31. --- plugin/build.gradle | 3 ++- plugin/gradle.properties | 3 ++- .../io/github/stewartbryson/JavaTest.groovy | 26 ++++++++++--------- .../stewartbryson/SnowflakePlugin.groovy | 24 ++++++++++++----- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/plugin/build.gradle b/plugin/build.gradle index 7020b66..424057c 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -46,7 +46,8 @@ testing { shouldRunAfter(test) systemProperties project.properties.findAll { it.key.startsWith "snowflake." } systemProperty 'internalStage', findProperty('internalStage') - systemProperty 'externalStage', findProperty('externalStage') + systemProperty 's3Stage', findProperty('s3Stage') + systemProperty 'gcsStage', findProperty('gcsStage') failFast true testLogging.showStandardStreams true } diff --git a/plugin/gradle.properties b/plugin/gradle.properties index 2026e58..d0cd085 100644 --- a/plugin/gradle.properties +++ b/plugin/gradle.properties @@ -1,2 +1,3 @@ internalStage=upload -externalStage=maven_snapshot +s3Stage=maven_snapshot +gcsStage=maven_snapshot_gcs \ No newline at end of file diff --git a/plugin/src/functionalTest/groovy/io/github/stewartbryson/JavaTest.groovy b/plugin/src/functionalTest/groovy/io/github/stewartbryson/JavaTest.groovy index 949d9d6..d4aa172 100644 --- a/plugin/src/functionalTest/groovy/io/github/stewartbryson/JavaTest.groovy +++ b/plugin/src/functionalTest/groovy/io/github/stewartbryson/JavaTest.groovy @@ -31,12 +31,14 @@ class JavaTest extends Specification { String account = System.getProperty("snowflake.account"), user = System.getProperty("snowflake.user"), password = System.getProperty("snowflake.password"), - publishUrl = System.getProperty("snowflake.publishUrl"), + s3PublishUrl = System.getProperty("snowflake.s3PublishUrl"), + gcsPublishUrl = System.getProperty("snowflake.gcsPublishUrl"), role = System.getProperty("snowflake.role"), database = System.getProperty("snowflake.database"), schema = System.getProperty("snowflake.schema"), internalStage = System.getProperty("internalStage"), - externalStage = System.getProperty("externalStage") + s3Stage = System.getProperty("s3Stage"), + gcsStage = System.getProperty("gcsStage") def setupSpec() { settingsFile = new File(projectDir, 'settings.gradle') @@ -131,34 +133,34 @@ class JavaTest extends Specification { !result.tasks.collect { it.outcome }.contains('FAILURE') } - def "tasks with publishUrl"() { + def "shadowJar"() { given: - taskName = 'tasks' + taskName = 'shadowJar' when: - result = executeSingleTask(taskName, ["-Psnowflake.stage=$externalStage".toString(), "-Psnowflake.publishUrl=$publishUrl".toString(), '-Si']) + result = executeSingleTask(taskName, ['-Si']) then: !result.tasks.collect { it.outcome }.contains('FAILURE') } - def "shadowJar"() { + def "snowflakePublish with S3 publishUrl option"() { given: - taskName = 'shadowJar' + taskName = 'snowflakePublish' when: - result = executeSingleTask(taskName, ['-Si']) + result = executeSingleTask(taskName, ["--stage", s3Stage, "-Psnowflake.publishUrl=$s3PublishUrl".toString(), '-Si']) then: !result.tasks.collect { it.outcome }.contains('FAILURE') } - def "snowflakePublish with publishUrl option"() { + def "snowflakePublish with GCS publishUrl option"() { given: taskName = 'snowflakePublish' when: - result = executeSingleTask(taskName, ["-Psnowflake.publishUrl=${publishUrl}".toString(), "-Psnowflake.stage=$externalStage".toString(), '-Si']) + result = executeSingleTask(taskName, ["--stage", gcsStage, "-Psnowflake.publishUrl=$gcsPublishUrl".toString(), '-Si']) then: !result.tasks.collect { it.outcome }.contains('FAILURE') @@ -169,7 +171,7 @@ class JavaTest extends Specification { taskName = 'snowflakePublish' when: - result = executeSingleTask(taskName, ["-Psnowflake.stage=$internalStage".toString(), '-Si']) + result = executeSingleTask(taskName, ["--stage", internalStage, '-Si']) then: !result.tasks.collect { it.outcome }.contains('FAILURE') @@ -180,7 +182,7 @@ class JavaTest extends Specification { taskName = 'snowflakePublish' when: - result = executeSingleTask(taskName, ['--jar', 'build/libs/unit-test-0.1.0-all.jar', '-Psnowflake.stage=upload', '-Si']) + result = executeSingleTask(taskName, ['--jar', 'build/libs/unit-test-0.1.0-all.jar', '--stage', 'upload', '-Si']) then: !result.tasks.collect { it.outcome }.contains('FAILURE') diff --git a/plugin/src/main/groovy/io/github/stewartbryson/SnowflakePlugin.groovy b/plugin/src/main/groovy/io/github/stewartbryson/SnowflakePlugin.groovy index 675bf69..549baed 100644 --- a/plugin/src/main/groovy/io/github/stewartbryson/SnowflakePlugin.groovy +++ b/plugin/src/main/groovy/io/github/stewartbryson/SnowflakePlugin.groovy @@ -13,7 +13,7 @@ class SnowflakePlugin implements Plugin { private static String PLUGIN = 'snowflake' /** - * Apply the gradle-snowflake plugin to a Gradle project. Also applies the 'com.github.johnrengelman.shadow' and 'java-library' plugins. Supporting the 'scala' plugin instead is on the roadmap. + * Apply the snowflake plugin to a Gradle project. Also applies the 'com.github.johnrengelman.shadow' plugin. Supporting the 'scala' plugin as well is on the roadmap. */ void apply(Project project) { project.extensions.create(PLUGIN, SnowflakeExtension) @@ -51,12 +51,22 @@ class SnowflakePlugin implements Plugin { } } // create repository - project.publishing.repositories { - maven { - name extension.stage - url extension.publishUrl - authentication { - awsIm(AwsImAuthentication) + // check and see if we are AWS or GCS + if (extension.publishUrl ==~ /(?i)(s3:\/\/)(.+)/) { + project.publishing.repositories { + maven { + name extension.stage + url extension.publishUrl + authentication { + awsIm(AwsImAuthentication) + } + } + } + } else { + project.publishing.repositories { + maven { + name extension.stage + url extension.publishUrl } } } From fb25bd8bdfd3ba11863998fb8936372278284b37 Mon Sep 17 00:00:00 2001 From: stewartbryson Date: Fri, 16 Sep 2022 16:02:18 -0400 Subject: [PATCH 2/3] Added GCP auth step. --- .github/workflows/gradle-pr.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/gradle-pr.yml b/.github/workflows/gradle-pr.yml index 0a73479..71b98dd 100644 --- a/.github/workflows/gradle-pr.yml +++ b/.github/workflows/gradle-pr.yml @@ -15,6 +15,12 @@ jobs: env: GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}} + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' + - name: Gradle build and test uses: gradle/gradle-build-action@v2 with: From cd32411e32ae5bd21ffddcb0081d3099b5fa6a8e Mon Sep 17 00:00:00 2001 From: stewartbryson Date: Fri, 16 Sep 2022 16:09:36 -0400 Subject: [PATCH 3/3] Added GCP auth step. --- .github/workflows/gradle-publish.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index 0a72f58..e97c60f 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -21,6 +21,12 @@ jobs: env: GRADLE_PROPERTIES: ${{secrets.GRADLE_PROPERTIES}} + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' + with: + credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' + - name: Gradle release uses: gradle/gradle-build-action@v2 with: