diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..65feb6c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +# Pull request validation: builds Release for every target framework. Publishes nothing. +# There is no unit test project; WpfSample is a manual sample and is built with the solution. +name: CI + +on: + pull_request: + branches: [master, development] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '10.x' + + - name: Restore workloads + run: dotnet workload restore DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj + + - name: Restore + run: dotnet restore DSoft.System.BluetoothLe.slnx + + - name: Build + run: dotnet build DSoft.System.BluetoothLe.slnx --configuration Release --no-restore diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c497498 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,101 @@ +# Release: on every push to master, builds Release and pushes the DSoft.*.nupkg +# package (with its .snupkg symbols) to nuget.org as 4.0.yyMM., then +# tags the commit and creates a GitHub release with the package attached. +# RELEASE_SUFFIX is empty for a stable version; set it to a suffix such as +# '-prerelease' to publish a prerelease. +# Signs in to nuget.org with Trusted Publishing (OIDC), so no API key is stored. +name: Release + +on: + push: + branches: [master] + paths-ignore: + - '**.md' + - '.github/workflows/**' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release + cancel-in-progress: false + +env: + RELEASE_SUFFIX: '' + +jobs: + release: + runs-on: windows-latest + environment: nuget + permissions: + contents: write # GitHub release and tag + id-token: write # Trusted Publishing + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '10.x' + + - name: Version + id: version + shell: bash + run: | + version="4.0.$(date -u +%y%m).${{ github.run_number }}" + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "package=$version$RELEASE_SUFFIX" >> "$GITHUB_OUTPUT" + echo "Version: $version$RELEASE_SUFFIX" + + - name: Restore workloads + run: dotnet workload restore DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj + + - name: Restore + run: dotnet restore DSoft.System.BluetoothLe.slnx + + # AssemblyVersion is deliberately not overridden. It is pinned in the csproj, because a strong-named + # assembly whose identity moves on every CI build forces consumers on net481 to carry a binding + # redirect. FileVersion still carries the build number, which is what a support engineer reads off + # a shipped file. + - name: Build + run: > + dotnet build DSoft.System.BluetoothLe.slnx --configuration Release --no-restore + /p:Version=${{ steps.version.outputs.package }} + /p:FileVersion=${{ steps.version.outputs.version }} + + - name: Collect packages + shell: bash + run: | + mkdir -p artifacts + find DSoft.System.BluetoothLe -path '*/bin/Release/*' \( -name 'DSoft.*.nupkg' -o -name 'DSoft.*.snupkg' \) -exec cp {} artifacts/ \; + ls artifacts + + - uses: actions/upload-artifact@v7 + with: + name: drop + path: artifacts/* + + - name: NuGet login + id: nuget + uses: NuGet/login@v1 + with: + user: ${{ secrets.NUGET_USER }} + + # The .snupkg next to each .nupkg is pushed with it. + - name: Push to nuget.org + shell: bash + run: | + for package in artifacts/*.nupkg; do + dotnet nuget push "$package" --api-key "${{ steps.nuget.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate + done + + - name: GitHub release + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "v${{ steps.version.outputs.package }}" artifacts/*.nupkg \ + --target "${{ github.sha }}" \ + --title "${{ steps.version.outputs.package }}" \ + --generate-notes \ + ${RELEASE_SUFFIX:+--prerelease} diff --git a/DSoft.System.BluetoothLe.slnx b/DSoft.System.BluetoothLe.slnx index 4143f79..5ba5d22 100644 --- a/DSoft.System.BluetoothLe.slnx +++ b/DSoft.System.BluetoothLe.slnx @@ -13,8 +13,8 @@ - - + + diff --git a/DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj b/DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj index 5f7b45e..aae1ef9 100644 --- a/DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj +++ b/DSoft.System.BluetoothLe/DSoft.System.BluetoothLe.csproj @@ -125,7 +125,7 @@ true true snupkg - true + true diff --git a/README.md b/README.md index 7facadd..bdbe61c 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,13 @@ dotnet build DSoft.System.BluetoothLe.slnx --no-restore `net10.0-windows10.0.19041.0` and `net481` are only built when the host is Windows; on macOS and Linux the remaining seven target frameworks build and the two Windows ones are skipped. +### Continuous integration + +GitHub Actions (`.github/workflows/`): + +- `ci.yml`: runs on pull requests to `master` and `development`. Builds Release for every target framework. Publishes nothing. +- `release.yml`: runs on every push to `master` (changes only to Markdown or workflow files are skipped; run it by hand to test a workflow change). Builds Release as `4.0.yyMM.` plus `RELEASE_SUFFIX` (empty for a stable version; set it to `-prerelease` in the workflow to publish a prerelease), uploads the package as the `drop` artifact and pushes it to nuget.org with Trusted Publishing (OIDC, `NUGET_USER` secret, `nuget` environment), then tags the commit `v` and creates a GitHub release with the package attached. `AssemblyVersion` is not stamped by CI: it stays pinned in the project file (see "Strong naming"). + ### Strong naming The assembly is strong-named with `DSoft.snk`, which is committed to this repository on purpose. A strong diff --git a/azure-pipelines-mergetest.yml b/azure-pipelines-mergetest.yml deleted file mode 100644 index bc56863..0000000 --- a/azure-pipelines-mergetest.yml +++ /dev/null @@ -1,54 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -trigger: none - -pool: - vmImage: 'windows-latest' - -variables: -- name: solution - value: '**/*.slnx' -- name: buildPlatform - value: 'Any CPU' -- name: buildConfiguration - value: 'Release' -- name: NUGET.PLUGIN.HANDSHAKE.TIMEOUT.IN.SECONDS - value: 60 -- name: NUGET.PLUGIN.REQUEST.TIMEOUT.IN.SECONDS - value: 60 -- name: netVersion - value: '10.x' - -steps: - -- task: NuGetToolInstaller@1 - displayName: Install Latest Nuget - -- task: UseDotNet@2 - displayName: 'Install .NET sdk' - inputs: - packageType: 'sdk' - version: $(netVersion) - -- task: Bash@3 - displayName: Restore Workloads - inputs: - targetType: 'inline' - script: - dotnet workload restore - -- task: DotNetCoreCLI@2 - displayName: dotnet restore - inputs: - command: 'restore' - projects: '$(solution)' - -- task: DotNetCoreCLI@2 - displayName: dotnet build - inputs: - projects: '$(solution)' - arguments: '--configuration=$(buildConfiguration) /p:Platform="$(buildPlatform)"' - diff --git a/azure-pipelines-release.yml b/azure-pipelines-release.yml deleted file mode 100644 index 85b6525..0000000 --- a/azure-pipelines-release.yml +++ /dev/null @@ -1,80 +0,0 @@ -# .NET Desktop -# Build and run tests for .NET Desktop or Windows classic desktop solutions. -# Add steps that publish symbols, save build artifacts, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net - -trigger: - batch: true - branches: - include: - - master -pool: - vmImage: 'windows-latest' - -variables: -- name: solution - value: '**/*.slnx' -- name: buildPlatform - value: 'Any CPU' -- name: buildConfiguration - value: 'Release' -- name: NUGET.PLUGIN.HANDSHAKE.TIMEOUT.IN.SECONDS - value: 60 -- name: NUGET.PLUGIN.REQUEST.TIMEOUT.IN.SECONDS - value: 60 -- name: netVersion - value: '10.x' -- name: releaseSuffix - value: '' - -name: 4.0.$(date:yyMM).$(date:dd)$(rev:r) -steps: - -- task: NuGetToolInstaller@1 - displayName: Install Latest Nuget - -- task: UseDotNet@2 - displayName: 'Install .NET sdk' - inputs: - packageType: 'sdk' - version: $(netVersion) - -- task: Bash@3 - displayName: Restore Workloads - inputs: - targetType: 'inline' - script: - dotnet workload restore - -- task: DotNetCoreCLI@2 - displayName: dotnet restore - inputs: - command: 'restore' - projects: '$(solution)' - -- task: DotNetCoreCLI@2 - displayName: dotnet build - inputs: - command: 'build' - projects: '$(solution)' - # AssemblyVersion is deliberately not overridden here. It is pinned in the csproj, because a strong-named - # assembly whose identity moves on every CI build forces consumers on net481 to carry a binding redirect. - # FileVersion still carries the build number, which is what a support engineer reads off a shipped file. - arguments: '--configuration $(buildConfiguration) --no-restore /p:Platform="$(buildPlatform)" /p:Version=$(Build.BuildNumber)$(ReleaseSuffix) /p:FileVersion=$(Build.BuildNumber)' - -- task: CopyFiles@2 - displayName: Copy Files to $(build.artifactstagingdirectory) - inputs: - SourceFolder: '$(system.defaultworkingdirectory)' - Contents: | - **/DSoft.*.nupkg - **/DSoft.*.snupkg - TargetFolder: '$(build.artifactstagingdirectory)' - flattenFolders: true - -- task: PublishBuildArtifacts@1 - displayName: Publish Artifacts drop - inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' - ArtifactName: 'drop' - publishLocation: 'Container'