From ecd4e410738b2d62c9c2cfabe992ae1108c69bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20P=C3=A9rez?= Date: Fri, 17 Oct 2025 02:30:10 +0200 Subject: [PATCH] ci updated --- .github/workflows/build.yml | 19 ++------------- .github/workflows/ci.yml | 6 +++++ .github/workflows/emulator-test.yml | 37 +++++++++++++++++++++++++++++ .github/workflows/pr.yml | 29 +--------------------- .github/workflows/release.yml | 12 ++++------ scripts/seed_emulator.py | 17 +++++++++++++ 6 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/emulator-test.yml create mode 100644 scripts/seed_emulator.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd842b7..0afae8e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,25 +6,10 @@ on: tags: [ "v*" ] pull_request: + jobs: ci: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install - run: | - python -m pip install -U pip - python -m pip install . - python -m pip install pytest - - name: Test - run: | - pytest -q + uses: ./.github/workflows/emulator-test.yml publish: needs: ci diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..92d0d6b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,6 @@ +name: CI + +on: [push, pull_request] +jobs: + test: + uses: ./.github/workflows/emulator-test.yml diff --git a/.github/workflows/emulator-test.yml b/.github/workflows/emulator-test.yml new file mode 100644 index 0000000..e8603bd --- /dev/null +++ b/.github/workflows/emulator-test.yml @@ -0,0 +1,37 @@ +name: emulator-test + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - uses: google-github-actions/setup-gcloud@v1 + with: + project_id: dummy-project + install_components: 'beta' + - name: Start Datastore Emulator + run: | + gcloud beta emulators datastore start --host-port=localhost:8010 --project=dummy-project & + sleep 10 + - name: Set environment variables + run: | + echo "DATASTORE_EMULATOR_HOST=localhost:8010" >> $GITHUB_ENV + echo "DATASTORE_PROJECT_ID=dummy-project" >> $GITHUB_ENV + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + pip install pytest + - name: Seed Emulator + run: python scripts/seed_emulator.py + - name: Run tests + run: pytest -q diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8bd86ea..905074a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -5,31 +5,4 @@ on: jobs: test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - - name: Install - run: | - python -m pip install -U pip - python -m pip install . - python -m pip install pytest ruff black build pip-audit - - name: Lint - run: | - ruff check . - black --check . - - name: Test - run: pytest -q - - name: Build and verify - run: | - python -m build - twine check dist/* || true - - name: Security audit - run: | - pip-audit -r requirements.txt || true \ No newline at end of file + uses: ./.github/workflows/emulator-test.yml \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4208745..c5415d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,8 +5,12 @@ on: branches: [ main ] jobs: + test: + uses: ./.github/workflows/emulator-test.yml + release: runs-on: ubuntu-latest + needs: test permissions: contents: write id-token: write @@ -22,13 +26,7 @@ jobs: run: | python -m pip install -U pip python -m pip install . - python -m pip install pytest ruff black build python-semantic-release pip-audit - - name: Lint - run: | - ruff check . - black --check . - - name: Test - run: pytest -q + python -m pip install build python-semantic-release pip-audit - name: Build and verify run: | python -m build diff --git a/scripts/seed_emulator.py b/scripts/seed_emulator.py new file mode 100644 index 0000000..3966de2 --- /dev/null +++ b/scripts/seed_emulator.py @@ -0,0 +1,17 @@ +from google.cloud import datastore + +client = datastore.Client(project="dummy-project") + +# Seed default namespace +key = client.key("TestKind", "test-id") +entity = datastore.Entity(key=key) +entity.update({"foo": "bar"}) +client.put(entity) + +# Seed custom namespace +key_ns = client.key("TestKind", "test-id-ns", namespace="test-ns") +entity_ns = datastore.Entity(key=key_ns) +entity_ns.update({"foo": "baz"}) +client.put(entity_ns) + +print("Seeded emulator with test entities in default and 'test-ns' namespaces.")