Fix 'Github Actions' configurations #117
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: CI | |
on: | |
push: | |
branches: | |
- 'master' | |
tags: [ 'v*' ] | |
pull_request: | |
branches: | |
- 'master' | |
defaults: | |
run: | |
shell: bash | |
env: | |
LOCAL_SOURCE_NAME: local | |
PACKAGES_DIRECTORY: nupkgs | |
PROJECT_NAME: Gon | |
TEST_PROJECT_NAME: TestProject | |
jobs: | |
test: | |
name: 'Test' | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
dotnet_sdk_version: [ '7.x' ] | |
dotnet_runtime_version: [ | |
'net45', 'net46', 'net47', 'net48', | |
'netstandard1.3', 'netstandard1.4', 'netstandard1.5', | |
'netstandard1.6', 'netstandard2.0', 'netstandard2.1', | |
'net5.0', 'net6.0', 'net7.0' | |
] | |
python_version: [ '3.11' ] | |
os: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ] | |
steps: | |
- name: 'Checkout' | |
uses: actions/checkout@v3 | |
- name: 'Setup .NET SDK' | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ matrix.dotnet_sdk_version }} | |
- name: 'Run dotnet format' | |
run: dotnet format style --verify-no-changes | |
- name: 'Install CSharpier' | |
run: dotnet tool install csharpier -g | |
- name: 'Run CSharpier' | |
run: dotnet csharpier --check . | |
- name: 'Setup Python' | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python_version }} | |
- name: 'Compare example from README with code' | |
run: > | |
python -c "import re;from pathlib import Path; | |
raise SystemExit( | |
'\n'.join(re.findall(r'(?<=\`\`\`cs\n)([^\`]+)', Path('README.md').read_text())) | |
!= Path('src/GonExamples/Basic.cs').read_text() | |
)" | |
- name: 'Install MyPy' | |
run: python -m pip install mypy | |
- name: 'Run MyPy' | |
run: mypy --ignore-missing-imports tests | |
- name: 'Install tests dependencies' | |
run: python -m pip install -r requirements-tests.txt | |
- name: 'Publish project' | |
run: > | |
dotnet publish --property:CheckEolTargetFramework=false | |
--property:PublishDir=$PWD/tests/ | |
--framework ${{ matrix.dotnet_runtime_version }} . | |
- name: 'Run tests' | |
run: pytest | |
pre-deploy: | |
name: 'Pre-deploy' | |
runs-on: ubuntu-latest | |
# needs: test | |
if: github.event_name == 'push' && github.ref_type == 'tag' | |
steps: | |
- name: '_' | |
run: echo "Pre-deploy step" | |
build: | |
name: 'Build' | |
runs-on: ubuntu-latest | |
needs: pre-deploy | |
steps: | |
- name: 'Checkout' | |
uses: actions/checkout@v3 | |
- name: 'Setup .NET SDK' | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '7.x' | |
- name: 'Build' | |
run: > | |
dotnet pack -c Release -o ${{ env.PACKAGES_DIRECTORY }} | |
src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj | |
- name: 'Upload' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.PACKAGES_DIRECTORY }} | |
path: ${{ env.PACKAGES_DIRECTORY }} | |
test-distributions: | |
name: Test distributions | |
runs-on: ${{ matrix.os }} | |
needs: build | |
strategy: | |
matrix: | |
dotnet_runtime_version: [ | |
'net45', 'net46', 'net47', 'net48', | |
'netstandard1.3', 'netstandard1.4', 'netstandard1.5', | |
'netstandard1.6', 'netstandard2.0', 'netstandard2.1', | |
'net5.0', 'net6.0', 'net7.0' | |
] | |
os: [ 'macos-latest', 'ubuntu-latest', 'windows-latest' ] | |
steps: | |
- name: 'Setup .NET SDK' | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '7.x' | |
- name: 'Download distributions' | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.PACKAGES_DIRECTORY }} | |
path: ${{ env.PACKAGES_DIRECTORY }} | |
- name: 'Configure NuGet' | |
run: | | |
dotnet nuget add source ${{ github.workspace }}/${{ env.PACKAGES_DIRECTORY }} --name ${{ env.LOCAL_SOURCE_NAME }} | |
cat > nuget.config <<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<packageSourceMapping> | |
<packageSource key="nuget.org"> | |
<package pattern="*"/> | |
</packageSource> | |
<packageSource key="${{ env.LOCAL_SOURCE_NAME }}"> | |
<package pattern="${{ env.PROJECT_NAME }}"/> | |
</packageSource> | |
</packageSourceMapping> | |
</configuration> | |
EOF | |
- name: 'Create test project' | |
run: > | |
dotnet new classlib -o ${{ env.TEST_PROJECT_NAME }} | |
--target-framework-override ${{ matrix.dotnet_runtime_version }} | |
- name: > | |
fix "CS8370: Feature 'file-scoped namespace' is not available in C# 7.3" | |
run: | | |
cat > .editorconfig <<EOF | |
root = true | |
[*.cs] | |
dotnet_analyzer_diagnostic.category-Style.severity = error | |
EOF | |
dotnet format style ${{ env.TEST_PROJECT_NAME }} --diagnostics IDE0160 | |
- name: 'Install' | |
run: > | |
dotnet add ${{ env.TEST_PROJECT_NAME }} package | |
${{ env.PROJECT_NAME }} -v ${GITHUB_REF_NAME#v} | |
- name: 'Build test project' | |
# "Nullable=disable" fixes "CS8630: Invalid 'nullable' value: 'Enable' for C# 7.3" | |
# "ImplicitUsings=disable" fixes "CS8370: Feature 'global using directive' is not available in C# 7.3" | |
run: > | |
dotnet build --property:Nullable=disable | |
--property:ImplicitUsings=disable | |
${{ env.TEST_PROJECT_NAME }} | |
deploy: | |
name: 'Deploy' | |
environment: release | |
needs: test-distributions | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Download distributions' | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.PACKAGES_DIRECTORY }} | |
path: ${{ env.PACKAGES_DIRECTORY }} | |
- name: 'Setup .NET SDK' | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '7.x' | |
- name: 'NuGet upload' | |
run: > | |
dotnet nuget push ${{ env.PACKAGES_DIRECTORY }}/*.nupkg --api-key $NUGET_API_KEY | |
-s https://api.nuget.org/v3/index.json | |
env: | |
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |