From ef77347647c8ceddd6d746090b92f990d05c308e Mon Sep 17 00:00:00 2001
From: Martijn Bodeman <11424653+skwasjer@users.noreply.github.com>
Date: Sat, 18 Nov 2023 02:19:18 +0100
Subject: [PATCH] ci: switch fully to GitHub actions instead of AppVeyor (#83)
---
.github/actions/download-artifact/action.yml | 32 ++++
.github/actions/upload-artifact/action.yml | 47 +++++
.github/workflows/codeql-analysis.yml | 33 ++--
.github/workflows/dotnetcore.yml | 35 ----
.github/workflows/main.yml | 191 +++++++++++++++++++
.github/workflows/sonarcloud.yml | 45 +++--
Directory.Build.props | 11 +-
Directory.Build.targets | 11 ++
GitVersion.yml | 12 ++
MockHttp.sln | 1 +
NuGet.config | 7 +
appveyor.yml | 41 ----
codecov.yml | 28 ---
src/Directory.Build.props | 5 +-
src/Directory.Build.targets | 10 +-
test/Directory.Build.targets | 10 +-
16 files changed, 364 insertions(+), 155 deletions(-)
create mode 100644 .github/actions/download-artifact/action.yml
create mode 100644 .github/actions/upload-artifact/action.yml
delete mode 100644 .github/workflows/dotnetcore.yml
create mode 100644 .github/workflows/main.yml
create mode 100644 Directory.Build.targets
create mode 100644 NuGet.config
delete mode 100644 appveyor.yml
delete mode 100644 codecov.yml
diff --git a/.github/actions/download-artifact/action.yml b/.github/actions/download-artifact/action.yml
new file mode 100644
index 00000000..7227ff20
--- /dev/null
+++ b/.github/actions/download-artifact/action.yml
@@ -0,0 +1,32 @@
+name: Download artifact
+description: Wrapper around GitHub's official action, with additional extraction before download
+
+# https://github.com/actions/download-artifact/blob/main/action.yml
+# https://github.com/actions/upload-artifact/issues/199
+inputs:
+ name:
+ description: Artifact name
+ required: true
+ path:
+ description: Destination path
+ required: false
+ default: .
+
+runs:
+ using: composite
+ steps:
+ - name: Download artifacts
+ uses: actions/download-artifact@v3
+ with:
+ name: ${{ inputs.name }}
+ path: ${{ inputs.path }}
+
+ - name: Extract artifacts
+ run: tar -xvf ${{ inputs.name }}.tar
+ shell: bash
+ working-directory: ${{ inputs.path }}
+
+ - name: Remove archive
+ run: rm -f ${{ inputs.name }}.tar
+ shell: bash
+ working-directory: ${{ inputs.path }}
diff --git a/.github/actions/upload-artifact/action.yml b/.github/actions/upload-artifact/action.yml
new file mode 100644
index 00000000..b8aeff26
--- /dev/null
+++ b/.github/actions/upload-artifact/action.yml
@@ -0,0 +1,47 @@
+name: Upload artifact
+description: Wrapper around GitHub's official action, with additional archiving before upload
+
+# https://github.com/actions/upload-artifact/blob/main/action.yml
+# https://github.com/actions/upload-artifact/issues/199
+inputs:
+ name:
+ description: Artifact name
+ required: true
+ path:
+ description: One or more files, directories or wildcard pattern that describes what to upload
+ required: true
+ if-no-files-found:
+ description: >
+ The desired behavior if no files are found using the provided path.
+ Available Options:
+ warn: Output a warning but do not fail the action
+ error: Fail the action with an error message
+ ignore: Do not output any warnings or errors, the action does not fail
+ required: false
+ default: warn
+ retention-days:
+ description: >
+ Duration after which artifact will expire in days. 0 means using default retention.
+ Minimum 1 day.
+ Maximum 90 days unless changed from the repository settings page.
+ required: false
+ default: '0'
+
+runs:
+ using: composite
+ steps:
+ - name: Archive artifacts
+ run: tar -cv -I 'xz -0 -T0' -f ${{ inputs.name }}.tar $(echo "${{ inputs.path }}" | tr '\n' ' ')
+ shell: bash
+
+ - name: Upload artifacts
+ uses: actions/upload-artifact@v3
+ with:
+ if-no-files-found: ${{ inputs.if-no-files-found }}
+ name: ${{ inputs.name }}
+ path: ${{ inputs.name }}.tar
+ retention-days: ${{ inputs.retention-days }}
+
+ - name: Remove archive
+ run: rm -f ${{ inputs.name }}.tar
+ shell: bash
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 1e6e444a..a3a28785 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -20,6 +20,17 @@ on:
schedule:
- cron: '0 7 * * 6'
+env:
+ DOTNET_CLI_TELEMETRY_OPTOUT: true
+ DOTNET_NOLOGO: true
+ dotnet-version: |
+ 8.0.x
+ 7.0.x
+ 6.0.x
+ 5.0.x
+ 3.1.x
+ 2.1.x
+
jobs:
analyze:
name: Analyze
@@ -38,25 +49,17 @@ jobs:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- - uses: actions/checkout@v3
+ # Setup
- uses: actions/setup-dotnet@v3
with:
- dotnet-version: |
- 7.0.x
- 6.0.x
- 5.0.x
- 3.1.x
- 2.1.x
+ dotnet-version: ${{ env.dotnet-version }}
- - name: dotnet info
- run: dotnet --info
+ - run: dotnet --info
- # https://github.com/actions/runner-images/blob/ubuntu22/20230821.1/images/linux/Ubuntu2204-Readme.md
- # There is an issue with latest SDK on Linux with .NET Framework:
- # https://github.com/microsoft/vstest/issues/4549
- # Unfortunatey, it becomes preinstalled with latest GitHub runner images, so have to remove it for now.
- - name: Remove latest .NET SDK (7.0.400)
- run: sudo rm -rf ${DOTNET_ROOT}/sdk/7.0.400
+ # Checkout
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml
deleted file mode 100644
index fa87e199..00000000
--- a/.github/workflows/dotnetcore.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-name: .NET Core
-
-on: [push, pull_request]
-
-jobs:
- dotnet:
- name: ${{ matrix.os }}
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- os: [ubuntu-latest, windows-latest, macos-latest]
- fail-fast: false
- steps:
- - uses: actions/checkout@v3
- - uses: actions/setup-dotnet@v3
- with:
- dotnet-version: |
- 7.0.x
- 6.0.x
- 5.0.x
- 3.1.x
- 2.1.x
-
- - name: dotnet info
- run: dotnet --info
-
- # https://github.com/actions/runner-images/blob/ubuntu22/20230821.1/images/linux/Ubuntu2204-Readme.md
- # There is an issue with latest SDK on Linux with .NET Framework:
- # https://github.com/microsoft/vstest/issues/4549
- # Unfortunatey, it becomes preinstalled with latest GitHub runner images, so have to remove it for now.
- - name: Remove latest .NET SDK (7.0.400)
- if: matrix.os != 'windows-latest'
- run: sudo rm -rf ${DOTNET_ROOT}/sdk/7.0.400
-
- - run: dotnet test -c Release
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 00000000..e1b45229
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,191 @@
+on:
+ push:
+ branches:
+ - main
+ release:
+ types:
+ - published
+ pull_request:
+
+name: pipeline
+env:
+ DOTNET_CLI_TELEMETRY_OPTOUT: true
+ DOTNET_NOLOGO: true
+ dotnet-version: |
+ 8.0.x
+ 7.0.x
+ 6.0.x
+ 5.0.x
+ 3.1.x
+ 2.1.x
+
+jobs:
+ determine-version:
+ runs-on: ubuntu-latest
+ env:
+ IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1
+ # v5.10.0 of GitVersion has a fix for incorrect versions when building on tag. See https://github.com/GitTools/GitVersion/issues/2838
+ # It appears that the fix then had a regression in a later version, so pinning to v5.10.0. See https://github.com/GitTools/GitVersion/issues/3351#issuecomment-1403657689
+ GITVERSION: '5.10.0'
+ outputs:
+ version: ${{ steps.gitversion.outputs.fullSemVer }}
+ package-version: ${{ steps.gitversion.outputs.fullSemVer }}
+ assembly-version: ${{ steps.gitversion.outputs.assemblySemVer }}
+ file-version: ${{ steps.gitversion.outputs.assemblySemFileVer }}
+ informational-version: ${{ steps.gitversion.outputs.informationalVersion }}
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ fetch-tags: true
+
+ - name: Install GitVersion ${{ env.GITVERSION }}
+ uses: gittools/actions/gitversion/setup@v0.10.2
+ with:
+ versionSpec: ${{ env.GITVERSION }}
+
+ - name: Determine version
+ uses: gittools/actions/gitversion/execute@v0.10.2
+ id: gitversion
+ with:
+ useConfigFile: true
+
+ build:
+ needs:
+ - determine-version
+ name: build (v${{ needs.determine-version.outputs.version }})
+ runs-on: ubuntu-latest
+ env:
+ msbuild-version-args: /p:Version="${{ needs.determine-version.outputs.version }}" /p:PackageVersion="${{ needs.determine-version.outputs.package-version }}" /p:AssemblyVersion="${{ needs.determine-version.outputs.assembly-version }}" /p:FileVersion="${{ needs.determine-version.outputs.file-version }}" /p:InformationalVersion="${{ needs.determine-version.outputs.informational-version }}"
+ outputs:
+ dotnet-version: ${{ env.dotnet-version }}
+ msbuild-version-args: ${{ env.msbuild-version-args }}
+ steps:
+ # Setup
+ - uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: ${{ env.dotnet-version }}
+
+ - run: dotnet --info
+
+ # Checkout
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 1
+
+ # NuGet cache
+ - name: Restore NuGet global package cache
+ uses: actions/cache@v3
+ with:
+ path: ~/.nuget/packages
+ key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.targets','**/*.props','**/*.csproj') }} # Can't use packages.lock.json yet, because Dependabot does not support it.
+ restore-keys: |
+ ${{ runner.os }}-nuget-
+
+ # Restore
+ - run: dotnet restore
+
+ # Build
+ - run: dotnet build --no-restore -c Release ${{ env.msbuild-version-args }}
+ - name: Upload build artifacts
+ uses: ./.github/actions/upload-artifact
+ with:
+ name: build
+ path: |
+ */**/bin
+ */**/obj
+ if-no-files-found: error
+ retention-days: 7
+
+ test:
+ needs: build
+ strategy:
+ matrix:
+ os:
+ - ubuntu-latest
+ - windows-latest
+ - macos-latest
+ fail-fast: false
+ runs-on: ${{ matrix.os }}
+ steps:
+ # Setup
+ - uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: ${{ env.dotnet-version }}
+
+ # Checkout
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 1
+
+ # Restore build artifacts
+ - name: Download build artifacts
+ uses: ./.github/actions/download-artifact
+ with:
+ name: build
+
+ # Run all tests
+ - run: dotnet test --no-restore --no-build -c Release
+
+ pack:
+ needs:
+ - determine-version
+ - build
+ runs-on: ubuntu-latest
+ steps:
+ # Setup
+ - uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: ${{ env.dotnet-version }}
+
+ # Checkout
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 1
+
+ # NuGet cache (.NET Framework Reference assemblies are needed for pack)
+ - name: Restore NuGet global package cache
+ uses: actions/cache@v3
+ with:
+ path: ~/.nuget/packages
+ key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.targets','**/*.props','**/*.csproj') }} # Can't use packages.lock.json yet, because Dependabot does not support it.
+ restore-keys: |
+ ${{ runner.os }}-nuget-
+ fail-on-cache-miss: true
+
+ # Restore build artifacts
+ - name: Download build artifacts
+ uses: ./.github/actions/download-artifact
+ with:
+ name: build
+
+ # Pack
+ - run: dotnet pack --no-restore --no-build -c Release ${{ needs.build.outputs.msbuild-version-args }}
+ - name: Upload release artifacts
+ uses: actions/upload-artifact@v3
+ with:
+ name: release-${{ needs.determine-version.outputs.package-version }}
+ path: |
+ **/*.*nupkg
+ if-no-files-found: error
+ retention-days: 90
+
+ deploy:
+ needs:
+ - determine-version
+ - test
+ - pack
+ if: github.event_name == 'release'
+ environment: production
+ runs-on: ubuntu-latest
+ steps:
+ # Restore release artifacts
+ - name: Download release artifact
+ uses: actions/download-artifact@v3
+ with:
+ name: release-${{ needs.determine-version.outputs.package-version }}
+
+ - name: push - nuget.org
+ env:
+ NUGET_SOURCE_URL: https://api.nuget.org/v3/index.json
+ run: dotnet nuget push **/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE_URL }}
diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml
index 43473a11..49bfdc08 100644
--- a/.github/workflows/sonarcloud.yml
+++ b/.github/workflows/sonarcloud.yml
@@ -1,12 +1,25 @@
-name: SonarCloud analysis
-
on:
push:
branches:
- main
+ release:
+ types:
+ - published
pull_request_target: # This exposes repo secrets to PR, so manual approval via authorize job is enforced via 'external' environment.
workflow_dispatch:
+name: sonarcloud
+env:
+ DOTNET_CLI_TELEMETRY_OPTOUT: true
+ DOTNET_NOLOGO: true
+ dotnet-version: |
+ 8.0.x
+ 7.0.x
+ 6.0.x
+ 5.0.x
+ 3.1.x
+ 2.1.x
+
jobs:
# Blog https://iterative.ai/blog/testing-external-contributions-using-github-actions-secrets
authorize:
@@ -21,21 +34,12 @@ jobs:
analysis:
needs: authorize
runs-on: ubuntu-latest
-
steps:
- - uses: actions/checkout@v3
- with:
- ref: ${{ github.event.pull_request.head.sha || github.ref }}
- fetch-depth: 0
-
- uses: actions/setup-dotnet@v3
with:
- dotnet-version: |
- 7.0.x
- 6.0.x
- 5.0.x
- 3.1.x
- 2.1.x
+ dotnet-version: ${{ env.dotnet-version }}
+
+ - run: dotnet --info
- uses: actions/setup-node@v3
with:
@@ -46,15 +50,10 @@ jobs:
distribution: "temurin"
java-version: "17"
- - name: dotnet info
- run: dotnet --info
-
- # https://github.com/actions/runner-images/blob/ubuntu22/20230821.1/images/linux/Ubuntu2204-Readme.md
- # There is an issue with latest SDK on Linux with .NET Framework:
- # https://github.com/microsoft/vstest/issues/4549
- # Unfortunatey, it becomes preinstalled with latest GitHub runner images, so have to remove it for now.
- - name: Remove latest .NET SDK (7.0.400)
- run: sudo rm -rf ${DOTNET_ROOT}/sdk/7.0.400
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ github.event.pull_request.head.sha || github.ref }}
+ fetch-depth: 0
- name: Install Sonar scanner
run: dotnet tool install --global dotnet-sonarscanner
diff --git a/Directory.Build.props b/Directory.Build.props
index c57a7c67..ad81edf7 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -5,8 +5,15 @@
true
enable
enable
- $(NoWarn);CS0618;NETSDK1138
- true
+ false
+ $(NoWarn);IDE0079;S1135;CA1510;CA1511;CA1512;CA1513;CA1863
+ $(NoWarn);NETSDK1138
+ $(WarningsAsErrors);NU1601;NU1603;NU1605;NU1608;NU1701;MSB3644
+ true
+ true
+
+
+ en
diff --git a/Directory.Build.targets b/Directory.Build.targets
new file mode 100644
index 00000000..f7f87bcf
--- /dev/null
+++ b/Directory.Build.targets
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/GitVersion.yml b/GitVersion.yml
index bd698fb3..64a722dc 100644
--- a/GitVersion.yml
+++ b/GitVersion.yml
@@ -1,9 +1,21 @@
assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDelivery
continuous-delivery-fallback-tag: 'ci'
+# If your package version contains one of the following, they will not be visible from the older clients
+# (NuGet clients before 4.3.0 or Visual Studio before 2017 version 15.3):
+# The pre-release label is dot-separated, e.g. 1.0.0-alpha.1
+# The version has build-metadata, e.g. 1.0.0+githash We recommend you consider this to be a beta-feature until a significant majority of our users are on these latest clients that understand Semantic Versioning 2.0.0.
+# See https://devblogs.microsoft.com/nuget/whats-nu-in-nuget-with-visual-studio-2017-version-15-3/#support-for-semantic-versioning-200
+legacy-semver-padding: 1
+build-metadata-padding: 1
+commits-since-version-source-padding: 1
branches:
main:
regex: ^main$
tag: 'ci'
+ pull-request:
+ regex: ^(pull|pull\-requests|pr)[/-]
+ mode: ContinuousDelivery
+ tag: pr
ignore:
sha: []
diff --git a/MockHttp.sln b/MockHttp.sln
index 07095945..3a3a3ca3 100644
--- a/MockHttp.sln
+++ b/MockHttp.sln
@@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
appveyor.yml = appveyor.yml
CHANGELOG.md = CHANGELOG.md
Directory.Build.props = Directory.Build.props
+ Directory.Build.targets = Directory.Build.targets
README.md = README.md
EndProjectSection
EndProject
diff --git a/NuGet.config b/NuGet.config
new file mode 100644
index 00000000..4d736c19
--- /dev/null
+++ b/NuGet.config
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index fb29f8fc..00000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-image: Visual Studio 2022
-skip_branch_with_pr: true
-configuration: Release
-environment:
- IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1
-install:
- - choco install gitversion.portable -y
- - gitversion /l console /output buildserver
- - choco install opencover.portable -y
- - choco install codecov -y
-cache:
- - C:\ProgramData\chocolatey\bin -> appveyor.yml, codecov.yml
- - C:\ProgramData\chocolatey\lib -> appveyor.yml, codecov.yml
-dotnet_csproj:
- patch: true
- file: '**\*.csproj;**\*.props'
- version: '{GitVersion_SemVer}'
- package_version: $(GitVersion_NuGetVersion)
- assembly_version: $(GitVersion_AssemblySemVer)
- file_version: $(GitVersion_AssemblySemFileVer)
- informational_version: $(GitVersion_InformationalVersion)
-nuget:
- project_feed: true
-# disable_publish_on_pr: true
-before_build:
- - dotnet restore
-build:
- project: MockHttp.sln
- publish_nuget: true
- publish_nuget_symbols: true
- use_snupkg_format: true
- verbosity: minimal
-test_script:
- - OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test -c Release /p:DebugType=full -l:trx;LogFilePrefix=testresults" -output:coverage.xml -register:user -returntargetcode -filter:"+[*MockHttp*]* -[*Tests]* -[*Testing]*" -excludebyattribute:*.ExcludeFromCodeCoverageAttribute;*.GeneratedCodeAttribute;*.DebuggerNonUserCodeAttribute;*.CompilerGeneratedAttribute;*.DebuggerHiddenAttribute -oldStyle
- - codecov -f coverage.xml
-deploy:
-- provider: NuGet
- api_key:
- secure: LYK2kBW5UKfW19u4OR0m91tWA4/+kvmPQKm721Gp/VPjKU6F0pO4E8XrhId71pVp
- on:
- APPVEYOR_REPO_TAG: true
diff --git a/codecov.yml b/codecov.yml
deleted file mode 100644
index f2a2be91..00000000
--- a/codecov.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-codecov:
- branch: main
- require_ci_to_pass: false
- notify:
- wait_for_ci: false
-comment:
- behavior: default
- layout: header,tree
- require_changes: false
-coverage:
- precision: 2
- round: down
- range: "70...100"
- status:
- changes: false
- patch: false
- project:
- default:
- threshold: 1%
-parsers:
- gcov:
- branch_detection:
- conditional: true
- loop: true
- macro: false
- method: false
- javascript:
- enable_partials: false
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index e809b0cd..c3d30e3a 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -1,8 +1,6 @@
- true
-
1.0.0
1.0.0
1.0.0.0
@@ -19,11 +17,14 @@
git
PackageIcon64.png
Release notes are at https://github.com/skwasjer/MockHttp/releases
+ true
+ latest-All
+
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index ee946f04..7180fa4b 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -1,8 +1,7 @@
- NU1605;CS1591
- $(NoWarn);IDE0079;S1939
+ $(WarningsAsErrors);CS1591
@@ -14,14 +13,13 @@
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets
index e6e55bce..f4f4b349 100644
--- a/test/Directory.Build.targets
+++ b/test/Directory.Build.targets
@@ -2,11 +2,12 @@
false
-
+ false
+ $(NoWarn);NU1902;NU1903
17.8.0
-
+
17.3.3
@@ -22,7 +23,7 @@
-
+
@@ -31,4 +32,7 @@
+
+
+