Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Azure Pipelines to GitHub Actions #1141

Merged
merged 24 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
6 changes: 6 additions & 0 deletions .github/actions/publish-artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ runs:
name: deployables-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/deployables
if: always()
- name: 📢 Upload deployables-LKG
uses: actions/upload-artifact@v4
with:
name: deployables-LKG-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/deployables-LKG
if: always()
File renamed without changes.
290 changes: 290 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
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 me@ci.com

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 == 'Windows' && 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 me@ci.com

- 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
28 changes: 27 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
release:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: ⚙️ Initialization
shell: pwsh
run: |
Expand Down Expand Up @@ -67,11 +69,26 @@ jobs:
- name: 🔻 Download deployables artifacts
uses: actions/download-artifact@v4
with:
name: deployables-Linux
name: deployables-Windows
path: ${{ runner.temp }}/deployables
run-id: ${{ steps.findrunid.outputs.runid }}
github-token: ${{ github.token }}

- name: 🔏 Code sign
shell: pwsh
run: >
dotnet tool install --tool-path obj SignClient

obj/SignClient sign
--baseDirectory '${{ runner.temp }}/deployables'
--input '**/*'
--config '${{ github.workspace }}/.github/SignClient.json'
--filelist '${{ github.workspace }}/.github/signfiles.txt'
--user '${{ secrets.CODESIGN_USERNAME }}'
--secret '${{ secrets.CODESIGN_SECRET }}'
--name 'Nerdbank.GitVersioning'
--descriptionUrl 'https://github.com/dotnet/Nerdbank.GitVersioning'

- name: 💽 Upload artifacts to release
shell: pwsh
if: ${{ github.event.release.assets_url }} != ''
Expand All @@ -86,3 +103,12 @@ jobs:
- name: 🚀 Push NuGet packages
run: dotnet nuget push ${{ runner.temp }}/deployables/*.nupkg --source https://api.nuget.org/v3/index.json -k '${{ secrets.NUGET_API_KEY }}'
if: ${{ env.NUGET_API_KEY_DEFINED == 'true' }}

- name: 🚀 Push NPM packages
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_API_KEY }}
Get-ChildItem '${{ runner.temp }}/deployables/*.tgz' |% {
npm publish $_ --registry=https://registry.npmjs.org/
}
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nerdbank.GitVersioning

[![Build Status](https://dev.azure.com/andrewarnott/OSS/_apis/build/status/Nerdbank.GitVersioning)](https://dev.azure.com/andrewarnott/OSS/_build/latest?definitionId=18)
[![🏭 Build](https://github.com/dotnet/Nerdbank.GitVersioning/actions/workflows/build.yml/badge.svg)](https://github.com/dotnet/Nerdbank.GitVersioning/actions/workflows/build.yml)
[![NuGet package](https://img.shields.io/nuget/v/Nerdbank.GitVersioning.svg)](https://nuget.org/packages/Nerdbank.GitVersioning)
[![NuGet downloads](https://img.shields.io/nuget/dt/Nerdbank.GitVersioning.svg)](https://nuget.org/packages/Nerdbank.GitVersioning)
[![NPM package](https://img.shields.io/npm/v/nerdbank-gitversioning.svg)](https://www.npmjs.com/package/nerdbank-gitversioning)
Expand Down
Loading