Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in repo structure cache script and improve pipeline #7733

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions eng/pipelines/openapitools/repo-structure-cache-job.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
parameters:
- name: DB_NAME
type: string
default: "openapi-portal"

- name: COLLECTION_NAME
type: string
default: "repoStructureCache"

- name: REPOS_URL_LIST
type: string
default: "https://github.com/test-repo-billy/azure-rest-api-specs/tree/main,https://github.com/test-repo-billy/azure-rest-api-specs-pr/tree/RPSaaSDev,https://github.com/test-repo-billy/azure-rest-api-specs-pr/tree/main,https://github.com/test-repo-billy/azure-rest-api-specs/tree/RPSaaSDev"

trigger:
- main
trigger: none
pr: none

pool:
name: azsdk-pool-mms-ubuntu-2204-general
vmImage: ubuntu-22.04

steps:

- script: |
pip install -r 'eng/scripts/OpenAPI Hub/requirements.txt'
pip install -r 'eng/scripts/openapitools/python/cacherepostructure/requirements.txt'
pip list
python 'eng/scripts/openapitools/python/cacherepostructure/sync-repo-structure-cache.py' --db_name ${{ parameters.DB_NAME }} --collection_name ${{ parameters.COLLECTION_NAME }} --repos_url_list ${{ parameters.REPOS_URL_LIST }} --repo_clone_path $(System.DefaultWorkingDirectory)
displayName: Run Script
displayName: Install dependencies

- script: |
python 'eng/scripts/openapitools/python/cacherepostructure/sync-repo-structure-cache.py' --db_name "openapiPortal" --collection_name "repoStructureCache" --repos_url_list "https://github.com/Azure/azure-rest-api-specs/tree/main,https://github.com/Azure/azure-rest-api-specs-pr/tree/RPSaaSDev,https://github.com/Azure/azure-rest-api-specs-pr/tree/main,https://github.com/Azure/azure-rest-api-specs-pr/tree/RPSaaSMaster" --repo_clone_path $(System.DefaultWorkingDirectory)
displayName: Update PROD cache
env:
MONGO_CONNECTION_STRING: $(Open-API-MongoDB-Connection-String)
GITHUB_TOKEN: $(azuresdk-github-pat)

- script: |
python 'eng/scripts/openapitools/python/cacherepostructure/sync-repo-structure-cache.py' --db_name "openapiPortal" --collection_name "repoStructureCache" --repos_url_list "https://github.com/Azure/azure-rest-api-specs/tree/main,https://github.com/Azure/azure-rest-api-specs-pr/tree/RPSaaSDev,https://github.com/Azure/azure-rest-api-specs-pr/tree/main,https://github.com/Azure/azure-rest-api-specs-pr/tree/RPSaaSMaster" --repo_clone_path $(System.DefaultWorkingDirectory)
displayName: Update PPE cache
env:
MONGO_CONNECTION_STRING: $(Open-API-MongoDB-Connection-String-PPE)
GITHUB_TOKEN: $(azuresdk-github-pat)
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def update_mongo_collection(
print(f"Using database '{DB_NAME}' and collection '{COLLECTION_NAME}'")

try:
existing_document: bool = collection.count_documents({"key": new_document["key"]}) == 0
existing_document_count: bool = collection.count_documents({"key": new_document["key"]})
except Exception as e:
print(f"Error while checking for existing document: {e}")
raise e

print(f"Existing document: {existing_document}")
if existing_document:
print(f"Existing documents: {existing_document_count}")
if existing_document_count > 0:
print(f"Document for '{new_document['key']}' exists, replacing...")
try:
collection.replace_one({"key": new_document['key']}, new_document)
Expand Down
Loading