Skip to content

Commit 4bebeed

Browse files
Harmonize /test and /publish commands on github + Fix MySQL tests in CI (#2531)
* Harmonize /test and /publish commands on github * Make normalization build on clean system without PyICU see https://getdbt.slack.com/archives/C50NEBJGG/p1615803416053800?thread_ts=1615511262.026400&cid=C50NEBJGG * Follow example from testcontainers/testcontainers-java#2689 to modify MySQL container as root * Add docs on new syntax for /test
1 parent ecf73c9 commit 4bebeed

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

.github/workflows/test-command.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
integration_test:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Search for valid integration name format
16+
- name: Search for valid connector name format
1717
id: regex
1818
uses: AsasInnab/regex-action@v1
1919
with:
20-
regex_pattern: '^[a-zA-Z0-9-_]+$'
20+
regex_pattern: '^((connectors|bases)/)?[a-zA-Z0-9-_]+$'
2121
regex_flags: 'i' # required to be set for this plugin
2222
search_string: ${{ github.event.inputs.connector }}
2323
- name: Validate input workflow format

airbyte-integrations/bases/base-normalization/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
author_email="[email protected]",
3232
url="https://github.com/airbytehq/airbyte",
3333
packages=setuptools.find_packages(),
34-
install_requires=["airbyte-protocol", "dbt==0.18.1", "pyyaml"],
34+
install_requires=["airbyte-protocol", "dbt==0.18.2rc1", "pyyaml"],
3535
package_data={"": ["*.yml"]},
3636
setup_requires=["pytest-runner"],
3737
entry_points={

airbyte-integrations/connectors/source-mysql/src/test/java/io/airbyte/integrations/source/mysql/MySqlJdbcStandardTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.google.common.collect.ImmutableMap;
2929
import io.airbyte.commons.json.Jsons;
30-
import io.airbyte.commons.resources.MoreResources;
3130
import io.airbyte.db.Database;
3231
import io.airbyte.db.Databases;
3332
import io.airbyte.integrations.source.jdbc.AbstractJdbcSource;
3433
import io.airbyte.integrations.source.jdbc.test.JdbcSourceStandardTest;
34+
import java.sql.Connection;
35+
import java.sql.DriverManager;
36+
import java.sql.SQLException;
3537
import org.apache.commons.lang3.RandomStringUtils;
3638
import org.jooq.SQLDialect;
3739
import org.junit.jupiter.api.AfterAll;
@@ -50,13 +52,15 @@ class MySqlJdbcStandardTest extends JdbcSourceStandardTest {
5052
private Database database;
5153

5254
@BeforeAll
53-
static void init() {
54-
// test containers withInitScript only accepts scripts that are mounted as resources.
55-
MoreResources.writeResource("init.sql",
56-
"CREATE USER '" + TEST_USER + "'@'%' IDENTIFIED BY '" + TEST_PASSWORD + "';\n"
57-
+ "GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%';\n");
58-
container = new MySQLContainer<>("mysql:8.0").withInitScript("init.sql").withUsername("root").withPassword("");
55+
static void init() throws SQLException {
56+
container = new MySQLContainer<>("mysql:8.0")
57+
.withUsername(TEST_USER)
58+
.withPassword(TEST_PASSWORD)
59+
.withEnv("MYSQL_ROOT_HOST", "%")
60+
.withEnv("MYSQL_ROOT_PASSWORD", TEST_PASSWORD);
5961
container.start();
62+
Connection connection = DriverManager.getConnection(container.getJdbcUrl(), "root", TEST_PASSWORD);
63+
connection.createStatement().execute("GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%';\n");
6064
}
6165

6266
@BeforeEach
@@ -76,6 +80,7 @@ public void setup() throws Exception {
7680
config.get("host").asText(),
7781
config.get("port").asText()),
7882
MySqlSource.DRIVER_CLASS,
83+
7984
SQLDialect.MYSQL);
8085

8186
database.query(ctx -> {

airbyte-integrations/connectors/source-mysql/src/test/java/io/airbyte/integrations/source/mysql/MySqlStressTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.google.common.collect.ImmutableMap;
2929
import io.airbyte.commons.json.Jsons;
30-
import io.airbyte.commons.resources.MoreResources;
3130
import io.airbyte.db.Database;
3231
import io.airbyte.db.Databases;
3332
import io.airbyte.integrations.source.jdbc.AbstractJdbcSource;
3433
import io.airbyte.integrations.source.jdbc.test.JdbcStressTest;
34+
import java.sql.Connection;
35+
import java.sql.DriverManager;
36+
import java.sql.SQLException;
3537
import java.util.Optional;
3638
import org.apache.commons.lang3.RandomStringUtils;
3739
import org.jooq.SQLDialect;
@@ -53,13 +55,15 @@ class MySqlStressTest extends JdbcStressTest {
5355
private Database database;
5456

5557
@BeforeAll
56-
static void init() {
57-
// test containers withInitScript only accepts scripts that are mounted as resources.
58-
MoreResources.writeResource("init.sql",
59-
"CREATE USER '" + TEST_USER + "'@'%' IDENTIFIED BY '" + TEST_PASSWORD + "';\n"
60-
+ "GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%';\n");
61-
container = new MySQLContainer<>("mysql:8.0").withInitScript("init.sql").withUsername("root").withPassword("");
58+
static void init() throws SQLException {
59+
container = new MySQLContainer<>("mysql:8.0")
60+
.withUsername(TEST_USER)
61+
.withPassword(TEST_PASSWORD)
62+
.withEnv("MYSQL_ROOT_HOST", "%")
63+
.withEnv("MYSQL_ROOT_PASSWORD", TEST_PASSWORD);
6264
container.start();
65+
Connection connection = DriverManager.getConnection(container.getJdbcUrl(), "root", TEST_PASSWORD);
66+
connection.createStatement().execute("GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%';\n");
6367
}
6468

6569
@BeforeEach

docs/contributing-to-airbyte/building-new-connector/testing-connectors.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,31 @@ Here are some example commands:
7070

7171
1. `/test connector=all` - Runs integration tests for all connectors in a single GitHub workflow. Some of our integration tests interact with rate-limited resources, so please use this judiciously.
7272
2. `/test connector=source-sendgrid` - Runs integration tests for a single connector on the latest PR commit.
73-
3. `/test connector=source-sendgrid ref=master` - Runs integration tests for a single connector on a different branch.
74-
4. `/test connector=source-sendgrid ref=d5c53102` - Runs integration tests for a single connector on a specific commit.
73+
3. `/test connector=connectors/source-sendgrid` - Runs integration tests for a single connector on the latest PR commit.
74+
4. `/test connector=source-sendgrid ref=master` - Runs integration tests for a single connector on a different branch.
75+
5. `/test connector=source-sendgrid ref=d5c53102` - Runs integration tests for a single connector on a specific commit.
7576

7677
A command dispatcher GitHub workflow will launch on comment submission. This dispatcher will add an :eyes: reaction to the comment when it starts processing. If there is an error dispatching your request, an error will be appended to your comment. If it launches the test run successfully, a :rocket: reaction will appear on your comment.
7778

7879
Once the integration test workflow launches, it will append a link to the workflow at the end of the comment. A success or failure response will also be added upon workflow completion.
7980

8081
Integration tests can also be manually requested by clicking "[Run workflow](https://github.com/airbytehq/airbyte/actions?query=workflow%3Aintegration-test)" and specifying the connector and GitHub ref.
8182

82-
### 3. Automatically Run From `master`
83+
### 3. Requesting GitHub PR publishing Docker Images
84+
85+
In order for users to reference the new versions of a connector, it needs to be published and available in the [dockerhub](https://hub.docker.com/r/airbyte/source-sendgrid/tags?page=1&ordering=last_updated) with the latest tag updated.
86+
87+
As seen previously, GitHub workflow can be triggered by comment submission.
88+
Publishing docker images to the dockerhub repository can also be submitted likewise:
89+
90+
Note that integration tests can be triggered with a slightly different syntax for arguments.
91+
This second set is required to distinguish between `connectors` and `bases` folders.
92+
Thus, it is also easier to switch between the `/test` and `/publish` commands:
93+
94+
- `/test connector=connectors/source-sendgrid` - Runs integration tests for a single connector on the latest PR commit.
95+
- `/publish connector=connectors/source-sendgrid` - Publish the docker image if it doesn't exist for a single connector on the latest PR commit.
96+
97+
### 4. Automatically Run From `master`
8398

8499
Commits to `master` attempt to launch integration tests. Two workflows launch for each commit: one is a launcher for integration tests, the other is the core build \(the same as the default for PR and branch builds\).
85100

tools/bin/ci_integration_test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
. tools/lib/lib.sh
6+
57
# runs integration tests for an integration name
68

79
connector="$1"
@@ -11,8 +13,14 @@ if [[ "$connector" == "all" ]] ; then
1113
echo "Running: ./gradlew --no-daemon --scan integrationTest"
1214
./gradlew --no-daemon --scan integrationTest
1315
else
14-
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector$" || echo "")
15-
integrationTestCommand=":airbyte-integrations:connectors:$connector:integrationTest"
16+
if [[ "$connector" == *"connectors"* ]] || [[ "$connector" == *"bases"* ]]; then
17+
connector_name=$(echo $connector | cut -d / -f 2)
18+
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector_name$" || echo "")
19+
integrationTestCommand="$(_to_gradle_path "airbyte-integrations/$connector" integrationTest)"
20+
else
21+
selected_integration_test=$(echo "$all_integration_tests" | grep "^$connector$" || echo "")
22+
integrationTestCommand=":airbyte-integrations:connectors:$connector:integrationTest"
23+
fi
1624
if [ -n "$selected_integration_test" ] ; then
1725
echo "Running: ./gradlew --no-daemon --scan $integrationTestCommand"
1826
./gradlew --no-daemon --scan "$integrationTestCommand"

0 commit comments

Comments
 (0)