From 7a4d90df91735106cfe3977b431a88204654c479 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:15:37 -0400 Subject: [PATCH 1/7] Revamp build validation --- .github/workflows/validate.yml | 36 +++++++++++++++++++++-------- readme.md | 42 ++-------------------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a83bc22..cdac67e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,34 +1,52 @@ name: Validate Python projects on: + push: pull_request: paths: - '**.py' branches: - main jobs: + index: + name: Generate matrix of project directories + runs-on: ubuntu-latest + outputs: + projects: ${{ steps.set_output.outputs.matches }} + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: List directories + run: find -name '*.py' -type 'f' -printf '%h\n' | uniq + - name: Set output + id: set_output + run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]')" >> $GITHUB_OUTPUT validate: name: Validate Python project + needs: index runs-on: ubuntu-latest container: python:3.7 strategy: matrix: - project-directory: - - ./001-quickstart - - ./002-quickstart-async - - ./003-how-to - - ./004-create-db - - ./005-create-container + project-directory: ${{ fromJson(needs.index.outputs.projects) }} defaults: run: working-directory: ${{ matrix.project-directory }} steps: - name: Checkout source code - uses: actions/checkout@v2 - - name: Check Python version + uses: actions/checkout@v4 + - name: Output Python version run: python --version - name: Install packages run: pip install black flake8 - name: Lint with flake8 run: flake8 --count --verbose *.py - name: Check format with black - run: black --check --verbose --line-length 79 *.py \ No newline at end of file + run: black --check --verbose --line-length 79 *.py + summarize: + name: Summarize all validation jobs + if: ${{ always() }} + runs-on: ubuntu-latest + needs: validate + steps: + - run: exit 1 + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} \ No newline at end of file diff --git a/readme.md b/readme.md index 78030ed..634ad0c 100644 --- a/readme.md +++ b/readme.md @@ -2,15 +2,9 @@ ## Getting started -This repo has a prebuilt development environment making it easy to get started. +This repo has a [devcontainer](https://containers.dev) environment making it easy to get started. -### Pull the repo - -Open the repo in a [development container](https://containers.dev) using either Visual Studio Code or GitHub Codespaces. - -- **Visual Studio Code**: Clone this repo to your local machine and open the folder using the [Dev containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). - -- **GitHub Codespaces**: Open this repo in the browser with a [GitHub codespace](https://docs.github.com/en/codespaces/overview). +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/cosmos-db-nosql-python-samples?quickstart=1) ### Run the app @@ -30,26 +24,6 @@ pip install azure-cosmos python 001-quickstart/app.py ``` -The application should output a single JSON object. - -```json -{ - "id": "70b63682-b93a-4c77-aad2-65501347265f", - "categoryId": "61dba35b-4f02-45c5-b648-c6badc0cbd79", - "categoryName": "gear-surf-surfboards", - "name": "Yamba Surfboard", - "quantity": 12, - "sale": false, - "_rid": "yzN6AIfJxe0BAAAAAAAAAA==", - "_self": "dbs/yzN6AA==/colls/yzN6AIfJxe0=/docs/yzN6AIfJxe0BAAAAAAAAAA==/", - "_etag": "\"2a00ccd4-0000-0200-0000-63650e420000\"", - "_attachments": "attachments/", - "_ts": 16457527130 -} -``` - -> **💡 TIP**: The fields assigned by Azure Cosmos DB (ex. `id`) will vary from this sample output. - ### Validate any changes you make If you change the code, run the linter and code formatter. @@ -71,15 +45,3 @@ If you use a self-signed certificate to connect your Cosmos DB instance (Cosmos- ```bash export REQUESTS_CA_BUNDLE='/etc/ssl/certs/emulatorcert.pem' ``` - -## Samples - -This project contains multiple samples used in [Azure Cosmos DB for NoSQL](https://learn.microsoft.com/azure/cosmos-db/nosql/) documentation. - -| Sample | Documentation | -| --- | --- | -| [001-quickstart](001-quickstart/app.py) | [Quickstart: Azure Cosmos DB for NoSQL client library for Python](https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-python?tabs=azure-portal%2Clinux%2Csync) | -| [002-quickstart-async](002-quickstart-async/app.py) | [Quickstart: Azure Cosmos DB for NoSQL client library for Python](https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-python?tabs=azure-portal%2Clinux%2Casync) | -| [[003-how-to](003-how-to/app.py)] | [Get started with Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-get-started) | -| [[004-create-db](003-how-to/app.py)] | [Create a database in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-create-database) | -| [[005-create-container](003-how-to/app.py)] | [Create a container in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-create-container) | From 64ed4631b893ce3a1e682fc79d1666d7a8b62524 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:17:25 -0400 Subject: [PATCH 2/7] Revamp PR template --- .github/PULL_REQUEST_TEMPLATE.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 73bb8e8..7f8cc78 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,9 +3,11 @@ ```bash -pip install flake8 -flake8 --verbose /app.py +pip install flake8 black +``` + +```bash +flake8 --verbose *.py -pip install black -black --verbose /app.py +black --verbose --line-length 79 *.py ``` From 57b6736977002a0bf07d708b1d46317822c9cded Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:23:36 -0400 Subject: [PATCH 3/7] Update validation job --- .github/workflows/validate.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index cdac67e..8cbd5dd 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout source code uses: actions/checkout@v4 - name: List directories - run: find -name '*.py' -type 'f' -printf '%h\n' | uniq + run: find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]' - name: Set output id: set_output run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]')" >> $GITHUB_OUTPUT @@ -44,9 +44,13 @@ jobs: run: black --check --verbose --line-length 79 *.py summarize: name: Summarize all validation jobs - if: ${{ always() }} - runs-on: ubuntu-latest needs: validate + runs-on: ubuntu-latest + if: always() steps: - - run: exit 1 - if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} \ No newline at end of file + - name: All validation passed + if: ${{ !(contains(needs.*.result, 'failure')) }} + run: exit 0 + - name: Some validation failed + if: ${{ contains(needs.*.result, 'failure') }} + run: exit 1 From 8de2c8e8d18678092249c3f6c20e818699c914f8 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:27:38 -0400 Subject: [PATCH 4/7] Try new jq --- .github/workflows/validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 8cbd5dd..5d48af0 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout source code uses: actions/checkout@v4 - name: List directories - run: find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]' + run: find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[inputs|select(length > 0)]' - name: Set output id: set_output run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]')" >> $GITHUB_OUTPUT From d2fd158a572ddf18f4efa2b5a0fd50d248fe251b Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:30:55 -0400 Subject: [PATCH 5/7] Validation script --- .github/workflows/validate.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5d48af0..b5de24d 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -46,11 +46,13 @@ jobs: name: Summarize all validation jobs needs: validate runs-on: ubuntu-latest - if: always() + if: ${{ always() }} steps: - - name: All validation passed - if: ${{ !(contains(needs.*.result, 'failure')) }} - run: exit 0 - - name: Some validation failed - if: ${{ contains(needs.*.result, 'failure') }} + - name: Evaluate status of jobs + if: >- + ${{ + contains(needs.*.result, 'failure') + || contains(needs.*.result, 'cancelled') + || contains(needs.*.result, 'skipped') + }} run: exit 1 From e9b23fea4860d0d3320d230a5d3505af1fb6106d Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:31:30 -0400 Subject: [PATCH 6/7] Validation script --- .github/workflows/validate.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index b5de24d..fe841d6 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,10 +16,10 @@ jobs: - name: Checkout source code uses: actions/checkout@v4 - name: List directories - run: find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[inputs|select(length > 0)]' + run: find -name '*.py' -type 'f' -printf '%h\n' | uniq - name: Set output id: set_output - run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --raw-input --compact-output --sort-keys '[., input?]')" >> $GITHUB_OUTPUT + run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --null-input --raw-input --compact-output --sort-keys '[inputs|select(length > 0)]')" >> $GITHUB_OUTPUT validate: name: Validate Python project needs: index From 89fd8836e38bd0169e7527d682751b9980c2ffc8 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Thu, 14 Sep 2023 14:32:42 -0400 Subject: [PATCH 7/7] Updated validation script --- .github/workflows/validate.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index fe841d6..5f16f9a 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -44,7 +44,9 @@ jobs: run: black --check --verbose --line-length 79 *.py summarize: name: Summarize all validation jobs - needs: validate + needs: + - index + - validate runs-on: ubuntu-latest if: ${{ always() }} steps: