OpenAstronomy / azure-pipelines-templates

An opinionated set of Azure Pipelines templates for Python projects using pyproject.toml (PEP517) and tox
https://openastronomy-azure-pipelines.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
11 stars 20 forks source link

Use fork clone URL if fork #77

Closed ConorMacBride closed 2 years ago

ConorMacBride commented 2 years ago

When using the check_skip.yml template on a PR from a fork it can't find the commit hash in the self repository Azure checks out. This PR is to use the GitHub API to get the clone URL of the fork and clone that instead of the target repository. Testing at https://github.com/sunpy/sunpy/pull/5700.

ConorMacBride commented 2 years ago

Note: the first checkout task deletes and recreates the sources directory so the bash task which writes to the sources directory (to clone the fork) must be after all checkout tasks in the job have run.

ConorMacBride commented 2 years ago

@Cadair Can you review and merge? This is working at https://github.com/sunpy/sunpy/pull/5700.

Cadair commented 2 years ago

from a fork it can't find the commit hash in the self repository Azure checks out

This is unfortunate, but I am like 90% sure it's possible to do that without resorting to the github API and checking out the fork itself.

I think the following git incantation should fetch all the commits for a PR as referenced through the upstream repo and not needing to reference the fork:

$ git fetch origin refs/pull/<num>/head

I tried this locally and it fetched all the commits on your sunpy/sunpy#5700 PR. If you ran this command before you went looking for the commit hash I think it would solve the issue without the extra API call?

ConorMacBride commented 2 years ago

That works much better! I've added the git fetch to the script which'll run if a PR_NUMBER env variable is set. It's working here: https://dev.azure.com/sunpy/sunpy/_build/results?buildId=21560&view=logs&j=b4877b35-8b5c-5460-4bbd-df532ed4d3a3&t=ebcf7dce-a25f-503f-8595-fdd814047e50

Cadair commented 2 years ago

Thanks a lot once again!