Switch from Azure Pipelines to GitHub Actions #16
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- main | |
- 'v*.*' | |
- validate/* | |
pull_request: | |
workflow_dispatch: | |
env: | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
BUILDCONFIGURATION: Release | |
# codecov_token: 4dc9e7e2-6b01-4932-a180-847b52b43d35 # Get a new one from https://codecov.io/ | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages/ | |
# dotnetfoundation code signing | |
jobs: | |
build: | |
name: 🏭 Build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-22.04 | |
- windows-2022 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
submodules: true | |
- name: ⚙ Install prerequisites | |
run: | | |
./init.ps1 -UpgradePrerequisites | |
dotnet --info | |
# Print mono version if it is present. | |
if (Get-Command mono -ErrorAction SilentlyContinue) { | |
mono --version | |
} | |
shell: pwsh | |
- name: ⚙ Install 32-bit .NET SDK and runtimes | |
shell: pwsh | |
run: | | |
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1 | |
& .\dotnet-install.ps1 -Architecture x86 -Version 9.0.101 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose | |
if: runner.os == 'Windows' | |
- name: ⚙️ Set pipeline variables based on source | |
run: tools/variables/_define.ps1 | |
shell: pwsh | |
- name: 🛠 build | |
run: dotnet build -t:build,pack --no-restore -c ${{ env.BUILDCONFIGURATION }} -warnAsError -warnNotAsError:NU1901,NU1902,NU1903,NU1904 /bl:"${{ runner.temp }}/_artifacts/build_logs/build.binlog" | |
- name: 🛠️ Build LKG package | |
run: dotnet pack -c ${{ env.BUILDCONFIGURATION }} --no-build -p:PackLKG=true /bl:"${{ runner.temp }}/_artifacts/build_logs/msbuild_lkg.binlog" | |
working-directory: src/Nerdbank.GitVersioning.Tasks | |
- name: 📢 Publish nbgv tool | |
run: dotnet publish -c ${{ env.BUILDCONFIGURATION }} -o ../nerdbank-gitversioning.npm/out/nbgv.cli/tools/net8.0/any /bl:"${{ runner.temp }}/_artifacts/build_logs/nbgv_publish.binlog" | |
working-directory: src/nbgv | |
- name: 🛠️ Build nerdbank-gitversioning NPM package | |
run: yarn build | |
working-directory: src/nerdbank-gitversioning.npm | |
- name: Capture .git directory | |
shell: pwsh | |
run: | | |
md ${{ runner.temp }}\_artifacts\drop | |
7z a ${{ runner.temp }}\_artifacts\drop\nbgv.7z * -r | |
Write-Host "##vso[artifact.upload containerfolder=drop;artifactname=drop;]${{ runner.temp }}\_artifacts\drop" | |
if: failure() && runner.os == 'Windows' | |
- name: 🧪 test | |
run: | | |
Write-Host "⚙️ Configure git commit author for testing" | |
git config --global user.name ci | |
git config --global user.email [email protected] | |
Write-Host "🧪 Run tests" | |
tools/dotnet-test-cloud.ps1 -Configuration ${{ env.BUILDCONFIGURATION }} -Agent ${{ runner.os }} -PublishResults | |
shell: pwsh | |
- name: 🧪 test x86 | |
run: tools/dotnet-test-cloud.ps1 -Configuration ${{ env.BUILDCONFIGURATION }} -Agent ${{ runner.os }} -PublishResults -X86 | |
if: success() && runner.os == 'Windows' | |
- name: 💅🏻 Verify formatted code | |
run: dotnet format --verify-no-changes --no-restore | |
shell: pwsh | |
if: runner.os == 'Linux' | |
- name: 📚 Verify docfx build | |
run: dotnet docfx docfx/docfx.json --warningsAsErrors --disableGitFeatures | |
if: runner.os == 'Linux' | |
- name: ⚙ Update pipeline variables based on build outputs | |
run: tools/variables/_define.ps1 | |
shell: pwsh | |
- name: 📢 Publish artifacts | |
uses: ./.github/actions/publish-artifacts | |
if: cancelled() == false | |
- name: 📦 Push CI package | |
shell: pwsh | |
run: | | |
if ('${{ secrets.AZP_TOKEN }}') { | |
dotnet nuget add source https://pkgs.dev.azure.com/andrewarnott/OSS/_packaging/PublicCI/nuget/v3/index.json -n publicCI -u andrewarnott -p ${{ secrets.AZP_TOKEN }} --store-password-in-clear-text | |
dotnet nuget push ${{ runner.temp }}/_artifacts/deployables/*.nupkg -s publicCI -k x | |
dotnet nuget push ${{ runner.temp }}/_artifacts/deployables-LKG/*.nupkg -s publicCI -k x | |
} | |
if: success() && runner.os == 'Linux' && github.event_name != 'pull_request' | |
continue-on-error: true | |
- name: 📢 Publish code coverage results to codecov.io | |
run: ./tools/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }}" | |
shell: pwsh | |
timeout-minutes: 3 | |
continue-on-error: true | |
if: env.codecov_token != '' | |
functional_testing: | |
name: 🧪 Functional testing | |
needs: build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: ubuntu-22.04 | |
container: mcr.microsoft.com/dotnet/sdk:8.0-jammy | |
- os: ubuntu-22.04 | |
container: mcr.microsoft.com/dotnet/sdk:9.0-noble | |
- os: ubuntu-22.04 | |
container: mcr.microsoft.com/dotnet/sdk:8.0 | |
- os: ubuntu-22.04 | |
container: mcr.microsoft.com/dotnet/sdk:9.0 | |
- os: macos-14 | |
container: "" | |
# This uses a matrix value for the container; macOS will have an empty string, which means no container. | |
container: | |
image: ${{ matrix.container }} | |
# GitHub Actions will ignore an empty image automatically. | |
steps: | |
- name: Show .NET SDK info | |
shell: pwsh | |
run: dotnet --info | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: deployables-Windows | |
path: deployables | |
- name: Set up git username and email address | |
shell: pwsh | |
run: | | |
git config --global init.defaultBranch main | |
git config --global user.name ci | |
git config --global user.email [email protected] | |
- name: Consume NB.GV from .NET build | |
shell: bash | |
run: > | |
PkgFileName=$(ls deployables/Nerdbank.GitVersioning.*nupkg) | |
NBGV_NuGetPackageVersion=$([[ $PkgFileName =~ Nerdbank.GitVersioning\.(.*)\.nupkg ]] && echo "${BASH_REMATCH[1]}") | |
echo "<configuration><packageSources><add key='local' value='deployables' /></packageSources></configuration>" > nuget.config && | |
dotnet new classlib -o lib && | |
cd lib && | |
echo '{"version":"42.42"}' > version.json && | |
git init && | |
git add version.json && | |
git commit -m "Initial commit" && | |
mkdir lib && cd lib && | |
for l in c# f# vb; | |
do | |
echo Testing language $l && | |
dotnet new classlib -lang=$l && | |
dotnet add package nerdbank.gitversioning -v $NBGV_NuGetPackageVersion && | |
dotnet pack -c debug /p:TreatWarningsAsErrors=false && | |
ls bin/debug/lib.42.42.1*.nupkg 1> /dev/null 2>&1 && | |
rm -r * | |
if [ $? -ne 0 ]; then exit 1; fi | |
done | |
- name: Consume Cake.GitVersioning | |
shell: bash | |
run: > | |
PkgFileName=$(ls deployables/Cake.GitVersioning.*nupkg) | |
NBGV_NuGetPackageVersion=$([[ $PkgFileName =~ Cake.GitVersioning\.(.*)\.nupkg ]] && echo "${BASH_REMATCH[1]}") | |
echo $NBGV_NuGetPackageVersion | |
mkdir caketest && | |
cd caketest && | |
git init && | |
dotnet new tool-manifest && | |
dotnet tool install Cake.Tool | |
echo "#addin nuget:?package=Cake.GitVersioning&version=${NBGV_NuGetPackageVersion}&prerelease=true" | |
echo "#addin nuget:?package=Cake.GitVersioning&version=${NBGV_NuGetPackageVersion}&prerelease=true" > build.cake | |
echo "Information(GitVersioningGetVersion().Version.ToString());" >> build.cake | |
dotnet cake | |
- name: Use nbgv dotnet CLI tool | |
shell: bash | |
run: > | |
echo DOTNET_ROOT=$DOTNET_ROOT | |
PkgFileName=$(ls deployables/Nerdbank.GitVersioning.*nupkg) | |
NBGV_NuGetPackageVersion=$([[ $PkgFileName =~ Nerdbank.GitVersioning\.(.*)\.nupkg ]] && echo "${BASH_REMATCH[1]}") | |
dotnet tool install nbgv --tool-path . --version $NBGV_NuGetPackageVersion --add-source deployables-Windows && | |
./nbgv get-version -f json -p lib && | |
./nbgv get-version -f json -p lib | grep 42.42.1 | |
perf_testing: | |
name: 🫏 Performance testing | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: ubuntu-22.04 | |
repoDir: '~/git' | |
- os: windows-2022 | |
repoDir: '${USERPROFILE}/source/repos' | |
- os: macos-14 | |
repoDir: '~/git' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # avoid shallow clone so nbgv can do its work. | |
submodules: true | |
- name: Install .NET SDK | |
uses: actions/setup-dotnet@v2 | |
with: | |
global-json-file: global.json | |
- name: Show .NET SDK info | |
run: dotnet --info | |
- name: Clone test repos | |
shell: bash | |
run: | | |
mkdir -p ${{ matrix.repoDir }} | |
git clone https://github.com/xunit/xunit ${{ matrix.repoDir }}/xunit | |
git clone https://github.com/gimlichael/Cuemon ${{ matrix.repoDir }}/Cuemon | |
git clone https://github.com/kerryjiang/SuperSocket ${{ matrix.repoDir }}/SuperSocket | |
git clone https://github.com/dotnet/Nerdbank.GitVersioning ${{ matrix.repoDir }}/Nerdbank.GitVersioning | |
- name: Build in Release mode | |
run: dotnet build -c Release | |
working-directory: test/Nerdbank.GitVersioning.Benchmarks | |
- name: Run benchmarks (packed) | |
run: dotnet run -c Release -f net9.0 --no-build -- --filter '*GetVersionBenchmarks*' --artifacts ${{ runner.temp }}/_artifacts//benchmarks/packed/${{ matrix.os }} | |
working-directory: test/Nerdbank.GitVersioning.Benchmarks | |
- name: Unpack Git repositories | |
shell: bash | |
run: | | |
cd ${{ matrix.repoDir }}/xunit | |
git unpack-objects < .git/objects/pack/*.pack | |
cd ${{ matrix.repoDir }}/Cuemon | |
git unpack-objects < .git/objects/pack/*.pack | |
cd ${{ matrix.repoDir }}/SuperSocket | |
git unpack-objects < .git/objects/pack/*.pack | |
cd ${{ matrix.repoDir }}/Nerdbank.GitVersioning | |
git unpack-objects < .git/objects/pack/*.pack | |
- name: Run benchmarks (unpacked) | |
run: dotnet run -c Release -f net9.0 --no-build -- --filter '*GetVersionBenchmarks*' --artifacts ${{ runner.temp }}/_artifacts//benchmarks/unpacked/${{ matrix.os }} | |
working-directory: test/Nerdbank.GitVersioning.Benchmarks | |
- name: Publish benchmarks artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: benchmarks-${{ matrix.os }} | |
path: ${{ runner.temp }}/_artifacts/benchmarks |