Build, pack, and publish #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, pack, and publish | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- 'Exporter.*-*' | |
- 'Extensions.*-*' | |
- 'Extensions-*' | |
- 'Instrumentation.*-*' | |
- 'PersistentStorage-*' | |
- 'ResourceDetectors.*-*' | |
- 'Resources.*-*' | |
- 'Sampler.*-*' | |
- 'SemanticConventions-*' | |
workflow_call: | |
inputs: | |
tag: | |
required: true | |
type: string | |
outputs: | |
artifact-id: | |
value: ${{ jobs.build-pack-publish.outputs.artifact-id }} | |
artifact-url: | |
value: ${{ jobs.build-pack-publish.outputs.artifact-url }} | |
schedule: | |
- cron: '0 0 * * *' # once in a day at 00:00 | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
build-pack-publish: | |
runs-on: windows-latest | |
outputs: | |
artifact-id: ${{ steps.upload-artifacts.outputs.artifact-id }} | |
artifact-url: ${{ steps.upload-artifacts.outputs.artifact-url }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Note: By default GitHub only fetches 1 commit. MinVer needs to find | |
# the version tag which is typically NOT on the first commit so we | |
# retrieve them all. | |
fetch-depth: 0 | |
ref: ${{ inputs.tag || github.ref || 'main' }} | |
- name: Resolve project | |
id: resolve-project | |
shell: pwsh | |
run: | | |
Import-Module .\build\scripts\build.psm1 | |
ResolveProjectForTag ` | |
-tag '${{ github.ref_type == 'tag' && github.ref_name || inputs.tag || '' }}' | |
- name: Setup dotnet | |
uses: actions/setup-dotnet@v4 | |
- name: dotnet restore ${{ steps.resolve-project.outputs.title }} | |
run: dotnet restore ${{ steps.resolve-project.outputs.project }} | |
- name: dotnet build ${{ steps.resolve-project.outputs.title }} | |
run: dotnet build ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} | |
- name: dotnet test ${{ steps.resolve-project.outputs.title }} | |
run: dotnet test ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore --no-build | |
- name: dotnet pack ${{ steps.resolve-project.outputs.title }} | |
run: dotnet pack ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore --no-build -p:PackTag=${{ github.ref_type == 'tag' && github.ref_name || inputs.tag || '' }} | |
- name: Publish Artifacts | |
id: upload-artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ inputs.tag || github.ref_name }}-packages | |
path: 'src\**\*.*nupkg' | |
- name: Publish MyGet | |
env: | |
MYGET_TOKEN_EXISTS: ${{ secrets.MYGET_TOKEN != '' }} | |
if: env.MYGET_TOKEN_EXISTS == 'true' # Skip MyGet publish if run on a fork without the secret | |
run: | | |
nuget setApiKey ${{ secrets.MYGET_TOKEN }} -Source https://www.myget.org/F/opentelemetry/api/v2/package | |
nuget push src\**\*.nupkg -Source https://www.myget.org/F/opentelemetry/api/v2/package | |
- name: Publish NuGets | |
env: | |
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN != '' }} | |
if: (github.ref_type == 'tag' || inputs.tag) && env.NUGET_TOKEN_EXISTS == 'true' # Skip NuGet publish for scheduled nightly builds or if run on a fork without the secret | |
run: | | |
nuget push src\**\*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }} | |
- name: Create GitHub Release | |
if: github.ref_type == 'tag' || inputs.tag | |
shell: pwsh | |
run: | | |
Import-Module .\build\scripts\post-release.psm1 | |
CreateRelease ` | |
-tag '${{ inputs.tag || github.ref_name }}' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Create GitHub Pull Request to update PackageValidationBaselineVersion in projects | |
if: | | |
(github.ref_type == 'tag' && !contains(github.ref_name, '-alpha') && !contains(github.ref_name, '-beta') && !contains(github.ref_name, '-rc')) | |
|| (inputs.tag && !contains(inputs.tag, '-alpha') && !contains(inputs.tag, '-beta') && !contains(inputs.tag, '-rc')) | |
shell: pwsh | |
run: | | |
Import-Module .\build\scripts\post-release.psm1 | |
CreatePackageValidationBaselineVersionUpdatePullRequest ` | |
-tag '${{ inputs.tag || github.ref_name }}' | |
env: | |
GH_TOKEN: ${{ github.token }} |