Skip to content

Commit dc253cf

Browse files
authored
chore: enable e2e tests with GitHub Actions (#977)
1 parent ecda805 commit dc253cf

File tree

6 files changed

+163
-28
lines changed

6 files changed

+163
-28
lines changed

.kokoro/tests/run_tests.sh renamed to .github/scripts/run_tests.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@
1616
# `-e` enables the script to automatically fail when a command fails
1717
set -e
1818

19-
# Kokoro setup
20-
if [ -n "$KOKORO_GFILE_DIR" ]; then
21-
# Move into project directory
22-
cd github/cloud-sql-jdbc-socket-factory
23-
# source secrets
24-
source "${KOKORO_GFILE_DIR}/TEST_SECRETS.sh"
25-
export GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/testing-service-account.json"
26-
fi
27-
2819
if [[ $OSTYPE == 'darwin'* ]]; then
2920
# Add alias for 127.0.0.2 to be used as a loopback address
3021
# https://superuser.com/questions/458875/how-do-you-get-loopback-addresses-other-than-127-0-0-1-to-work-on-os-x
31-
ifconfig lo0 alias 127.0.0.2 up
22+
sudo ifconfig lo0 alias 127.0.0.2 up
3223
fi
3324

3425
echo -e "******************** Running tests... ********************\n"

.github/workflows/coverage.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,32 @@
1313
# limitations under the License.
1414

1515
name: Code Coverage
16-
on: [pull_request]
16+
on:
17+
pull_request:
18+
pull_request_target:
19+
types: [labeled]
1720

1821
jobs:
1922
build:
2023
name: Coverage check
2124
runs-on: ubuntu-latest
2225
steps:
26+
- name: Remove PR Label
27+
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
28+
uses: actions/github-script@v6
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
script: |
32+
try {
33+
await github.rest.issues.removeLabel({
34+
name: 'tests: run',
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
issue_number: context.payload.pull_request.number
38+
});
39+
} catch (e) {
40+
console.log('Failed to remove label. Another job may have already removed it!');
41+
}
2342
- name: Setup Java
2443
uses: actions/setup-java@v3
2544
with:

.github/workflows/lint.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: lint
16+
on:
17+
pull_request:
18+
pull_request_target:
19+
types: [labeled]
20+
21+
jobs:
22+
lint:
23+
if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}"
24+
name: checkstyle
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Remove PR Label
28+
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
29+
uses: actions/github-script@v6
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
script: |
33+
try {
34+
await github.rest.issues.removeLabel({
35+
name: 'tests: run',
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
issue_number: context.payload.pull_request.number
39+
});
40+
} catch (e) {
41+
console.log('Failed to remove label. Another job may have already removed it!');
42+
}
43+
- name: Checkout code
44+
uses: actions/checkout@v3
45+
- name: Set up JDK 17
46+
uses: actions/setup-java@v3
47+
with:
48+
distribution: 'zulu'
49+
java-version: '17'
50+
- name: lint
51+
run: mvn -B compile -Plint

.github/workflows/tests.yml

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,101 @@
1313
# limitations under the License.
1414

1515
name: tests
16-
on: [pull_request]
16+
on:
17+
pull_request:
18+
push:
19+
branches:
20+
- main
21+
pull_request_target:
22+
types: [labeled]
23+
schedule:
24+
- cron: '0 2 * * *'
1725

1826
jobs:
19-
build:
20-
name: lint
21-
runs-on: ubuntu-latest
27+
unit-e2e:
28+
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label)
29+
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}"
30+
name: unit + e2e
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
matrix:
34+
os: [macos-latest, windows-latest, ubuntu-latest]
35+
java-version: ["8", "11", "17"]
36+
fail-fast: false
37+
permissions:
38+
contents: 'read'
39+
id-token: 'write'
2240
steps:
41+
- name: Remove PR label
42+
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
43+
uses: actions/github-script@v6
44+
with:
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
46+
script: |
47+
try {
48+
await github.rest.issues.removeLabel({
49+
name: 'tests: run',
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
issue_number: context.payload.pull_request.number
53+
});
54+
} catch (e) {
55+
console.log('Failed to remove label. Another job may have already removed it!');
56+
}
2357
- name: Checkout code
24-
uses: actions/checkout@v3
25-
- name: Set up JDK 17
58+
uses: 'actions/checkout@v3'
59+
with:
60+
ref: ${{ github.event.pull_request.head.sha }}
61+
repository: ${{ github.event.pull_request.head.repo.full_name }}
62+
63+
- name: Set up JDK
2664
uses: actions/setup-java@v3
2765
with:
2866
distribution: 'zulu'
29-
java-version: '17'
30-
- name: lint
31-
run: mvn -B compile -Plint
67+
java-version: ${{matrix.java-version}}
68+
69+
- id: 'auth'
70+
name: 'Authenticate to Google Cloud'
71+
uses: 'google-github-actions/[email protected]'
72+
with:
73+
workload_identity_provider: ${{ secrets.PROVIDER_NAME }}
74+
service_account: ${{ secrets.SERVICE_ACCOUNT }}
75+
access_token_lifetime: 600s
76+
77+
- id: 'secrets'
78+
name: Get secrets
79+
uses: 'google-github-actions/[email protected]'
80+
with:
81+
secrets: |-
82+
MYSQL_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_CONNECTION_NAME
83+
MYSQL_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER
84+
MYSQL_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS
85+
MYSQL_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB
86+
POSTGRES_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME
87+
POSTGRES_IAM_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_IAM_CONNECTION_NAME
88+
POSTGRES_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER
89+
POSTGRES_IAM_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_JAVA
90+
POSTGRES_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_PASS
91+
POSTGRES_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_DB
92+
SQLSERVER_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_CONNECTION_NAME
93+
SQLSERVER_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_USER
94+
SQLSERVER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_PASS
95+
SQLSERVER_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_DB
96+
- name: Run tests
97+
env:
98+
MYSQL_CONNECTION_NAME: '${{ steps.secrets.outputs.MYSQL_CONNECTION_NAME }}'
99+
MYSQL_USER: '${{ steps.secrets.outputs.MYSQL_USER }}'
100+
MYSQL_PASS: '${{ steps.secrets.outputs.MYSQL_PASS }}'
101+
MYSQL_DB: '${{ steps.secrets.outputs.MYSQL_DB }}'
102+
POSTGRES_CONNECTION_NAME: '${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}'
103+
POSTGRES_IAM_CONNECTION_NAME: '${{ steps.secrets.outputs.POSTGRES_IAM_CONNECTION_NAME }}'
104+
POSTGRES_USER: '${{ steps.secrets.outputs.POSTGRES_USER }}'
105+
POSTGRES_IAM_USER: '${{ steps.secrets.outputs.POSTGRES_IAM_USER }}'
106+
POSTGRES_PASS: '${{ steps.secrets.outputs.POSTGRES_PASS }}'
107+
POSTGRES_DB: '${{ steps.secrets.outputs.POSTGRES_DB }}'
108+
SQLSERVER_CONNECTION_NAME: '${{ steps.secrets.outputs.SQLSERVER_CONNECTION_NAME }}'
109+
SQLSERVER_USER: '${{ steps.secrets.outputs.SQLSERVER_USER }}'
110+
SQLSERVER_PASS: '${{ steps.secrets.outputs.SQLSERVER_PASS }}'
111+
SQLSERVER_DB: '${{ steps.secrets.outputs.SQLSERVER_DB }}'
112+
run: ./.github/scripts/run_tests.sh
113+
shell: bash

.kokoro/tests/run_tests_java11.bat

Lines changed: 0 additions & 4 deletions
This file was deleted.

.kokoro/tests/run_tests_java17.bat

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)