diff --git a/.github/workflows/publish_garf_google_ads.yaml b/.github/workflows/publish_garf_google_ads.yaml new file mode 100644 index 0000000..6eea4c8 --- /dev/null +++ b/.github/workflows/publish_garf_google_ads.yaml @@ -0,0 +1,47 @@ +name: Publish to PyPI - garf-google-ads + +on: + push: + branches: + - main + paths: + - 'libs/community/google/ads/**' + - '!libs/community/google/ads/*.md' + +jobs: + publish: + runs-on: ubuntu-latest + environment: + name: pypi + permissions: + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install uv + uses: astral-sh/setup-uv@v4 + + - name: Get versions and check for change + id: version_check + run: | + PREV_VERSION=$(git show HEAD~1:libs/community/google/ads/garf_google_ads/__init__.py | grep -oE "__version__ = '([0-9]+\.[0-9]+\.[0-9]+)'" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') + CURRENT_VERSION=$(grep -oE "__version__ = '([0-9]+\.[0-9]+\.[0-9]+)'" libs/community/google/ads/garf_google_ads/__init__.py | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') + + if [[ "$CURRENT_VERSION" != "$PREV_VERSION" ]]; then + echo "Version change detected: $PREV_VERSION -> $CURRENT_VERSION" + echo "should_publish=true" >> $GITHUB_OUTPUT + echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + else + echo "No version change. Skipping publish." + echo "should_publish=false" >> $GITHUB_OUTPUT + fi + + - name: Build the package + if: steps.version_check.outputs.should_publish == 'true' + run: uv build libs/community/google/ads/ + + - name: Publish to PyPI + if: steps.version_check.outputs.should_publish == 'true' + run: uv publish libs/community/google/ads/dist/* diff --git a/.github/workflows/test_garf_google_ads.yaml b/.github/workflows/test_garf_google_ads.yaml new file mode 100644 index 0000000..77bbb47 --- /dev/null +++ b/.github/workflows/test_garf_google_ads.yaml @@ -0,0 +1,34 @@ +name: Run tests for garf-google-ads + +on: + workflow_dispatch: + pull_request: + branches: [main] + paths: + - 'libs/community/google/ads/garf_google_ads/**' + +env: + UV_SYSTEM_PYTHON: 1 + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: "3.13" + - name: Setup uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.5.4" + enable-cache: true + - name: Install dependencies + run: | + uv pip install pytest + - name: Test ${{ matrix.library }} + run: | + cd libs/community/google/ads/ + uv pip install -e . + pytest tests/unit diff --git a/libs/community/google/ads/garf_google_ads/__init__.py b/libs/community/google/ads/garf_google_ads/__init__.py index 840d881..67ed2b9 100644 --- a/libs/community/google/ads/garf_google_ads/__init__.py +++ b/libs/community/google/ads/garf_google_ads/__init__.py @@ -22,4 +22,4 @@ 'GoogleAdsApiReportFetcher', ] -__version__ = '0.0.1' +__version__ = '0.0.2' diff --git a/libs/community/google/ads/garf_google_ads/report_fetcher.py b/libs/community/google/ads/garf_google_ads/report_fetcher.py index 4a3f510..d483618 100644 --- a/libs/community/google/ads/garf_google_ads/report_fetcher.py +++ b/libs/community/google/ads/garf_google_ads/report_fetcher.py @@ -52,6 +52,18 @@ def fetch( customer_ids_query: str | None = None, **kwargs: str, ) -> garf_core.GarfReport: + """Fetches data from Google Ads API. + + Args: + query_specifiction: Query to execute. + args: Optional parameters to fine-tune the query. + account: Account(s) to get data from. + expand_mcc: Whether to perform account expansion (MCC to Account). + custom_ids_query: Query to reduce number of accounts based a condition. + + Returns: + Fetched report for provided accounts. + """ if isinstance(account, str): account = account.split(',') if not args: @@ -102,14 +114,11 @@ def expand_mcc( """Performs Manager account(s) expansion to child accounts. Args: - customer_ids: - Manager account(s) to be expanded. - customer_ids_query: - Garf query to limit the expansion only to accounts - satisfying the condition. + customer_ids: Manager account(s) to be expanded. + customer_ids_query: GAQL query used to reduce the number of customer_ids. Returns: - All child accounts under provided customer_ids. + All child accounts under provided customer_ids. """ return self._get_customer_ids( seed_customer_ids=customer_ids, customer_ids_query=customer_ids_query @@ -127,7 +136,7 @@ def _get_customer_ids( customer_ids_query: GAQL query used to reduce the number of customer_ids. Returns: - All customer_ids from MCC satisfying the condition. + All customer_ids from MCC satisfying the condition. """ query = """ SELECT customer_client.id FROM customer_client diff --git a/libs/community/google/ads/pyproject.toml b/libs/community/google/ads/pyproject.toml index c1399a0..7e58ace 100644 --- a/libs/community/google/ads/pyproject.toml +++ b/libs/community/google/ads/pyproject.toml @@ -8,6 +8,7 @@ dependencies = [ "garf-core", "garf-io", "google-ads", + "tenacity", ] authors = [ {name = "Andrei Markin", email = "amarkin@google.com"}, @@ -36,3 +37,7 @@ test = [ "pytest-cov", "python-dotenv", ] + +[[tool.uv.index]] +url = "https://pypi.org/simple" +default = true