Skip to content

[Core] CI step added to check external github url#9831

Open
msarfraz wants to merge 3 commits intoAzure:mainfrom
msarfraz:network-test
Open

[Core] CI step added to check external github url#9831
msarfraz wants to merge 3 commits intoAzure:mainfrom
msarfraz:network-test

Conversation

@msarfraz
Copy link
Copy Markdown
Contributor

Description
This PR removes the dependency on GitHub (raw.githubusercontent.com) VM image aliases, replacing it with Azure Blob Storage (azcliprod.blob.core.windows.net). This change enables Azure CLI to work properly in network isolated environments where GitHub access is blocked.

In addition, new validation added in CI pipeline to flag if any raw.githubusercontent.com URL is used in the code.

Background
In enterprise environments with strict network isolation policies, access to raw.githubusercontent.com is not allowed.

Changes

VM Image Alias Migration

Before:
https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json
After:
https://azcliprod.blob.core.windows.net/cli/vm/aliases_master.json

Before:
https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json
After:
https://azcliprod.blob.core.windows.net/cli/vm/aliases.json

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Copilot AI review requested due to automatic review settings April 29, 2026 03:11
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented Apr 29, 2026

️✔️Azure CLI Extensions Breaking Change Test
️✔️Non Breaking Changes

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @msarfraz,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 29, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown
Contributor

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a CI guardrail to prevent introducing new raw.githubusercontent.com dependencies (problematic in network-isolated environments) by scanning PR diffs for forbidden external GitHub raw URLs and maintaining an exclusions list for known/intentional occurrences.

Changes:

  • Added scripts/ci/validate_external_source_urls.py to scan added diff lines for forbidden raw.githubusercontent.com URLs.
  • Added scripts/ci/external_url_exclusions.json to configure path-based exclusions for the validator.
  • Added a new CheckExternalUrls Azure Pipelines job to run the validator in PR builds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
scripts/ci/validate_external_source_urls.py New diff-based validator that fails CI when forbidden raw GitHub URLs are added.
scripts/ci/external_url_exclusions.json Exclusions configuration consumed by the validator to skip docs/tests/etc.
azure-pipelines.yml New pipeline job to execute the validator during CI.

Comment on lines +16 to +18
"scripts/*"
],
"_justification": "CI and tooling scripts are maintained separately from extension source content and are excluded to avoid self-flagging the validator configuration."
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The exclusion rule "scripts/*" effectively disables validation for all scripts (including CI tooling). That makes it easy for new raw.githubusercontent.com usages to be introduced in scripts without being flagged. Consider narrowing this exclusion to only the specific files that need to self-contain the checker (e.g., the validator script/config), rather than excluding the entire scripts/ tree.

Suggested change
"scripts/*"
],
"_justification": "CI and tooling scripts are maintained separately from extension source content and are excluded to avoid self-flagging the validator configuration."
"scripts/ci/external_url_exclusions.json"
],
"_justification": "The external URL validator configuration is excluded so it can self-contain the allowlist and justification text without self-flagging."

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +104
def _run_diff(src: str, tgt: str, cached: bool = False) -> str:
cmd = ["git", "diff", "--unified=0", "--no-color"]
if cached:
cmd.append("--cached")
else:
cmd.append(f"{tgt}...{src}")

proc = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=False,
)
if proc.returncode != 0:
raise RuntimeError(proc.stderr.strip() or "git diff failed")
return proc.stdout
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

git diff {tgt}...{src} relies on computing a merge-base. In CI with shallow fetches, the merge-base often isn't present and this form can fail (or produce an incomplete diff). Either fetch sufficient history/unshallow so the merge-base is available, or switch to a diff form that doesn't require merge-base (e.g., tgt..src) depending on the intended semantics.

Copilot uses AI. Check for mistakes.
Comment thread azure-pipelines.yml
Comment on lines +153 to +155
- job: CheckExternalUrls
displayName: "Check External Source URLs"
pool:
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

This job runs for non-PR builds as well, and then exits early in the script. To avoid consuming an extra agent/job on every branch build, add a job-level condition similar to other PR-only jobs (e.g. eq(variables['Build.Reason'], 'PullRequest')) instead of relying on an in-script check.

Copilot uses AI. Check for mistakes.
Comment thread azure-pipelines.yml
Comment on lines +166 to +168
# If CI is set to shallow fetch, target branch should be explicitly fetched.
# External URL exclusions are maintained in scripts/ci/external_url_exclusions.json.
git fetch origin --depth=1 $(System.PullRequest.TargetBranch)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The pipeline fetches the target branch with --depth=1, but the validator uses a git diff form that needs merge-base history. With shallow history this can cause the validation step to fail unexpectedly. Consider increasing fetch depth (or unshallow) enough to compute the merge base, or adjust the validator to avoid relying on merge-base diffs.

Suggested change
# If CI is set to shallow fetch, target branch should be explicitly fetched.
# External URL exclusions are maintained in scripts/ci/external_url_exclusions.json.
git fetch origin --depth=1 $(System.PullRequest.TargetBranch)
# If CI is set to shallow fetch, ensure enough history is available
# for validators that may need to compute a merge base.
if [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then
git fetch origin --unshallow
fi
# External URL exclusions are maintained in scripts/ci/external_url_exclusions.json.
git fetch origin "$(System.PullRequest.TargetBranch):refs/remotes/origin/$(System.PullRequest.TargetBranch)"

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +146
parser = argparse.ArgumentParser(description="Check diff for forbidden raw github URL usage.")
parser.add_argument("--src", default="HEAD", help="Source ref/commit for git diff.")
parser.add_argument("--tgt", default="HEAD~1", help="Target ref/commit for git diff.")
parser.add_argument("--cached", action="store_true", help="Check staged changes in git index.")
args = parser.parse_args()

try:
_get_excluded_path_patterns()
diff_text = _run_diff(src=args.src, tgt=args.tgt, cached=args.cached)
except Exception as ex: # pylint: disable=broad-except
if args.cached:
print(f"Unable to evaluate staged diff: {ex}", file=sys.stderr)
else:
print(f"Unable to evaluate diff between '{args.tgt}' and '{args.src}': {ex}", file=sys.stderr)
return 1

violations = _find_violations(diff_text)
if not violations:
print("No forbidden external github URL found in added lines.")
return 0
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

User-facing output and argparse description use inconsistent capitalization ("github" vs "GitHub"). Since this is a CI validation message, it’s worth standardizing to "GitHub" throughout for clarity/professionalism.

Copilot uses AI. Check for mistakes.
Comment thread azure-pipelines.yml
Comment on lines +153 to +154
- job: CheckExternalUrls
displayName: "Check External Source URLs"
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

PR description mentions migrating VM image alias URLs from raw.githubusercontent.com to Azure Blob Storage, but the changes in this PR appear to only add the CI validator + exclusions/pipeline job. Either update the PR description to match the actual scope, or include the alias migration changes here if they’re intended to be part of this PR.

Copilot uses AI. Check for mistakes.
@msarfraz msarfraz requested a review from calvinhzy as a code owner April 30, 2026 01:37
@github-actions
Copy link
Copy Markdown
Contributor

CodeGen Tools Feedback Collection

Thank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants