Skip to content

Commit

Permalink
ci: showcase native check (#1833)
Browse files Browse the repository at this point in the history
* ci: showcase native check

* fix: add explicit java version

* fix: adjust syntax

* fix: add resource-config entry for ITGdch

* fix: copy file to temp folder so it can be accessed by path

* chore: formatting

* fix: prevent shutdown warnings with client.awaitTermination

* ci: fix build file location for downstream test

* chore: use static imports for Truth assertions
  • Loading branch information
burkedavison authored Jul 10, 2023
1 parent b1d3fe0 commit a3e91b0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ jobs:
--batch-mode \
--no-transfer-progress
showcase-native:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.2'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: mvn -version
- run: native-image --version
- name: Install sdk-platform-java
run: mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
- name: Install showcase server
run: |
sudo mkdir -p /usr/src/showcase
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/googleapis/gapic-showcase/releases/download/v${SHOWCASE_VERSION}/gapic-showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz --output /usr/src/showcase/showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz
cd /usr/src/showcase/
tar -xf showcase-*
./gapic-showcase run &
cd -
- name: Build native image
working-directory: showcase
run: mvn test -Pnative,-showcase -ntp -B

showcase-clirr:
if: ${{ github.base_ref != '' }} # Only execute on pull_request trigger event
runs-on: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions .kokoro/presubmit/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# All builds use the trampoline script to run in docker.
build_file: "gapic-generator-java/.kokoro/trampoline.sh"
build_file: "sdk-platform-java/.kokoro/trampoline.sh"

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/gapic-generator-java/.kokoro/presubmit/downstream-build.sh"
value: "github/sdk-platform-java/.kokoro/presubmit/downstream-build.sh"
}

# TODO: remove this after we've migrated all tests and scripts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.showcase.v1beta1.it;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThrows;
Expand All @@ -32,15 +34,17 @@
import com.google.showcase.v1beta1.EchoClient;
import com.google.showcase.v1beta1.EchoSettings;
import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory;
import com.google.showcase.v1beta1.stub.EchoStub;
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
import com.google.showcase.v1beta1.stub.EchoStubSettings;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -53,10 +57,11 @@
*/
public class ITGdch {

private static final String TEST_GDCH_CREDENTIAL_FILE = "/test_gdch_credential.json";
private static final String CA_CERT_RESOURCE_PATH = "/fake_cert.pem";
private static final String CA_CERT_FILENAME = "fake_cert.pem";
private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME;
private static final String CA_CERT_JSON_KEY = "ca_cert_path";
private static final String TEMP_CREDENTIAL_JSON_FILENAME = "temp_gdch_credential.json";
private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json";
private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME;
private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2";
private static final String SID_NAME = "service-identity-name";

Expand All @@ -67,7 +72,6 @@ public class ITGdch {
private EchoStubSettings stubSettings;
private Credentials initialCredentials;
private ClientContext context;
private EchoStub stub;
private InterceptingMockTokenServerTransportFactory transportFactory;
private String projectId;
private URI tokenUri;
Expand All @@ -76,37 +80,42 @@ public class ITGdch {
public void setup() throws IOException, URISyntaxException {
transportFactory = new InterceptingMockTokenServerTransportFactory();
prepareCredentials();
tempFolder.create();
settings =
EchoSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials))
.build();
}

@After
public void tearDown() {
public void tearDown() throws InterruptedException {
if (client != null) {
client.close();
client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
}
}

private void prepareCredentials() throws IOException, URISyntaxException {
// compute absolute path of the CA certificate
Path caCertPath = Paths.get(getClass().getResource(CA_CERT_RESOURCE_PATH).toURI());
private void prepareCredentials() throws IOException {
// Copy file so it can be referenced by Path even in native-image builds
File caCertFile = tempFolder.newFile(CA_CERT_FILENAME);
try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) {
assertThat(inputStream).isNotNull();
Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue();

// open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate
// obtained from above)
JsonFactory factory = new GsonFactory();
GenericJson converted =
factory.fromInputStream(
getClass().getResourceAsStream(TEST_GDCH_CREDENTIAL_FILE), GenericJson.class);
getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class);

// modify and save to a temporary folder
converted.set(CA_CERT_JSON_KEY, caCertPath.toAbsolutePath().toString());
converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString());
projectId = converted.get("project").toString();
tokenUri = URI.create(converted.get("token_uri").toString());

File tempGdchCredentialFile = tempFolder.newFile(TEMP_CREDENTIAL_JSON_FILENAME);
File tempGdchCredentialFile = tempFolder.newFile(GDCH_CREDENTIAL_FILENAME);
try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) {
String preparedJson = converted.toPrettyString();
fileWriter.write(preparedJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"resources":[{"pattern": ".*.json"}]
"resources": [
{ "pattern": ".*.json" },
{ "pattern": ".*.pem" }
]
}

0 comments on commit a3e91b0

Please sign in to comment.