Skip to content

Commit

Permalink
Merge branch 'main' into fix/1562
Browse files Browse the repository at this point in the history
  • Loading branch information
joegoldman2 committed Jun 12, 2024
2 parents da6428e + 39a7818 commit c7ac4b4
Show file tree
Hide file tree
Showing 74 changed files with 1,321 additions and 288 deletions.
42 changes: 36 additions & 6 deletions .github/workflows/add-labels.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
name: 'Add labels for component found in bug issue descriptions'
name: 'Add labels to issues and pull requests'
on:
issues:
types: [opened]
types: [ opened ]

pull_request_target:
branches: [ 'main*', 'instrumentation*', 'exporter*', 'extensions*' ]

permissions:
issues: write
pull-requests: write

jobs:
add-labels:
if: ${{ !github.event.issue.pull_request }}
add-labels-on-issues:
if: github.event_name == 'issues' && !github.event.issue.pull_request

runs-on: ubuntu-latest

steps:
- name: check out code
uses: actions/checkout@v4

- name: Add labels for component found in bug issue descriptions
shell: pwsh
run: |
.\build\scripts\add-labels.ps1 -issueNumber $env:ISSUE_NUMBER -issueBody $env:ISSUE_BODY
Import-Module .\build\scripts\add-labels.psm1
AddLabelsOnIssuesForComponentFoundInBody `
-issueNumber ${{ github.event.issue.number }} `
-issueBody $env:ISSUE_BODY
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_BODY: ${{ github.event.issue.body }}

add-labels-on-pull-requests:
if: github.event_name == 'pull_request_target'

runs-on: ubuntu-latest

steps:
- name: check out code
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }} # Note: Do not run on the PR branch we want to execute add-labels.psm1 from main on the base repo only because pull_request_target can see secrets

- name: Add labels for files changed on pull requests
shell: pwsh
run: |
Import-Module .\build\scripts\add-labels.psm1
AddLabelsOnPullRequestsBasedOnFilesChanged `
-pullRequestNumber ${{ github.event.pull_request.number }} `
-labelPackagePrefix 'comp:'
env:
GH_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .github/workflows/automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
value: ${{ vars.AUTOMATION_EMAIL }}
secrets:
OPENTELEMETRYBOT_GITHUB_TOKEN:
required: true
required: false

jobs:
resolve-automation:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
&& github.event.action == 'closed'
&& github.event.pull_request.user.login == needs.automation.outputs.username
&& github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.title, '[repo] Prepare release ')
&& startsWith(github.event.pull_request.title, '[release] Prepare release ')
&& needs.automation.outputs.enabled
env:
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
&& github.event.issue.locked == true
&& github.event.comment.user.login != needs.automation.outputs.username
&& contains(github.event.comment.body, '/CreateReleaseTag')
&& startsWith(github.event.issue.title, '[repo] Prepare release ')
&& startsWith(github.event.issue.title, '[release] Prepare release ')
&& github.event.issue.pull_request.merged_at
&& needs.automation.outputs.enabled
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:

outputs:
artifact-url: ${{ steps.upload-artifacts.outputs.artifact-url }}
artifact-id: ${{ steps.upload-artifacts.outputs.artifact-id }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -120,6 +121,16 @@ jobs:
with:
token: ${{ secrets[needs.automation.outputs.token-secret-name] }}

- name: Download Artifacts
run: |
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ github.token }}" \
-L \
-o '${{ github.workspace }}/artifacts/${{ github.ref_name }}-packages.zip' \
--create-dirs \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${{ needs.build-pack-publish.outputs.artifact-id }}/zip"
- name: Create GitHub Release
if: github.ref_type == 'tag'
shell: pwsh
Expand All @@ -128,7 +139,8 @@ jobs:
CreateRelease `
-gitRepository '${{ github.repository }}' `
-tag '${{ github.ref_name }}'
-tag '${{ github.ref_name }}' `
-releaseFiles '${{ github.workspace }}/artifacts/${{ github.ref_name }}-packages.zip#Packages'
- name: Post notice when packages are ready
shell: pwsh
Expand Down
6 changes: 3 additions & 3 deletions build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<OpenTelemetryExporterInMemoryPkgVer>$(OpenTelemetryCoreLatestVersion)</OpenTelemetryExporterInMemoryPkgVer>
<OpenTelemetryExporterInMemoryLatestPreReleasePkgVer>$(OpenTelemetryCoreLatestPrereleaseVersion)</OpenTelemetryExporterInMemoryLatestPreReleasePkgVer>
<SupportedNetTargets>net8.0;net7.0;net6.0</SupportedNetTargets>
<XUnitRunnerVisualStudioPkgVer>[2.5.0,3.0)</XUnitRunnerVisualStudioPkgVer>
<XUnitPkgVer>[2.5.0,3.0)</XUnitPkgVer>
<WiremockNetPkgVer>[1.5.48,2.0)</WiremockNetPkgVer>
<XUnitRunnerVisualStudioPkgVer>[2.8.1,3.0)</XUnitRunnerVisualStudioPkgVer>
<XUnitPkgVer>[2.8.1,3.0)</XUnitPkgVer>
<WiremockNetPkgVer>[1.5.58,2.0)</WiremockNetPkgVer>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
Expand Down
12 changes: 0 additions & 12 deletions build/scripts/add-labels.ps1

This file was deleted.

148 changes: 148 additions & 0 deletions build/scripts/add-labels.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
function AddLabelsOnIssuesForComponentFoundInBody {
param(
[Parameter(Mandatory=$true)][int]$issueNumber,
[Parameter(Mandatory=$true)][string]$issueBody
)

$match = [regex]::Match($issueBody, '^[#]+ Component\s*OpenTelemetry\.((?:.|\w+)+)')
if ($match.Success -eq $false)
{
Return
}

gh issue edit $issueNumber --add-label $("comp:" + $match.Groups[1].Value.ToLower())
}

Export-ModuleMember -Function AddLabelsOnIssuesForComponentFoundInBody

function AddLabelsOnPullRequestsBasedOnFilesChanged {
param(
[Parameter(Mandatory=$true)][int]$pullRequestNumber,
[Parameter(Mandatory=$true)][string]$labelPackagePrefix # 'pkg:' on main repo, 'comp:' on contrib repo
)

# Note: This function is intended to work on main repo and on contrib. Please
# keep them in sync.

$repoLabels = gh label list --json name,id | ConvertFrom-Json

$filesChangedOnPullRequest = gh pr diff $pullRequestNumber --name-only

$labelsOnPullRequest = (gh pr view $pullRequestNumber --json labels | ConvertFrom-Json).labels

$visitedProjects = New-Object System.Collections.Generic.HashSet[string]
$labelsToAdd = New-Object System.Collections.Generic.HashSet[string]
$labelsToRemove = New-Object System.Collections.Generic.HashSet[string]

# Note: perf label may be added but it is kind of a guess so we don't remove
# it automatically in order to also allow manual inclusion after reviewing files
$managedLabels = 'infra', 'documentation', 'dependencies'
$rootInfraFiles = 'global.json', 'NuGet.config', 'codeowners'
$documentationFiles = 'readme.md', 'contributing.md', 'releasing.md', 'versioning.md'

foreach ($fileChanged in $filesChangedOnPullRequest)
{
$fileChanged = $fileChanged.ToLower()
$fullFileName = [System.IO.Path]::GetFileName($fileChanged)
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($fileChanged)
$fileExtension = [System.IO.Path]::GetExtension($fileChanged)

if ($fileChanged.StartsWith('src/') -or $fileChanged.StartsWith('test/'))
{
$match = [regex]::Match($fileChanged, '^(?:(?:src)|(?:test))\/(.*?)\/.+$')
if ($match.Success -eq $false)
{
continue
}
$rawProjectName = $match.Groups[1].Value
if ($rawProjectName.Contains(".benchmarks") -or $rawProjectName.Contains(".stress"))
{
$added = $labelsToAdd.Add("perf")
}

$projectName = $rawProjectName.Replace(".tests", "").Replace(".benchmarks", "").Replace(".stress", "")
if ($visitedProjects.Contains($projectName))
{
continue
}

$added = $visitedProjects.Add($projectName);

foreach ($repoLabel in $repoLabels)
{
if ($repoLabel.name.StartsWith($labelPackagePrefix))
{
$package = $repoLabel.name.Substring($labelPackagePrefix.Length).ToLower()
if ($package.StartsWith('opentelemetry') -eq $false)
{
# Note: On contrib labels don't have "OpenTelemetry." prefix
$package = 'opentelemetry.' + $package
}
if ($package -eq $projectName)
{
$added = $labelsToAdd.Add($repoLabel.name)
break
}
}
}
}

if ($documentationFiles.Contains($fullFileName) -or
$fileChanged.StartsWith('docs/') -or
$fileChanged.StartsWith('examples/'))
{
$added = $labelsToAdd.Add("documentation")
}

if ($fileChanged.StartsWith('build/') -or
$fileChanged.StartsWith('.github/') -or
$rootInfraFiles.Contains($fullFileName) -or
$fileExtension -eq ".props" -or
$fileExtension -eq ".targets" -or
$fileChanged.StartsWith('test\openTelemetry.aotcompatibility'))
{
$added = $labelsToAdd.Add("infra")
}

if ($fileChanged.StartsWith('test\benchmarks'))
{
$added = $labelsToAdd.Add("perf")
}

if ($fullFileName -eq 'directory.packages.props')
{
$added = $labelsToAdd.Add("dependencies")
}
}

foreach ($labelOnPullRequest in $labelsOnPullRequest)
{
if ($labelsToAdd.Contains($labelOnPullRequest.name))
{
$removed = $labelsToAdd.Remove($labelOnPullRequest.name)
}
elseif ($labelOnPullRequest.name.StartsWith($labelPackagePrefix) -or
$managedLabels.Contains($labelOnPullRequest.name))
{
$added = $labelsToRemove.Add($labelOnPullRequest.name)
}
}

if ($labelsToAdd.Count -gt 0)
{
foreach ($label in $labelsToAdd)
{
gh pr edit $pullRequestNumber --add-label $label
}
}

if ($labelsToRemove.Count -gt 0)
{
foreach ($label in $labelsToRemove)
{
gh pr edit $pullRequestNumber --remove-label $label
}
}
}

Export-ModuleMember -Function AddLabelsOnPullRequestsBasedOnFilesChanged
19 changes: 10 additions & 9 deletions build/scripts/post-release.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function CreateRelease {
param(
[Parameter(Mandatory=$true)][string]$gitRepository,
[Parameter(Mandatory=$true)][string]$tag
[Parameter(Mandatory=$true)][string]$tag,
[Parameter()][string]$releaseFiles
)

$match = [regex]::Match($tag, '^(.*?-)(.*)$')
Expand All @@ -28,7 +29,7 @@ function CreateRelease {

foreach ($line in $changelogContent)
{
if ($line -like "## $packageVersion" -and $started -ne $true)
if ($line -like "## $version" -and $started -ne $true)
{
$started = $true
}
Expand Down Expand Up @@ -69,15 +70,15 @@ $content

if ($version -match '-alpha' -or $version -match '-beta' -or $version -match '-rc')
{
gh release create $tag `
gh release create $tag $releaseFiles `
--title $tag `
--verify-tag `
--notes $notes `
--prerelease
}
else
{
gh release create $tag `
gh release create $tag $releaseFiles `
--title $tag `
--verify-tag `
--notes $notes `
Expand Down Expand Up @@ -106,7 +107,7 @@ function TryPostPackagesReadyNoticeOnPrepareReleasePullRequest {

foreach ($pr in $prListResponse)
{
if ($pr.author.login -ne $botUserName -or $pr.title -ne "[repo] Prepare release $tag")
if ($pr.author.login -ne $botUserName -or $pr.title -ne "[release] Prepare release $tag")
{
continue
}
Expand Down Expand Up @@ -249,11 +250,11 @@ Merge once packages are available on NuGet and the build passes.
"@

gh pr create `
--title "[repo] $tagPrefix stable release $version updates" `
--title "[release] $tagPrefix stable release $version updates" `
--body $body `
--base $targetBranch `
--head $branch `
--label infra
--label release
}

Export-ModuleMember -Function CreatePackageValidationBaselineVersionUpdatePullRequest
Expand Down Expand Up @@ -362,11 +363,11 @@ Merge once packages are available on NuGet and the build passes.
"@

$createPullRequestResponse = gh pr create `
--title "[repo] Core release $version updates" `
--title "[release] Core release $version updates" `
--body $body `
--base $targetBranch `
--head $branch `
--label infra
--label release

$match = [regex]::Match($createPullRequestResponse, "\/pull\/(.*)$")
if ($match.Success -eq $false)
Expand Down
Loading

0 comments on commit c7ac4b4

Please sign in to comment.