Skip to content
Closed
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
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ jobs:
inputs:
targetType: 'filePath'
filePath: scripts/ci/test_index_ref_doc.sh
env:
ADO_PULL_REQUEST_LATEST_COMMIT: HEAD
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)

- job: CheckInit
displayName: "Check Init Files"
Expand Down
40 changes: 37 additions & 3 deletions scripts/ci/index_ref_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@

from __future__ import print_function

import logging
import os
import sys
import tempfile
import traceback
import unittest
import shutil
from subprocess import check_call, CalledProcessError
import shlex
from subprocess import check_call, check_output, CalledProcessError
from pkg_resources import parse_version, get_distribution

from six import with_metaclass

from util import get_index_data, get_whl_from_url, get_repo_root
from util import get_index_data, get_whl_from_url, get_repo_root, SRC_PATH

logger = logging.getLogger(__name__)

REF_GEN_SCRIPT = os.path.join(get_repo_root(), 'scripts', 'refdoc', 'generate.py')

Expand All @@ -30,6 +33,31 @@
sys.exit(1)

ALL_TESTS = []
MODIFIED_EXTS = []

for src_d in os.listdir(SRC_PATH):
src_d_full = os.path.join(SRC_PATH, src_d)
if not os.path.isdir(src_d_full):
continue
pkg_name = next((d for d in os.listdir(src_d_full) if d.startswith('azext_')), None)

cmd_tpl = 'git --no-pager diff --name-only origin/{commit_start} {commit_end} -- {code_dir}'
ado_branch_last_commit = os.environ.get('ADO_PULL_REQUEST_LATEST_COMMIT')
ado_target_branch = os.environ.get('ADO_PULL_REQUEST_TARGET_BRANCH')
if ado_branch_last_commit and ado_target_branch:
if ado_branch_last_commit == '$(System.PullRequest.SourceCommitId)':
# default value if ADO_PULL_REQUEST_LATEST_COMMIT not set in ADO
continue
elif ado_target_branch == '$(System.PullRequest.TargetBranch)':
# default value if ADO_PULL_REQUEST_TARGET_BRANCH not set in ADO
continue
else:
cmd = cmd_tpl.format(commit_start=ado_target_branch, commit_end=ado_branch_last_commit, code_dir=src_d_full)
if not check_output(shlex.split(cmd)):
continue

if pkg_name:
MODIFIED_EXTS.append(src_d)

CLI_VERSION = get_distribution('azure-cli').version

Expand All @@ -44,7 +72,13 @@

candidates_sorted = sorted(filtered_exts, key=lambda c: parse_version(c['metadata']['version']), reverse=True)
chosen = candidates_sorted[0]
ALL_TESTS.append((extension_name, chosen['downloadUrl'], chosen['filename']))
if extension_name in MODIFIED_EXTS:
ALL_TESTS.append((extension_name, chosen['downloadUrl'], chosen['filename']))

logger.warning(f'ado_branch_last_commit: {ado_branch_last_commit}, '
f'ado_target_branch: {ado_target_branch}, '
f'MODIFIED_EXTS: {MODIFIED_EXTS}, '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the extension is not in the repo, updating index.json will not add it in MODIFIED_EXTS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should mark this test as continueOnError, all extensions are independent of each other, we should not let an issue with one extension block other extensions.

f'ALL_TESTS: {ALL_TESTS}')


class TestIndexRefDocsMeta(type):
Expand Down