Skip to content

Commit

Permalink
Merge pull request #57 from AArnott/dev/andarno/libtemplateUpdate
Browse files Browse the repository at this point in the history
Merge latest Library.Template
  • Loading branch information
AArnott authored Dec 16, 2024
2 parents c4cdeb5 + e69734e commit 4c6dfcd
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"rollForward": false
},
"nbgv": {
"version": "3.6.146",
"version": "3.7.112",
"commands": [
"nbgv"
],
Expand Down
67 changes: 67 additions & 0 deletions .github/actions/publish-artifacts/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Publish artifacts
description: Publish artifacts

runs:
using: composite
steps:
- name: 📥 Collect artifacts
run: azure-pipelines/artifacts/_stage_all.ps1
shell: pwsh
if: always()

# TODO: replace this hard-coded list with a loop that utilizes the NPM package at
# https://github.com/actions/toolkit/tree/main/packages/artifact (or similar) to push the artifacts.

- name: 📢 Upload project.assets.json files
if: always()
uses: actions/upload-artifact@v4
with:
name: projectAssetsJson-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/projectAssetsJson
continue-on-error: true
- name: 📢 Upload variables
uses: actions/upload-artifact@v4
with:
name: variables-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/Variables
continue-on-error: true
- name: 📢 Upload build_logs
if: always()
uses: actions/upload-artifact@v4
with:
name: build_logs-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/build_logs
continue-on-error: true
- name: 📢 Upload test_logs
if: always()
uses: actions/upload-artifact@v4
with:
name: test_logs-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/test_logs
continue-on-error: true
- name: 📢 Upload testResults
if: always()
uses: actions/upload-artifact@v4
with:
name: testResults-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/testResults
continue-on-error: true
- name: 📢 Upload coverageResults
if: always()
uses: actions/upload-artifact@v4
with:
name: coverageResults-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/coverageResults
continue-on-error: true
- name: 📢 Upload symbols
uses: actions/upload-artifact@v4
with:
name: symbols-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/symbols
continue-on-error: true
- name: 📢 Upload deployables
uses: actions/upload-artifact@v4
with:
name: deployables-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/deployables
if: always()
62 changes: 5 additions & 57 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: 🏭 Build

on:
push:
Expand All @@ -8,6 +8,7 @@ on:
tags:
- v*.*
pull_request:
workflow_dispatch:

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
Expand All @@ -17,6 +18,7 @@ env:

jobs:
build:
name: 🏭 Build

runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -59,62 +61,8 @@ jobs:
- name: ⚙ Update pipeline variables based on build outputs
run: azure-pipelines/variables/_pipelines.ps1
shell: pwsh
- name: 📥 Collect artifacts
run: azure-pipelines/artifacts/_stage_all.ps1
shell: pwsh
if: always()
- name: 📢 Upload project.assets.json files
if: always()
uses: actions/upload-artifact@v4
with:
name: projectAssetsJson-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/projectAssetsJson
continue-on-error: true
- name: 📢 Upload variables
uses: actions/upload-artifact@v4
with:
name: variables-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/Variables
continue-on-error: true
- name: 📢 Upload build_logs
if: always()
uses: actions/upload-artifact@v4
with:
name: build_logs-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/build_logs
continue-on-error: true
- name: 📢 Upload test_logs
if: always()
uses: actions/upload-artifact@v4
with:
name: test_logs-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/test_logs
continue-on-error: true
- name: 📢 Upload testResults
if: always()
uses: actions/upload-artifact@v4
with:
name: testResults-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/testResults
continue-on-error: true
- name: 📢 Upload coverageResults
if: always()
uses: actions/upload-artifact@v4
with:
name: coverageResults-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/coverageResults
continue-on-error: true
- name: 📢 Upload symbols
uses: actions/upload-artifact@v4
with:
name: symbols-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/symbols
continue-on-error: true
- name: 📢 Upload deployables
uses: actions/upload-artifact@v4
with:
name: deployables-${{ runner.os }}
path: ${{ runner.temp }}/_artifacts/deployables
- name: 📢 Publish artifacts
uses: ./.github/actions/publish-artifacts
if: always()
- name: 📢 Publish code coverage results to codecov.io
run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
actions: read
pages: write
id-token: write
contents: read

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/libtemplate-update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Library.Template update
name: Library.Template update

# PREREQUISITE: This workflow requires the repo to be configured to allow workflows to create pull requests.
# Visit https://github.com/USER/REPO/settings/actions
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: 🎁 Release

on:
release:
types: [published]
workflow_dispatch:
inputs:
ship_run_id:
description: ID of the GitHub workflow run to ship
required: true

run-name: ${{ github.ref_name }}

permissions:
actions: read
contents: write

jobs:
release:
runs-on: ubuntu-22.04
steps:
- name: ⚙️ Initialization
shell: pwsh
run: |
if ('${{ secrets.NUGET_API_KEY }}') {
Write-Host "NUGET_API_KEY secret detected. NuGet packages will be pushed."
echo "NUGET_API_KEY_DEFINED=true" >> $env:GITHUB_ENV
}
- name: 🔎 Search for build of ${{ github.ref }}
shell: pwsh
id: findrunid
env:
GH_TOKEN: ${{ github.token }}
run: |
if ('${{ inputs.ship_run_id }}') {
$runid = '${{ inputs.ship_run_id }}'
} else {
$restApiRoot = '/repos/${{ github.repository }}'
# Resolve the tag reference to a commit sha
$resolvedRef = gh api `
-H "Accept: application/vnd.github+json" `
-H "X-GitHub-Api-Version: 2022-11-28" `
$restApiRoot/git/ref/tags/${{ github.ref_name }} `
| ConvertFrom-Json
$commitSha = $resolvedRef.object.sha
Write-Host "Resolved ${{ github.ref_name }} to $commitSha"
$releases = gh run list -R ${{ github.repository }} -c $commitSha -w .github/workflows/build.yml -s success --json databaseId,startedAt `
| ConvertFrom-Json | Sort-Object startedAt -Descending
if ($releases.length -eq 0) {
Write-Error "No successful builds found for ${{ github.ref }}."
} elseif ($releases.length -gt 1) {
Write-Warning "More than one successful run found for ${{ github.ref }}. Artifacts from the most recent successful run will ship."
}
$runid = $releases[0].databaseId
}
Write-Host "Using artifacts from run-id: $runid"
Echo "runid=$runid" >> $env:GITHUB_OUTPUT
- name: 🔻 Download deployables artifacts
uses: actions/download-artifact@v4
with:
name: deployables-Linux
path: ${{ runner.temp }}/deployables
run-id: ${{ steps.findrunid.outputs.runid }}
github-token: ${{ github.token }}

- name: 💽 Upload artifacts to release
shell: pwsh
if: ${{ github.event.release.assets_url }} != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
Get-ChildItem '${{ runner.temp }}/deployables' |% {
Write-Host "Uploading $($_.Name) to release..."
gh release -R ${{ github.repository }} upload "${{ github.ref_name }}" $_.FullName
}
- 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' }}
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ Building, testing, and packing this repository can be done by using the standard

[pwsh]: https://docs.microsoft.com/powershell/scripting/install/installing-powershell?view=powershell-6

## Releases

Use `nbgv tag` to create a tag for a particular commit that you mean to release.
[Learn more about `nbgv` and its `tag` and `prepare-release` commands](https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/doc/nbgv-cli.md).

Push the tag.

### GitHub Actions

When your repo is hosted by GitHub and you are using GitHub Actions, you should create a GitHub Release using the standard GitHub UI.
Having previously used `nbgv tag` and pushing the tag will help you identify the precise commit and name to use for this release.

After publishing the release, the `.github\workflows\release.yml` workflow will be automatically triggered, which will:

1. Find the most recent `.github\workflows\build.yml` GitHub workflow run of the tagged release.
1. Upload the `deployables` artifact from that workflow run to your GitHub Release.
1. If you have `NUGET_API_KEY` defined as a secret variable for your repo or org, any nuget packages in the `deployables` artifact will be pushed to nuget.org.

### Azure Pipelines

When your repo builds with Azure Pipelines, use the `azure-pipelines/release.yml` pipeline.
Trigger the pipeline by adding the `auto-release` tag on a run of your main `azure-pipelines.yml` pipeline.

## Tutorial and API documentation

API and hand-written docs are found under the `docfx/` directory. and are built by [docfx](https://dotnet.github.io/docfx/).
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<GlobalPackageReference Include="CSharpIsNullAnalyzer" Version="0.1.593" />
<GlobalPackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" />
<!-- The condition works around https://github.com/dotnet/sdk/issues/44951 -->
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.146" Condition="!('$(TF_BUILD)'=='true' and '$(dotnetformat)'=='true')" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.7.112" Condition="!('$(TF_BUILD)'=='true' and '$(dotnetformat)'=='true')" />
<GlobalPackageReference Include="PolySharp" Version="1.15.0" />
<GlobalPackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
</ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions azure-pipelines/artifacts/coverageResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ $RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
$coverageFiles = @(Get-ChildItem "$RepoRoot/test/*.cobertura.xml" -Recurse | Where {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" })

# Prepare code coverage reports for merging on another machine
if ($env:SYSTEM_DEFAULTWORKINGDIRECTORY) {
Write-Host "Substituting $env:SYSTEM_DEFAULTWORKINGDIRECTORY with `"{reporoot}`""
$repoRoot = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
if (!$repoRoot) { $repoRoot = $env:GITHUB_WORKSPACE }
if ($repoRoot) {
Write-Host "Substituting $repoRoot with `"{reporoot}`""
$coverageFiles |% {
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($env:SYSTEM_DEFAULTWORKINGDIRECTORY), "{reporoot}" }
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" }
Set-Content -LiteralPath $_ -Value $content -Encoding UTF8
}
} else {
Write-Warning "coverageResults: Azure Pipelines not detected. Machine-neutral token replacement skipped."
Write-Warning "coverageResults: Cloud build not detected. Machine-neutral token replacement skipped."
}

if (!((Test-Path $RepoRoot\bin) -and (Test-Path $RepoRoot\obj))) { return }
Expand Down

0 comments on commit 4c6dfcd

Please sign in to comment.