Skip to content

Conversation

@wtgodbe
Copy link
Member

@wtgodbe wtgodbe commented Apr 19, 2023

Disables Component Governance except in internal builds of branches named main or internal/release/*. Repos who want to opt in to other branches running CG can set the disableComponentGovernance parameter in their .yml file (Same with dev branches). I tested this in EFCore and all the scenarios I tried worked. Note that repos like aspnetcore that use the job.yml template instead of jobs.yml will also have to manually set the disableComponentGovernance param. We should backport this to 6 and 7 once approved

@wtgodbe wtgodbe requested review from a team and mmitche April 19, 2023 18:54
@garath
Copy link
Member

garath commented Apr 19, 2023

Just curious, CG tools already understand the difference between "production" and "non-production" branches. Is that not covering your scenario?

@dougbu
Copy link
Contributor

dougbu commented Apr 19, 2023

Just curious, CG tools already understand the difference between "production" and "non-production" branches. Is that not covering your scenario?

There's a long email thread w/ Tactics and more people on it about this very topic. The systems no longer work that way @garath.

mmitche
mmitche previously approved these changes Apr 19, 2023
@garath
Copy link
Member

garath commented Apr 19, 2023

There's a long email thread w/ Tactics and more people on it about this very topic.

Ah I had a feeling that I was missing part of the convo. Thanks for the answer!

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 19, 2023

Test builds for new approach:

non-prod branch - Should skip CG (no arcade injected task, auto-injected task should be skipped due to variable)
prod branch - Should run the arcade injected task, skip the auto-injected task
non-prod branch that opts itself back in - Same behavior as above

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 19, 2023

Whoops, gotta account for OS when setting the variable, another iteration incoming

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 19, 2023

New builds:

non-prod branch - Should skip CG (no arcade injected task, auto-injected task should be skipped due to variable)
prod branch - Should run the arcade injected task, skip the auto-injected task
non-prod branch that opts itself back in - Same behavior as above

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 19, 2023

One more iteration because I realized that at least one of the steps in component-governance.yml needed to run on every build, and previously neither would run in PR builds against internal branches. I moved all of the logic into the invocation of the template. New builds going now

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 19, 2023

Alright, latest builds behaved how I'd expect. @dougbu any concerns with the current approach?


steps:
- ${{ if eq(parameters.disableComponentGovernance, 'true') }}:
- script: "echo ##vso[task.setvariable variable=skipComponentGovernanceDetection]true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain how this works or link to the successful test builds❔ I expected the variable would need to be set around https://github.com/dotnet/arcade/pull/13214/files#diff-22da7e3800f8d77bccd75b181def1385123174ef4a38a7ccbd7a3d7317580c12R162 i.e., before the default injection logic runs (which is effectively the first step of any pipeline).

Copy link
Member Author

@wtgodbe wtgodbe Apr 19, 2023

Choose a reason for hiding this comment

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

here is an example from a build of EFCore using the arcade files from this branch. This variable doesn't actually skip the step entirely (even when set "in time"), it only tells the step to no-op. The auto-injected step only skips entirely if CG has already ran (e.g. here)

Copy link
Contributor

Choose a reason for hiding this comment

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

In that build, click on Windows on the left side, open job preparation parameters, then head down to line 163. You'll see a long line that ends w/ a check of the variable:

Evaluating:
  and(
    eq(resources['repositories']['self']['ref'], resources['repositories']['self']['defaultBranch']),
    eq(resources['repositories']['__designer_repo']['ref'], resources['repositories']['__designer_repo']['defaultBranch']),
    or(eq(resources['repositories']['self']['type'], 'Git'),
       eq(resources['repositories']['__designer_repo']['type'], 'Git'),
       eq(resources['repositories']['self']['type'], 'Github'),
       eq(resources['repositories']['__designer_repo']['type'], 'Github'),
       eq(resources['repositories']['self']['type'], 'GitHubEnterprise'),
       eq(resources['repositories']['__designer_repo']['type'], 'GitHubEnterprise')),
    ne(variables['PREVENT_RUNNING_CG'], 'true'),
    ne(variables['skipComponentGovernanceDetection'], 'true'))

If the variable were set in job.yml's variables expansion (as we did at https://github.com/dotnet/aspnetcore/blob/bec278eabea54f63da15e10e654bdfa4168a2479/.azure/pipelines/jobs/default-build.yml#L164-L165), the step should be removed entirely. That's more efficient and avoids noise in the build display. Unfortunately, it's not working 😦

In any case and as I think about this more, I doubt there's anyone w/ a strange need to use the auto-injected task b/c it's so limited e.g., it only handles 'main' and runs in public builds too. You could simplify things and unconditionally set the variable in job.yml.

Due to the current bug around auto-injection (it worked when we changed dotnet/aspnetcore), this isn't worth holding up the PR.

dougbu
dougbu previously approved these changes Apr 20, 2023
@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 20, 2023

/backport to release/6.0

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 20, 2023

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/arcade/actions/runs/4756248514

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/arcade/actions/runs/4756249367

@github-actions
Copy link
Contributor

@wtgodbe backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Disable CG in non-prod branches
Applying: Use a template instead
Using index info to reconstruct a base tree...
M	eng/common/templates/job/job.yml
M	eng/common/templates/jobs/jobs.yml
Falling back to patching base and 3-way merge...
Auto-merging eng/common/templates/jobs/jobs.yml
Auto-merging eng/common/templates/job/job.yml
CONFLICT (content): Merge conflict in eng/common/templates/job/job.yml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Use a template instead
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@wtgodbe backporting to release/7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Disable CG in non-prod branches
Applying: Use a template instead
Using index info to reconstruct a base tree...
M	eng/common/templates/job/job.yml
Falling back to patching base and 3-way merge...
Auto-merging eng/common/templates/job/job.yml
CONFLICT (content): Merge conflict in eng/common/templates/job/job.yml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Use a template instead
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@wtgodbe an error occurred while backporting to release/6.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@github-actions
Copy link
Contributor

@wtgodbe an error occurred while backporting to release/7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@wtgodbe
Copy link
Member Author

wtgodbe commented Apr 20, 2023

Manual PRs incoming. Looks like the timeout failure is happening everywhere, @mmitche / @dougbu could I get help merging this?

@mmitche mmitche merged commit d75baf7 into main Apr 20, 2023
@wtgodbe wtgodbe deleted the wtgodbe/CGCondition branch April 20, 2023 20:55
- template: /eng/common/templates/steps/component-governance.yml
parameters:
${{ if eq(parameters.disableComponentGovernance, '') }}:
${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), eq(parameters.runAsPublic, 'false'), or(contains(variables['Build.SourceBranch'], 'internal/release'), eq(variables['Build.SourceBranch'], 'main'))) }}:
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't the 'Build.SourceBranch' contain the full branch name?

eq(variables['Build.SourceBranch'], 'main') ---> eq(variables['Build.SourceBranch'], 'refs/heads/main')
contains(variables['Build.SourceBranch'], 'internal/release') ---> startsWith(variables['Build.SourceBranch'], 'refs/heads/internal/release')

Comment on lines +159 to +165
parameters:
${{ if eq(parameters.disableComponentGovernance, '') }}:
${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), eq(parameters.runAsPublic, 'false'), or(contains(variables['Build.SourceBranch'], 'internal/release'), eq(variables['Build.SourceBranch'], 'main'))) }}:
disableComponentGovernance: false
${{ else }}:
disableComponentGovernance: true
componentGovernanceIgnoreDirectories: ${{ parameters.componentGovernanceIgnoreDirectories }}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it have something like

        disableComponentGovernance: ${{ parameters.disableComponentGovernance }}

in the non-empty case to pass the value through? (We are getting CG warnings in our internal superpmi-collect pipeline that tries to pass this through to job.yml.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I put up a PR for this: #13274

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants