diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 2e6a659..f5a5d42 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -109,3 +109,29 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | gh release upload '${{ github.ref_name }}' dist/** --repo '${{ github.repository }}' + + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/${{ matrix.package }} + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} \ No newline at end of file diff --git a/packages/happtiq_commons_google_cloud/src/happtiq_commons_google_cloud/gcs_api_service.py b/packages/happtiq_commons_google_cloud/src/happtiq_commons_google_cloud/gcs_api_service.py index 33f66c9..c7403b7 100644 --- a/packages/happtiq_commons_google_cloud/src/happtiq_commons_google_cloud/gcs_api_service.py +++ b/packages/happtiq_commons_google_cloud/src/happtiq_commons_google_cloud/gcs_api_service.py @@ -37,3 +37,14 @@ def upload_file(self, file_path: bytes, bucket_name: str, destination: str, con blob.upload_from_filename(file_path, content_type=content_type, timeout=self.timeout) self.logger.info(f"File uploaded to {destination}.") return f"gs://{bucket_name}/{destination}" + + def list_files_with_prefix(self, bucket_name: str, prefix: str): + self.logger.info(f"Listing files in bucket {bucket_name} with prefix {prefix}") + bucket = self.client.bucket(bucket_name) + blobs = bucket.list_blobs(prefix=prefix) + + file_list = [blob.name for blob in blobs] + self.logger.debug(f"Files in bucket {bucket_name} with prefix {prefix}: {file_list}") + self.logger.info(f"found {len(file_list)} files in bucket {bucket_name} with prefix {prefix}") + + return file_list diff --git a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py index a5b5e9e..370a147 100644 --- a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py +++ b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py @@ -75,3 +75,25 @@ def test_upload_file_gzipped(gcs_api_service, monkeypatch): gcs_api_service.client.bucket().blob.assert_called_once_with(destination) gcs_api_service.client.bucket().blob(destination).upload_from_filename.assert_called_once_with(file_path, content_type=content_type, timeout=30) gcs_api_service.client.bucket().blob(destination).content_encoding = "gzip" + +def test_list_files_with_prefix(gcs_api_service, monkeypatch): + mock_client = MagicMock() + mock_bucket = MagicMock() + mock_blob1 = MagicMock() + mock_blob1.name = "file1.txt" + mock_blob2 = MagicMock() + mock_blob2.name = "file2.txt" + mock_blobs = [mock_blob1,mock_blob2] + + mock_client.bucket.return_value = mock_bucket + mock_bucket.list_blobs.return_value = mock_blobs + monkeypatch.setattr(gcs_api_service, "client", mock_client) + + bucket_name = "test-bucket" + prefix = "test-prefix/" + + result = gcs_api_service.list_files_with_prefix(bucket_name, prefix) + + assert result == ["file1.txt", "file2.txt"] + mock_client.bucket.assert_called_once_with(bucket_name) + mock_bucket.list_blobs.assert_called_once_with(prefix=prefix)