Skip to content

Commit 1c7a041

Browse files
committed
Added in more optimisations and document the process
1 parent 942022b commit 1c7a041

18 files changed

+116
-25
lines changed

.github/ci-Template.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: build-test
2+
3+
on:
4+
pull_request:
5+
branches: [ 'main*', 'instrumentation*', 'exporter*', 'extensions*' ]
6+
paths:
7+
- 'modules/{{moduleName}}/**'
8+
9+
jobs:
10+
{{moduleName}}:
11+
uses: ./.github/workflows/build-module.yml
12+
with:
13+
module-name: {{moduleName}}
14+
module-directory: './modules/{{moduleName}}'
15+
16+
build-test:
17+
needs: [
18+
{{moduleName}}
19+
]
20+
if: always() && !cancelled()
21+
runs-on: ubuntu-22.04
22+
steps:
23+
- run: |
24+
if ( ${{ contains(needs.*.result, 'failure') }} == true ); then echo 'build failed ✗'; exit 1; else echo 'build complete ✓'; fi

.github/workflows/Dotnet.Main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ jobs:
113113
with:
114114
files: '**/TestResults/**/*Cobertura.xml'
115115
env_vars: OS,TFM,FILTER
116-
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
117-
name: Code Coverage for ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }} on [${{ matrix.os }}.${{ matrix.version }}]
116+
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.module-name }}
117+
name: Code Coverage for ${{ inputs.code-cov-prefix }}-${{ inputs.module-name }} on [${{ matrix.os }}.${{ matrix.version }}]
118118
codecov_yml_path: .github/codecov.yml
119119

120120
- name: Upload test results ${{ inputs.code-cov-prefix }}-${{ inputs.module-name }}
@@ -123,6 +123,6 @@ jobs:
123123
with:
124124
files: '**/TestResults/junit.xml'
125125
env_vars: OS,TFM,FILTER
126-
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
127-
name: Test results for ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }} on [${{ matrix.os }}.${{ matrix.version }}]
126+
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.module-name }}
127+
name: Test results for ${{ inputs.code-cov-prefix }}-${{ inputs.module-name }} on [${{ matrix.os }}.${{ matrix.version }}]
128128
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/ci-Resources.OperatingSystem.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: build-test
22

33
on:
4+
push:
5+
branches: [ 'main*', 'instrumentation*', 'exporter*', 'extensions*' ]
6+
paths:
7+
- 'modules/Resources.OperatingSystem/**'
48
pull_request:
59
branches: [ 'main*', 'instrumentation*', 'exporter*', 'extensions*' ]
610
paths:

CONTRIBUTING.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,43 @@ file for the new project. The component owner(s) are expected to respond to
210210
issues and review PRs affecting their component.
211211

212212
Although the projects within this repo share some properties and configurations,
213-
they are built and released independently. So if you are creating a new project
214-
within `/src` and corresponding test project within `/test`, here are a few
215-
things you should do to ensure that your project is automatically built and
216-
shipped through CI.
213+
they are built and released independently. This independence is controlled via modules.
214+
If you are creating a new module the first step is to create a folder
215+
within the `/modules` folder for your module. This folder will contain the following:
216+
217+
* `/src` folder for the source code
218+
* `/test` folder for the tests
219+
* `OpenTelemetry.{moduleName}.slnf` which is a solution filter for your project
220+
* `Directory.packages.props` a listing of all packages used and enables CPM.
221+
This is to import from the root file.
222+
* `Directory.build.props` a convient location to define
223+
shared properties for your module.
224+
This is to import from the root file.
225+
226+
To facilitate CI/CD, a workflow needs to be added in the `.github\workflows` folder.
227+
This file should be based on `ci-Template.yml` with
228+
`{{moduleName}}` replaced with your module name.
229+
230+
To facilitate code coverage analysis, a block based on the below
231+
232+
```code
233+
unittests-{{moduleName}}:
234+
carryforward: true
235+
paths:
236+
- modules/{{moduleName}}/src/OpenTelemetry.{{moduleName}}
237+
```
238+
239+
with
240+
`{{moduleName}}` replaced with your module name.
217241

218242
> [!NOTE]
219243
> It is generally helpful to reference a previous pull request when adding a new
220244
project to the repository. A good example to follow is the pull request which
221245
added the `OpenTelemetry.Resources.OperatingSystem` project:
222246
[#1943](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1943).
223247

248+
### Additional Information for new projects
249+
224250
* Based on what your project is, you may need to depend on the [OpenTelemetry
225251
SDK](https://www.nuget.org/packages/OpenTelemetry) or the [OpenTelemetry
226252
API](https://www.nuget.org/packages/OpenTelemetry.Api) Include the necessary
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<Project>
2-
<Import Project="..\Directory.Build.props" Condition="Exists('..\Directory.Build.props')" />
32
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'opentelemetry-dotnet-contrib.sln'))\build\Common.prod.props" />
43
</Project>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22

3-
<Import Project="..\Directory.Build.targets" Condition="Exists('..\Directory.Build.targets')" />
4-
<Import Project="$(RepoRoot)\build\Common.targets" />
3+
<Import Project="build\Common.targets" />
54

65
<PropertyGroup>
76
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>

Directory.Packages.props

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project>
2+
<PropertyGroup Condition="'$(IsCPM)' != 'true'">
3+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<PropertyGroup Condition="'$(IsCPM)' == 'true'">
6+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
7+
</PropertyGroup>
8+
<!-- Todo: Move the below to the global parent-->
9+
<ItemGroup Condition="'$(IsCPM)' == 'true'">
10+
<GlobalPackageReference Include="MinVer" Version="[6.0.0,7.0)" Condition="'$(IntegrationBuild)' != 'true'" />
11+
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="[8.0.0,9.0)" />
12+
<GlobalPackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23525.2]" />
13+
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="[1.0.3,2.0)" />
14+
<GlobalPackageReference Include="StyleCop.Analyzers" Version="[1.2.0-beta.556,2.0)" Condition="'$(SkipAnalysis)'!='true'" />
15+
</ItemGroup>
16+
17+
<ItemGroup Condition="'$(IsTestProject)' == 'true' and '$(IsCPM)' == 'true'">
18+
<GlobalPackageReference Include="GitHubActionsTestLogger" Version="2.4.1" />
19+
<GlobalPackageReference Include="JunitXml.TestLogger" Version="6.1.0" />
20+
<GlobalPackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.12.0,18.0)" />
21+
<GlobalPackageReference Include="xunit" Version="[2.9.3,3.0)" />
22+
<GlobalPackageReference Include="xunit.runner.visualstudio" Version="[2.8.2,3.0)" />
23+
</ItemGroup>
24+
</Project>

Directory.Solution.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup Condition="$(MSBuildProjectName.Contains('.Tests'))">
3+
<IsTestProject>true</IsTestProject>
4+
</PropertyGroup>
5+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'opentelemetry-dotnet-contrib.sln'))\build\Common.prod.props" />
6+
</Project>

build/Common.nonprod.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<WiremockNetPkgVer>[1.7.0,2.0)</WiremockNetPkgVer>
3939
</PropertyGroup>
4040

41-
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
41+
<ItemGroup Condition="'$(IsTestProject)' == 'true' and '$(IsCPM)' != 'true'">
4242
<PackageReference Include="GitHubActionsTestLogger" Version="$(GitHubActionsTestLoggerPkgVer)" />
4343
<PackageReference Include="JunitXml.TestLogger" Version="$(JunitXmlTestLoggerPkgVer)" />
4444
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPkgVer)" />

build/Common.prod.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<PackageChangelogFile>CHANGELOG.md</PackageChangelogFile>
2222
</PropertyGroup>
2323

24-
<ItemGroup>
24+
<ItemGroup Condition="'$(IsCPM)' != 'true'">
2525
<PackageReference Include="MinVer" Version="$(MinVerPkgVer)" PrivateAssets="All" Condition="'$(IntegrationBuild)' != 'true'" />
2626
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGitHubPkgVer)" PrivateAssets="All" Condition="'$(IntegrationBuild)' != 'true'" />
2727
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftPublicApiAnalyzersPkgVer)" PrivateAssets="All" Condition="'$(EnablePublicApi)' != 'false'" />

0 commit comments

Comments
 (0)