Build, pack, and publish #53
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-*' | |
- 'Resources.*-*' | |
- 'Sampler.*-*' | |
- 'SemanticConventions-*' | |
schedule: | |
- cron: '0 0 * * *' # once in a day at 00:00 | |
jobs: | |
automation: | |
uses: ./.github/workflows/automation.yml | |
secrets: inherit | |
build-pack-publish: | |
runs-on: windows-latest | |
outputs: | |
artifact-url: ${{ steps.upload-artifacts.outputs.artifact-url }} | |
artifact-id: ${{ steps.upload-artifacts.outputs.artifact-id }} | |
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 | |
- name: Resolve project | |
id: resolve-project | |
shell: pwsh | |
run: | | |
Import-Module .\build\scripts\build.psm1 | |
# Note: The ResolveProjectForTag call here figures out the .proj file to | |
# use for the build. It will be either opentelemetry-dotnet-contrib.proj | |
# (for manual/scheduled builds), a .proj file in .\build\Projects\ (if | |
# one is defined with MinVerTagPrefix matching the tag), or | |
# Component.proj for simple projects (where a single csproj has | |
# MinVerTagPrefix matching the tag). | |
$title = '' # Used for friendly names in action UI | |
$project = '' # Actual project passed to dotnet | |
$component = '' # Used to tell Component.proj what to build | |
ResolveProjectForTag ` | |
-tag '${{ github.ref_type == 'tag' && github.ref_name || '' }}' ` | |
-title ([ref]$title) ` | |
-project ([ref]$project) ` | |
-component ([ref]$component) | |
echo "title=$title" >> $env:GITHUB_OUTPUT | |
echo "project=$project" >> $env:GITHUB_OUTPUT | |
# Note: BUILD_COMPONENT envvar tells Component.proj what to build. Only | |
# used if $project ends up Component.proj. | |
echo "BUILD_COMPONENT=$component" >> $env:GITHUB_ENV | |
- 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 || '' }} | |
- name: Publish Artifacts | |
id: upload-artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ 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' && 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 }} | |
post-build: | |
runs-on: ubuntu-latest | |
needs: | |
- automation | |
- build-pack-publish | |
if: needs.automation.outputs.enabled && github.event_name == 'push' | |
env: | |
GH_TOKEN: ${{ secrets[needs.automation.outputs.token-secret-name] }} | |
steps: | |
- name: check out code | |
uses: actions/checkout@v4 | |
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 | |
run: | | |
Import-Module .\build\scripts\post-release.psm1 | |
CreateRelease ` | |
-gitRepository '${{ github.repository }}' ` | |
-tag '${{ github.ref_name }}' ` | |
-releaseFiles '${{ github.workspace }}/artifacts/${{ github.ref_name }}-packages.zip#Packages' | |
- name: Post notice when packages are ready | |
shell: pwsh | |
run: | | |
Import-Module .\build\scripts\post-release.psm1 | |
TryPostPackagesReadyNoticeOnPrepareReleasePullRequest ` | |
-gitRepository '${{ github.repository }}' ` | |
-tag '${{ github.ref_name }}' ` | |
-tagSha '${{ github.sha }}' ` | |
-packagesUrl '${{ needs.build-pack-publish.outputs.artifact-url }}' ` | |
-botUserName '${{ needs.automation.outputs.username }}' |