Skip to content

Conversation

@sima-zhu
Copy link
Contributor

@sima-zhu sima-zhu commented Apr 4, 2022

@sima-zhu sima-zhu requested a review from a team as a code owner April 4, 2022 23:09
@sima-zhu sima-zhu requested review from danieljurek and weshaggard and removed request for a team April 4, 2022 23:11
@check-enforcer-staging
Copy link

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

Copy link
Member

@danieljurek danieljurek left a comment

Choose a reason for hiding this comment

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

  • This pipeline is currently scheduled to run weekly
  • This only generates BranchPrefix for the day from a week ago
  • If the pipeline were modified to run daily this could work (I don't seen any obvious failures in the history of scheduled runs)

I think in this case we'd want to have a script which fetches the names of the branches starting with daily/, determine if a given branch should be deleted, then sends the branch off for deletion using Delete-RemoteBranches.ps1. This would give us multiple attempts at deleting a branch and not couple the deletion process to the pipeline schedule.

@sima-zhu
Copy link
Contributor Author

sima-zhu commented Apr 5, 2022

  • This pipeline is currently scheduled to run weekly
  • This only generates BranchPrefix for the day from a week ago
  • If the pipeline were modified to run daily this could work (I don't seen any obvious failures in the history of scheduled runs)

I think in this case we'd want to have a script which fetches the names of the branches starting with daily/, determine if a given branch should be deleted, then sends the branch off for deletion using Delete-RemoteBranches.ps1. This would give us multiple attempts at deleting a branch and not couple the deletion process to the pipeline schedule.

@danieljurek Since the daily branches are not necessary to be accurate to one week. How do you think we delete the ones in last month?

("daily/" + (Get-Date (Get-Date).AddMonths(-1) -UFormat "%Y-%m"))

The problem for this approach is we probably only have one daily branch at the first day of the month. If this causes us pain, we can add steps to return a range of branches then loop into each one.

@sima-zhu sima-zhu requested a review from danieljurek April 5, 2022 17:15
@sima-zhu sima-zhu self-assigned this Apr 5, 2022
@sima-zhu sima-zhu added the Central-EngSys This issue is owned by the Engineering System team. label Apr 5, 2022
@sima-zhu sima-zhu changed the title Remove daily docs from previous week Remove daily docs branches last month Apr 5, 2022
- azure-sdk-for-net
- azure-sdk-for-python

- name: AzureDocsRepo
Copy link
Member

Choose a reason for hiding this comment

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

Why add another set of parameters? If the only thing different is a branch pattern we should just add that as a property of the repo so we can use the same logic for everything.

Copy link
Member

Choose a reason for hiding this comment

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

@danieljurek
Copy link
Member

danieljurek commented Apr 7, 2022

@sima-zhu -- Date math is a very intricate domain. Libraries are almost always the right way to go. If we're reusing the Delete-RemoteBranches.ps1 script (which we probably should) then we'll need to call it in a loop because a prefix doesn't give us the level of granularity needed:

Get a list of all existing branches that start with daily/:

daily/2022-04-06
daily/2022-04-05
daily/2022-04-04
daily/2022-04-03
daily/2022-04-02
daily/2022-04-01
daily/2022-03-31
daily/2022-03-30
daily/2022-03-29
daily/2022-03-28
daily/2022-03-27
...

Do some parsing:

$parsedDates = $dates `
  | ForEach-Object { ($_ -split '/')[1] } `    # <-- TODO: handle removing the potential '[-ci-(succeeded|failed)]' scenario
  | ForEach-Object { 
    $outpuut = New-Object datetime; 
    $ignore = [datetime]::TryParseExact(
      $_, 
      'yyyy-MM-dd', 
      [System.Globalization.CultureInfo]::InvariantCulture, 
      [System.Globalization.DateTimeStyles]::None, 
      [ref]$a
    ); 
    return $output } 

Compare the dates:

$prefixesToDelete = $parsedDates `
  | Where-Object { ((Get-Date - $_).TotalDays -gt 7 } `        # <-- Date math happens here
  | ForEach-Object { "daily/$($_.ToString('yyyy-MM-dd'))" } 

Delete the branches:

foreach ($prefix in $prefixesToDelete) { 
  $(System.DefaultWorkingDirectory)/eng/common/scripts/Delete-RemoteBranches.ps1
    -RepoOwner "MicrosoftDocs"
    -RepoName ${{ repo }}
    -BranchPrefix $prefix                          # <-- Delete prefix from the list
    -AuthToken $(azuresdk-github-pat)
}

@weshaggard
Copy link
Member

Just for my understanding are we trying to delete all the daily branches that are older than a week old? If so, should we be using the branch name or the date of the last commit into a branch? If we do the later that might be a more general approach for all the branch clean-up.

@benbp
Copy link
Member

benbp commented Apr 13, 2022

Just for my understanding are we trying to delete all the daily branches that are older than a week old? If so, should we be using the branch name or the date of the last commit into a branch? If we do the later that might be a more general approach for all the branch clean-up.

I do worry here if there are scenarios where you cut a new branch but don't rev any commits, resulting in newer branches being deleted when they shouldn't. Also, we would need a pretty explicit branch pattern to make sure we don't accidentally pick up other random branches, and if we're already checking an explicit branch pattern we might as well just encode the entire date in it and delete it via @danieljurek's scripts?

@danieljurek
Copy link
Member

Our current automation for creating daily branches don't create new branches unless the automation is also pushing commits to those branches... If someone were to manually create a branch which met whatever filtration criteria we set then it's possible that such a script would delete the branch out from under them... though they could encounter similar problems if the branch they created had a name that met the criteria that we're explicitly parsing here as well.

When configuring automation based on branch name and most recent commit date, one would want to avoid matching on things like feature/ or other branch names that could really cause havoc.

Also, commit date can, with some work, be modified by the user but I think that's pretty far out of the scope of what we care about.

I think we have other branch cleanup scripts for things like eng/common PRs and one code path to delete them all might be preferable to multiple code paths that do very similar things.

@sima-zhu
Copy link
Contributor Author

@danieljurek @benbp
Thanks for commenting on the PR.
The purpose of the scripts are to delete branches with different names, so regex might solve the issue, but limited our choice. If we have complicated situation, we have no choices but loop the script call in yml files.

I am thinking adding another parameters like branch creation date range, so we can solve the problem without looping on top of the script step.

@sima-zhu sima-zhu changed the title Remove daily docs branches last month Remove daily docs branches Apr 18, 2022
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@sima-zhu sima-zhu requested review from benbp and weshaggard April 25, 2022 21:03
$RepoName = ($Repo -split "/")[1]
$GithubAPIBaseURI = "repos/$RepoOwner/$RepoName"

function HandleGHAPICall ($api, $method="GET") {
Copy link
Contributor Author

@sima-zhu sima-zhu Apr 25, 2022

Choose a reason for hiding this comment

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

Switch to gh, as the github API has no ability to call the commit sha url directly which introduce more complexity to the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use Invoke-RestMethod, but make the script combined with Github API helper method and rest api call. GH is flexible in this case.

Copy link
Member

Choose a reason for hiding this comment

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

If we are switching to using gh commands directly why do we need to use the raw api calls as opposed to the higher level gh commands? This approach seems as though we are just replacing Invoke-RestMethod with gh api and I'm not sure why that is helpful.

@sima-zhu sima-zhu requested a review from weshaggard April 27, 2022 20:09
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@sima-zhu sima-zhu requested a review from weshaggard April 27, 2022 22:51
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

}
catch {
LogError "Get-GithubReferenceCommitDate failed with exception:`n$_"
exit 1
Copy link
Member

Choose a reason for hiding this comment

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

We should watch to ensure this does not happen in any normal cases otherwise we might get to a spot where this clean-up continuously fail.

Copy link
Member

@weshaggard weshaggard left a comment

Choose a reason for hiding this comment

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

Finish testing but I think the changes are ready now.

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@ghost
Copy link

ghost commented Apr 28, 2022

Hello @azure-sdk!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 0dfb187 into Azure:main Apr 28, 2022
@sima-zhu sima-zhu deleted the clean_docs_daily branch April 28, 2022 15:29
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Central-EngSys This issue is owned by the Engineering System team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants