Skip to content

Commit

Permalink
[repo] Add dedicated CI for AspNet projects (#1386)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com>
  • Loading branch information
CodeBlanch and Kielek authored Oct 11, 2023
1 parent 7d0524f commit 0e3495a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 135 deletions.
6 changes: 6 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ flags:
paths:
- src/OpenTelemetry.Exporter.OneCollector

unittests-Instrumentation.AspNet:
carryforward: true
paths:
- src/OpenTelemetry.Instrumentation.AspNet
- src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule

unittests-Instrumentation.Owin:
carryforward: true
paths:
Expand Down
70 changes: 54 additions & 16 deletions .github/workflows/Component.Package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ on:
project-name:
required: true
type: string
release-name:
required: false
type: string
default: ''

jobs:
build-test-pack:
permissions:
contents: write

strategy:
matrix:
os: [windows-latest]
runs-on: windows-latest

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -40,21 +41,58 @@ jobs:
- name: Publish Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.project-name }}-packages
path: '**/${{ inputs.project-name }}/bin/**/*.*nupkg'
name: ${{ inputs.project-name }}.proj-packages
path: 'src/*/bin/Release/*.*nupkg'

- name: Publish Nuget
- name: Publish NuGets
run: |
nuget push **/${{ inputs.project-name }}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }}
- name: Create GitHub Prerelease
if: ${{ (contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{ inputs.project-name }}/CHANGELOG.md) for details." --prerelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
nuget push src/*/bin/Release/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }}
- name: Create GitHub Release
if: ${{ !(contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{ inputs.project-name }}/CHANGELOG.md) for details." --latest
shell: pwsh
run: |
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
$notes = ''
$firstPackageVersion = ''
foreach ($package in $packages)
{
$match = [regex]::Match($package, '(.*)\.(\d+\.\d+\.\d+.*?)\.nupkg')
$packageName = $match.Groups[1].Value
$packageVersion = $match.Groups[2].Value
if ($firstPackageVersion -eq '')
{
$firstPackageVersion = $packageVersion
}
$notes +=
@"
* NuGet: [$packageName v$packageVersion](https://www.nuget.org/packages/$packageName/$packageVersion)
See [CHANGELOG](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
"@
}
$releaseName = '${{ inputs.release-name || inputs.project-name }}'
if ($firstPackageVersion -contains '-alpha' -or $firstPackageVersion -contains '-beta' -or $firstPackageVersion -contains '-rc')
{
gh release create ${{ github.ref_name }} `
--title "$releaseName v$firstPackageVersion" `
--verify-tag `
--notes "$notes" `
--prerelease
}
else
{
gh release create ${{ github.ref_name }} `
--title "$releaseName v$firstPackageVersion" `
--verify-tag `
--notes "$notes" `
--latest
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
build: ['build/**', '.github/**/*.yml', '!.github/workflows/package-*']
shared: ['src/Shared/**']
code: ['**.cs', '.editorconfig']
aspnet: ['*/OpenTelemetry.Instrumentation.AspNet*/**', 'examples/AspNet/**', '!**/*.md']
geneva: ['*/OpenTelemetry.Exporter.Geneva*/**', '!**/*.md']
onecollector: ['*/OpenTelemetry.Instrumentation.OneCollector*/**', '!**/*.md']
owin: ['*/OpenTelemetry.Instrumentation.Owin*/**', 'examples/owin/**', '!**/*.md']
Expand Down Expand Up @@ -54,6 +55,19 @@ jobs:
if: contains(needs.detect-changes.outputs.changes, 'code')
uses: ./.github/workflows/dotnet-format.yml

build-test-aspnet:
needs: detect-changes
if: |
contains(needs.detect-changes.outputs.changes, 'aspnet')
|| contains(needs.detect-changes.outputs.changes, 'build')
|| contains(needs.detect-changes.outputs.changes, 'shared')
uses: ./.github/workflows/Component.BuildTest.yml
with:
project-name: OpenTelemetry.Instrumentation.AspNet
code-cov-name: Instrumentation.AspNet
os-list: '[ "windows-latest" ]'
tfm-list: '[ "net462" ]'

build-test-geneva:
needs: detect-changes
if: |
Expand Down Expand Up @@ -167,6 +181,8 @@ jobs:
-Exclude `
OpenTelemetry.Exporter.Geneva.Tests.csproj,
OpenTelemetry.Exporter.OneCollector.Tests.csproj,
OpenTelemetry.Instrumentation.AspNet.Tests.csproj,
OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests.csproj,
OpenTelemetry.Instrumentation.Owin.Tests.csproj,
OpenTelemetry.Instrumentation.Process.Tests.csproj,
OpenTelemetry.Instrumentation.StackExchangeRedis.Tests.csproj,
Expand Down Expand Up @@ -200,6 +216,7 @@ jobs:
detect-changes,
lint-md,
lint-dotnet-format,
build-test-aspnet,
build-test-geneva,
build-test-onecollector,
build-test-owin,
Expand Down

This file was deleted.

60 changes: 9 additions & 51 deletions .github/workflows/package-Instrumentation.AspNet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Pack OpenTelemetry.Instrumentation.AspNet

# Note: This releases OpenTelemetry.Instrumentation.AspNet & OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule

on:
workflow_dispatch:
inputs:
Expand All @@ -9,58 +11,14 @@ on:
default: 'warning'
push:
tags:
- 'Instrumentation.AspNet-*'
- 'Instrumentation.AspNet-*' # trigger when we create a tag with prefix "Instrumentation.AspNet-"

jobs:
build-test-pack:
runs-on: ${{ matrix.os }}
call-build-test-pack:
permissions:
contents: write
env:
PROJECT: OpenTelemetry.Instrumentation.AspNet

strategy:
matrix:
os: [windows-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetching all

- name: Setup dotnet
uses: actions/setup-dotnet@v3

- name: Install dependencies
run: dotnet restore src/${{env.PROJECT}}

- name: dotnet build ${{env.PROJECT}}
run: dotnet build src/${{env.PROJECT}} --configuration Release --no-restore -p:Deterministic=true

- name: dotnet test ${{env.PROJECT}}
run: dotnet test test/${{env.PROJECT}}.Tests

- name: dotnet pack ${{env.PROJECT}}
run: dotnet pack src/${{env.PROJECT}} --configuration Release --no-build

- name: Publish Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{env.PROJECT}}-packages
path: '**/${{env.PROJECT}}/bin/**/*.*nupkg'

- name: Publish Nuget
run: |
nuget push **/${{env.PROJECT}}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }}
- name: Create GitHub Prerelease
if: ${{ (contains(github.ref_name, '-alpha.') || contains(github.ref_name, '-beta.') || contains(github.ref_name, '-rc.') || contains(github.ref_name, '-rc9.')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{env.PROJECT}}/CHANGELOG.md) for details." --prerelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub Release
if: ${{ !(contains(github.ref_name, '-alpha.') || contains(github.ref_name, '-beta.') || contains(github.ref_name, '-rc.') || contains(github.ref_name, '-rc9.')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{env.PROJECT}}/CHANGELOG.md) for details." --latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ./.github/workflows/Component.Package.yml
with:
project-name: OpenTelemetry.Instrumentation.AspNet
release-name: 'OpenTelemetry Asp.Net Instrumentation Packages'
secrets: inherit
30 changes: 30 additions & 0 deletions build/Projects/OpenTelemetry.Instrumentation.AspNet.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project>

<PropertyGroup>
<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.Parent.FullName)</RepoRoot>
</PropertyGroup>

<ItemGroup>
<SolutionProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj" />
<SolutionProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet\OpenTelemetry.Instrumentation.AspNet.csproj" />
<SolutionProjects Include="$(RepoRoot)\test\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests.csproj" />
<SolutionProjects Include="$(RepoRoot)\test\OpenTelemetry.Instrumentation.AspNet.Tests\OpenTelemetry.Instrumentation.AspNet.Tests.csproj" />
<SolutionProjects Include="$(RepoRoot)\examples\AspNet\**\*.csproj" />

<PackProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj" />
<PackProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet\OpenTelemetry.Instrumentation.AspNet.csproj" />
</ItemGroup>

<Target Name="Build">
<MSBuild Projects="@(SolutionProjects)" Targets="Build" ContinueOnError="ErrorAndStop" />
</Target>

<Target Name="Restore">
<MSBuild Projects="@(SolutionProjects)" Targets="Restore" ContinueOnError="ErrorAndStop" />
</Target>

<Target Name="Pack">
<MSBuild Projects="@(PackProjects)" Targets="Pack" ContinueOnError="ErrorAndStop" />
</Target>

</Project>
1 change: 0 additions & 1 deletion opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\package-Extensions.AzureMonitor.yml = .github\workflows\package-Extensions.AzureMonitor.yml
.github\workflows\package-Extensions.Docker.yml = .github\workflows\package-Extensions.Docker.yml
.github\workflows\package-Extensions.yml = .github\workflows\package-Extensions.yml
.github\workflows\package-Instrumentation.AspNet.TelemetryHttpModule.yml = .github\workflows\package-Instrumentation.AspNet.TelemetryHttpModule.yml
.github\workflows\package-Instrumentation.AspNet.yml = .github\workflows\package-Instrumentation.AspNet.yml
.github\workflows\package-Instrumentation.AWS.yml = .github\workflows\package-Instrumentation.AWS.yml
.github\workflows\package-Instrumentation.AWSLambda.yml = .github\workflows\package-Instrumentation.AWSLambda.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IncludeSharedExceptionExtensionsSource>true</IncludeSharedExceptionExtensionsSource>
<Description>A module that instruments incoming request with System.Diagnostics.Activity and notifies listeners with DiagnosticsSource.</Description>
<PackageTags>$(PackageTags);distributed-tracing;AspNet;MVC;WebAPI</PackageTags>
<MinVerTagPrefix>Instrumentation.AspNet.TelemetryHttpModule-</MinVerTagPrefix>
<MinVerTagPrefix>Instrumentation.AspNet-</MinVerTagPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 0e3495a

Please sign in to comment.