-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split workitem validation and labeling workflows #2960
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||||
name: Enrich Pull Request | ||||||||
on: | ||||||||
workflow_run: | ||||||||
workflows: ["Work Item Validation"] | ||||||||
types: | ||||||||
- completed | ||||||||
|
||||||||
permissions: | ||||||||
contents: read | ||||||||
pull-requests: write | ||||||||
issues: write | ||||||||
|
||||||||
defaults: | ||||||||
run: | ||||||||
shell: pwsh | ||||||||
|
||||||||
jobs: | ||||||||
GitHubIssueValidation: | ||||||||
name: 'Validate link to issues and work items' | ||||||||
runs-on: ubuntu-latest | ||||||||
steps: | ||||||||
- name: Harden Runner | ||||||||
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 | ||||||||
with: | ||||||||
egress-policy: audit | ||||||||
|
||||||||
- name: Checkout | ||||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||||||||
|
||||||||
- name: Validate work items for pull request | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
build/scripts/PullRequestValidation/ValidateIssuesForPullRequest.ps1 -PullRequestNumber ${{github.event.workflow_run.pull_requests[0].number}} -Repository ${{ github.repository }} | ||||||||
- name: Link work items to pull request if possible | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
build/scripts/PullRequestValidation/LinkPullRequestToWorkItem.ps1 -PullRequestNumber ${{github.event.workflow_run.pull_requests[0].number}} -Repository ${{ github.repository }} | ||||||||
- name: Validate internal work items for pull request | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
build/scripts/PullRequestValidation/ValidateInternalWorkItemForPullRequest.ps1 -PullRequestNumber ${{github.event.workflow_run.pull_requests[0].number}} -Repository ${{ github.repository }} | ||||||||
- name: Add Linked label to PR | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if: github.event.workflow_run.head_repository.full_name != github.repository | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
gh api /repos/${{ github.repository }}/issues/${{github.event.workflow_run.pull_requests[0].number}}/labels -f "labels[]=Linked" -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" | ||||||||
- name: Add milestone to PR | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
build/scripts/PullRequestValidation/AddMilestoneToPullRequest.ps1 -PullRequestNumber ${{github.event.workflow_run.pull_requests[0].number}} -Repository ${{ github.repository }} | ||||||||
Label: | ||||||||
name: 'Label pull request' | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the same workflow, can't the two jobs be consolidated as well? |
||||||||
runs-on: ubuntu-latest | ||||||||
steps: | ||||||||
- name: Label pull request | ||||||||
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 | ||||||||
with: | ||||||||
repo-token: '${{ secrets.GITHUB_TOKEN }}' | ||||||||
sync-labels: true | ||||||||
pr-number: ${{github.event.workflow_run.pull_requests[0].number}} | ||||||||
|
||||||||
- name: Label community contribution | ||||||||
if: github.event.workflow_run.head_repository.full_name != github.repository | ||||||||
env: | ||||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||
run: | | ||||||||
gh api /repos/${{ github.repository }}/issues/${{github.event.workflow_run.pull_requests[0].number}}/labels -f "labels[]=From Fork" -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,37 @@ | ||
name: Work Item Validation | ||
|
||
on: | ||
pull_request_target: | ||
pull_request: | ||
types: [opened, synchronize, reopened, edited] | ||
branches: [ 'main', 'releases/*' ] | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
issues: write | ||
permissions: read-all | ||
|
||
defaults: | ||
run: | ||
shell: pwsh | ||
|
||
jobs: | ||
GitHubIssueValidation: | ||
if: github.repository_owner == 'microsoft' && github.event.pull_request.state == 'open' | ||
name: 'Validate link to issues' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 | ||
with: | ||
egress-policy: audit | ||
|
||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Validate work items for pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/ValidateIssuesForPullRequest.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} | ||
|
||
WorkItemValidationForMicrosoft: | ||
if: github.repository_owner == 'microsoft' && github.event.pull_request.state == 'open' | ||
name: 'For Microsoft: Validate link to internal work items' | ||
runs-on: ubuntu-latest | ||
needs: GitHubIssueValidation | ||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 | ||
with: | ||
egress-policy: audit | ||
|
||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Link work items to pull request if possible | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/LinkPullRequestToWorkItem.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} | ||
|
||
- name: Validate internal work items for pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/ValidateInternalWorkItemForPullRequest.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} | ||
|
||
- name: Add Linked label to PR | ||
if: github.event.pull_request.head.repo.full_name != github.repository | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh api /repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels -f "labels[]=Linked" -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" | ||
|
||
- name: Add milestone to PR | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/AddMilestoneToPullRequest.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} | ||
WorkItemValidationForMicrosoft: | ||
name: 'For Microsoft: Validate link to internal work items' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 | ||
with: | ||
egress-policy: audit | ||
|
||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: Validate work items for pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/ValidateIssuesForPullRequest.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} -ValidateOnly | ||
|
||
- name: Validate internal work items for pull request | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
build/scripts/PullRequestValidation/ValidateInternalWorkItemForPullRequest.ps1 -PullRequestNumber ${{ github.event.pull_request.number }} -Repository ${{ github.repository }} -ValidateOnly |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ param( | |
[Parameter(Mandatory = $true)] | ||
[string] $PullRequestNumber, | ||
[Parameter(Mandatory = $true)] | ||
[string] $Repository | ||
[string] $Repository, | ||
[Parameter(Mandatory = $false)] | ||
[switch] $ValidateOnly | ||
) | ||
|
||
# Set error action | ||
|
@@ -24,22 +26,26 @@ function Test-ADOWorkItemIsLinked() { | |
[Parameter(Mandatory = $false)] | ||
[string[]] $ADOWorkItems, | ||
[Parameter(Mandatory = $false)] | ||
[object] $PullRequest | ||
[object] $PullRequest, | ||
[Parameter(Mandatory = $false)] | ||
[switch] $ValidateOnly | ||
) | ||
|
||
$Comment = "Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'" | ||
|
||
if (-not $ADOWorkItems) { | ||
# If the pull request is not from a fork, add a comment to the pull request | ||
if (-not $PullRequest.IsFromFork()) { | ||
# If the pull request is not from a fork and not validate only, add a comment | ||
if (-not $PullRequest.IsFromFork() -and -not $ValidateOnly) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The How about we scratch that part? The workflow error should be descriptive enough. |
||
$PullRequest.AddComment($Comment) | ||
} | ||
|
||
# Throw an error if there is no linked ADO workitem | ||
throw $Comment | ||
} | ||
|
||
$PullRequest.RemoveComment($Comment) | ||
if (-not $ValidateOnly) { | ||
$PullRequest.RemoveComment($Comment) | ||
} | ||
} | ||
|
||
Write-Host "Validating PR $PullRequestNumber" | ||
|
@@ -52,6 +58,6 @@ if (-not $pullRequest) { | |
$adoWorkItems = $pullRequest.GetLinkedADOWorkItemIDs() | ||
|
||
# Validate that all pull requests links to an ADO workitem | ||
Test-ADOWorkItemIsLinked -ADOWorkItems $adoWorkItems -PullRequest $PullRequest | ||
Test-ADOWorkItemIsLinked -ADOWorkItems $adoWorkItems -PullRequest $PullRequest -ValidateOnly:$ValidateOnly | ||
|
||
Write-Host "PR $PullRequestNumber validated successfully" -ForegroundColor Green |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a check here that the parent workflow was successful?