diff --git a/README.md b/README.md index 9458a83..be1def7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v2.3.4 - name: Deploy schemas to BigQuery uses: Atom-Learning/bigquery-upload-action - env: + with: gcp_project: 'gcp-us-project' dataset_id: 'dataset-id' table_id: 'table-id' diff --git a/conftest.py b/conftest.py index 6932831..e0a6766 100644 --- a/conftest.py +++ b/conftest.py @@ -3,24 +3,24 @@ @pytest.fixture def dataset_id(monkeypatch): - return monkeypatch.setenv("dataset_id", "foo_dataset_id") + return monkeypatch.setenv("INPUT_DATASET_ID", "foo_dataset_id") @pytest.fixture def gcp_project(monkeypatch): - return monkeypatch.setenv("gcp_project", "foo_gcp_project") + return monkeypatch.setenv("INPUT_GCP_PROJECT", "foo_gcp_project") @pytest.fixture def table_id(monkeypatch): - return monkeypatch.setenv("table_id", "foo_table_id") + return monkeypatch.setenv("INPUT_TABLE_ID", "foo_table_id") @pytest.fixture def bq_rows_as_json_path(monkeypatch): - return monkeypatch.setenv("bq_rows_as_json_path", "foo.json") + return monkeypatch.setenv("INPUT_BQ_ROWS_AS_JSON_PATH", "foo.json") @pytest.fixture def credentials(monkeypatch): - return monkeypatch.setenv("credentials", "{'secret': 'value'}") + return monkeypatch.setenv("INPUT_CREDENTIALS", "{'secret': 'value'}") diff --git a/plugin_scripts/config.py b/plugin_scripts/config.py index b3ea25e..bedd20c 100644 --- a/plugin_scripts/config.py +++ b/plugin_scripts/config.py @@ -11,10 +11,6 @@ def nullthrows(arg: Optional[T]) -> T: class Config(NamedTuple): - """ - Names of the arguments are env var names read from - """ - gcp_project: str dataset_id: str table_id: str @@ -23,18 +19,20 @@ class Config(NamedTuple): def _validate_env_variables() -> None: - for env_var in Config._fields: + for param in Config._fields: + # GH actions prefixes the arguments passed to `with` with `INPUT_` and puts upper case. + env_var = "INPUT_" + param.upper() if not os.environ.get(env_var): - raise Exception(f"Missing `{env_var}` config") + raise Exception(f"Missing `{param}` config") def read_config() -> Config: _validate_env_variables() - gcp_project = os.environ.get("gcp_project") - dataset_id = os.environ.get("dataset_id") - table_id = os.environ.get("table_id") - bq_rows_as_json_path = os.environ.get("bq_rows_as_json_path") - credentials_as_json = os.environ.get("credentials") + gcp_project = os.environ.get("INPUT_GCP_PROJECT") + dataset_id = os.environ.get("INPUT_DATASET_ID") + table_id = os.environ.get("INPUT_TABLE_ID") + bq_rows_as_json_path = os.environ.get("INPUT_BQ_ROWS_AS_JSON_PATH") + credentials_as_json = os.environ.get("INPUT_CREDENTIALS") credentials = json.loads(nullthrows(credentials_as_json)) return Config( diff --git a/plugin_scripts/requirements.lock b/plugin_scripts/requirements.lock index 7a3427f..3e99221 100644 --- a/plugin_scripts/requirements.lock +++ b/plugin_scripts/requirements.lock @@ -9,7 +9,7 @@ google-cloud-core==2.3.1 google-crc32c==1.3.0 google-resumable-media==2.3.3 googleapis-common-protos==1.56.4 -grpcio==1.54.2 +grpcio==1.56.0 grpcio-status==1.47.0 idna==3.3 packaging==21.3 diff --git a/tests/test_config.py b/tests/test_config.py index 4c14266..f938609 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,6 +4,7 @@ # Fixtures imported automatically from conftest.py file + def test__validate_env_variables_missing_dataset_id( table_id, gcp_project, credentials, bq_rows_as_json_path ):