diff --git a/.github/workflows/auto-release.yaml b/.github/workflows/auto-release.yaml new file mode 100644 index 00000000..d26427e4 --- /dev/null +++ b/.github/workflows/auto-release.yaml @@ -0,0 +1,69 @@ +on: + pull_request: +name: auto-release +jobs: + approve: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3.0.0 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + debug: true + script: | + // only approve PRs from release-please[bot] + if (context.payload.pull_request.user.login !== "release-please[bot]") { + return; + } + + // only approve PRs like "chore: release " + if ( !context.payload.pull_request.title.startsWith("chore: release") ) { + return; + } + + // trigger auto-release when + // 1) it is a SNAPSHOT release (auto-generated post regular release) + // 2) there are dependency updates only + // 3) there are no open dependency update PRs in this repo (to avoid multiple releases) + if ( + context.payload.pull_request.body.includes("Fix") || + context.payload.pull_request.body.includes("Build") || + context.payload.pull_request.body.includes("Documentation") || + context.payload.pull_request.body.includes("BREAKING CHANGES") || + context.payload.pull_request.body.includes("Features") + ) { + console.log( "Not auto-releasing since it is not a dependency-update-only release." ); + return; + } + + const promise = github.pulls.list.endpoint({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open' + }); + const open_pulls = await github.paginate(promise) + + if ( open_pulls.length > 1 && !context.payload.pull_request.title.includes("SNAPSHOT") ) { + for ( const pull of open_pulls ) { + if ( pull.title.startsWith("deps: update dependency") ) { + console.log( "Not auto-releasing yet since there are dependency update PRs open in this repo." ); + return; + } + } + } + + // approve release PR + await github.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Rubber stamped release!', + pull_number: context.payload.pull_request.number, + event: 'APPROVE' + }); + + // attach kokoro:force-run and automerge labels + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ['kokoro:force-run', 'automerge'] + }); \ No newline at end of file diff --git a/.github/workflows/samples.yaml b/.github/workflows/samples.yaml new file mode 100644 index 00000000..a1d50073 --- /dev/null +++ b/.github/workflows/samples.yaml @@ -0,0 +1,14 @@ +on: + pull_request: +name: samples +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Run checkstyle + run: mvn -P lint --quiet --batch-mode checkstyle:check + working-directory: samples/snippets diff --git a/.kokoro/release/stage.cfg b/.kokoro/release/stage.cfg index d4d9ca18..868f59ab 100644 --- a/.kokoro/release/stage.cfg +++ b/.kokoro/release/stage.cfg @@ -13,32 +13,7 @@ action { } } -# Fetch the token needed for reporting release status to GitHub -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "yoshi-automation-github-key" - } - } -} - -# Fetch magictoken to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "releasetool-magictoken" - } - } -} - -# Fetch api key to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "magic-github-proxy-api-key" - } - } +env_vars: { + key: "SECRET_MANAGER_KEYS" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 81655553..18ade497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [0.1.2](https://www.github.com/googleapis/java-analytics-admin/compare/v0.1.1...v0.1.2) (2020-09-21) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-shared-dependencies to v0.9.0 ([#34](https://www.github.com/googleapis/java-analytics-admin/issues/34)) ([52df7a7](https://www.github.com/googleapis/java-analytics-admin/commit/52df7a73bb0244e557f714c713d9eb7a700c6a4f)) + ### [0.1.1](https://www.github.com/googleapis/java-analytics-admin/compare/v0.1.0...v0.1.1) (2020-08-11) diff --git a/README.md b/README.md index 27c7ff76..0896661b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you are using Maven, add this to your pom.xml file: com.google.analytics google-analytics-admin - 0.0.0 + 0.1.1 ``` @@ -28,11 +28,11 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.analytics:google-analytics-admin:0.1.1' +compile 'com.google.analytics:google-analytics-admin:0.1.2' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.analytics" % "google-analytics-admin" % "0.1.1" +libraryDependencies += "com.google.analytics" % "google-analytics-admin" % "0.1.2" ``` [//]: # ({x-version-update-end}) @@ -67,6 +67,16 @@ use this Analytics Admin Client Library. +## Samples + +Samples are in the [`samples/`](https://github.com/googleapis/java-analytics-admin/tree/master/samples) directory. The samples' `README.md` +has instructions for running the samples. + +| Sample | Source Code | Try it | +| --------------------------- | --------------------------------- | ------ | +| Quickstart Sample | [source code](https://github.com/googleapis/java-analytics-admin/blob/master/samples/snippets/src/main/java/com/example/analyticsadmin/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-analytics-admin&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/analyticsadmin/QuickstartSample.java) | + + ## Troubleshooting diff --git a/google-analytics-admin-bom/pom.xml b/google-analytics-admin-bom/pom.xml index 4f59291d..3d22057b 100644 --- a/google-analytics-admin-bom/pom.xml +++ b/google-analytics-admin-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.analytics google-analytics-admin-bom - 0.1.1 + 0.1.2 pom com.google.cloud @@ -68,17 +68,17 @@ com.google.analytics google-analytics-admin - 0.1.1 + 0.1.2 com.google.api.grpc proto-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 com.google.api.grpc grpc-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 diff --git a/google-analytics-admin/pom.xml b/google-analytics-admin/pom.xml index 05275359..0d2059e4 100644 --- a/google-analytics-admin/pom.xml +++ b/google-analytics-admin/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.analytics google-analytics-admin - 0.1.1 + 0.1.2 jar Google Analytics Admin https://github.com/googleapis/java-analytics-admin @@ -11,7 +11,7 @@ com.google.analytics google-analytics-admin-parent - 0.1.1 + 0.1.2 google-analytics-admin diff --git a/grpc-google-analytics-admin-v1alpha/pom.xml b/grpc-google-analytics-admin-v1alpha/pom.xml index b6cc9e57..b6c81e92 100644 --- a/grpc-google-analytics-admin-v1alpha/pom.xml +++ b/grpc-google-analytics-admin-v1alpha/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 grpc-google-analytics-admin-v1alpha GRPC library for grpc-google-analytics-admin-v1alpha com.google.analytics google-analytics-admin-parent - 0.1.1 + 0.1.2 diff --git a/pom.xml b/pom.xml index d98efa87..a0dceccc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.analytics google-analytics-admin-parent pom - 0.1.1 + 0.1.2 Google Analytics Admin Parent https://github.com/googleapis/java-analytics-admin @@ -70,23 +70,23 @@ com.google.analytics google-analytics-admin - 0.1.1 + 0.1.2 com.google.api.grpc proto-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 com.google.api.grpc grpc-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 com.google.cloud google-cloud-shared-dependencies - 0.8.6 + 0.9.0 pom import @@ -129,7 +129,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.1.0 + 3.1.1 diff --git a/proto-google-analytics-admin-v1alpha/pom.xml b/proto-google-analytics-admin-v1alpha/pom.xml index 75405ab7..1215cd5d 100644 --- a/proto-google-analytics-admin-v1alpha/pom.xml +++ b/proto-google-analytics-admin-v1alpha/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-analytics-admin-v1alpha - 0.1.1 + 0.1.2 proto-google-analytics-admin-v1alpha PROTO library for proto-google-analytics-admin-v1alpha com.google.analytics google-analytics-admin-parent - 0.1.1 + 0.1.2 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 34399ae3..9a59cc1b 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -14,7 +14,7 @@ com.google.cloud.samples shared-configuration - 1.0.18 + 1.0.12 @@ -29,7 +29,7 @@ com.google.analytics google-analytics-admin - 0.1.0 + 0.1.1 @@ -53,7 +53,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.2.0 + 3.1.0 add-snippets-source diff --git a/samples/pom.xml b/samples/pom.xml index 24edad23..5c579328 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.google.cloud + com.google.analytics google-analytics-admin-samples 0.0.1-SNAPSHOT pom @@ -28,7 +28,6 @@ - install-without-bom snapshot snippets diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 3aab9258..bfb90939 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.google.cloud + com.google.analytics analytics-admin-snapshot jar Google Analytics Admin Snapshot Samples @@ -28,7 +28,7 @@ com.google.analytics google-analytics-admin - 0.1.0 + 0.1.2 diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index ec103b3c..6b6b1344 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.google.cloud + com.google.analytics analytics-admin-snippets jar Google Analytics Admin Snippets @@ -23,26 +23,12 @@ UTF-8 - - - - - - com.google.cloud - libraries-bom - 8.1.0 - pom - import - - - - com.google.analytics google-analytics-admin + 0.1.2 - junit diff --git a/samples/snippets/src/main/java/com/example/analyticsadmin/QuickstartSample.java b/samples/snippets/src/main/java/com/example/analyticsadmin/QuickstartSample.java new file mode 100644 index 00000000..e07f59bd --- /dev/null +++ b/samples/snippets/src/main/java/com/example/analyticsadmin/QuickstartSample.java @@ -0,0 +1,90 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +/* This application demonstrates the usage of the Analytics Admin API using + service account credentials. For more information on service accounts, see + https://cloud.google.com/iam/docs/understanding-service-accounts + + The following document provides instructions on setting service account + credentials for your application: + https://cloud.google.com/docs/authentication/production + + In a nutshell, you need to: + + 1. Create a service account and download the key JSON file. + https://cloud.google.com/docs/authentication/production#creating_a_service_account + + 2. Provide service account credentials using one of the following options: + - set the GOOGLE_APPLICATION_CREDENTIALS environment variable, the API + client will use the value of this variable to find the service account key + JSON file. + + https://cloud.google.com/docs/authentication/production#setting_the_environment_variable + + OR + + - manually pass the path to the service account key JSON file to the API client + by specifying the keyFilename parameter in the constructor. + https://cloud.google.com/docs/authentication/production#passing_the_path_to_the_service_account_key_in_code + + To run this sample using Maven: + cd java-analytics-admin/samples/snippets + mvn exec:java -Dexec.mainClass="com.example.analytics.QuickstartSample" + */ + +// [START analytics_admin_quickstart] + +import com.google.analytics.admin.v1alpha.Account; +import com.google.analytics.admin.v1alpha.AnalyticsAdminServiceClient; +import com.google.analytics.admin.v1alpha.AnalyticsAdminServiceClient.ListAccountsPage; +import com.google.analytics.admin.v1alpha.AnalyticsAdminServiceClient.ListAccountsPagedResponse; +import com.google.analytics.admin.v1alpha.ListAccountsRequest; + +public class QuickstartSample { + + public static void main(String... args) throws Exception { + listAccounts(); + } + + + // This is an example snippet that calls the Google Analytics Admin API and lists all Google + // Analytics accounts available to the authenticated user. + static void listAccounts() throws Exception { + // Instantiates a client using default credentials. + // See https://cloud.google.com/docs/authentication/production for more information + // about managing credentials. + try (AnalyticsAdminServiceClient analyticsAdmin = AnalyticsAdminServiceClient.create()) { + // Calls listAccounts() method of the Google Analytics Admin API and prints + // the response for each account. + ListAccountsPagedResponse response = analyticsAdmin + .listAccounts(ListAccountsRequest.newBuilder().build()); + for (ListAccountsPage page : response.iteratePages()) { + for (Account account : page.iterateAll()) { + System.out.printf("Account name: %s%n", account.getName()); + System.out.printf("Display name: %s%n", account.getDisplayName()); + System.out.printf("Country code: %s%n", account.getCountryCode()); + System.out.printf("Create time: %s%n", account.getCreateTime().getSeconds()); + System.out.printf("Update time: %s%n", account.getUpdateTime().getSeconds()); + System.out.println(); + } + } + } + } +} + +// [END analytics_admin_quickstart] diff --git a/samples/snippets/src/test/java/com/example/analyticsadmin/QuickstartSampleTest.java b/samples/snippets/src/test/java/com/example/analyticsadmin/QuickstartSampleTest.java new file mode 100644 index 00000000..7bc63b03 --- /dev/null +++ b/samples/snippets/src/test/java/com/example/analyticsadmin/QuickstartSampleTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.analytics; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleTest { + + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testQuickstart() throws Exception { + // Act + QuickstartSample.main(); + + // Assert + String got = bout.toString(); + assertThat(got).contains("Account name:"); + } +} \ No newline at end of file diff --git a/synth.metadata b/synth.metadata index 041c3105..a69dfd73 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-analytics-admin.git", - "sha": "dde01446cb6e73c568f1f778a3b03427ad9135ab" + "sha": "c280fb4ec596270e7d7ef2927622c73bee95e9cd" } }, { @@ -19,7 +19,7 @@ "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "f8823dec98277a9516f2fb6fae9f58b3a59a23e1" + "sha": "538a68019eb4a36a0cdfa4021f324dd01b784395" } } ], @@ -42,7 +42,9 @@ ".github/PULL_REQUEST_TEMPLATE.md", ".github/release-please.yml", ".github/trusted-contribution.yml", + ".github/workflows/auto-release.yaml", ".github/workflows/ci.yaml", + ".github/workflows/samples.yaml", ".kokoro/build.bat", ".kokoro/build.sh", ".kokoro/coerce_logs.sh", diff --git a/versions.txt b/versions.txt index 0da9a109..3c2437f3 100644 --- a/versions.txt +++ b/versions.txt @@ -1,6 +1,6 @@ # Format: # module:released-version:current-version -google-analytics-admin:0.1.1:0.1.1 -proto-google-analytics-admin-v1alpha:0.1.1:0.1.1 -grpc-google-analytics-admin-v1alpha:0.1.1:0.1.1 \ No newline at end of file +google-analytics-admin:0.1.2:0.1.2 +proto-google-analytics-admin-v1alpha:0.1.2:0.1.2 +grpc-google-analytics-admin-v1alpha:0.1.2:0.1.2 \ No newline at end of file