Skip to content

Include dotnet 3.1, 6.0 and 8.0 in devcontainer #22

Include dotnet 3.1, 6.0 and 8.0 in devcontainer

Include dotnet 3.1, 6.0 and 8.0 in devcontainer #22

Workflow file for this run

name: .NET CI/CD
on: [push, pull_request]
env:
# more info on dotnet cli environment variables here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Disable welcome message on dotnet CLI first run
DOTNET_NOLOGO: true
# Disable redundant package caching
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
tests:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
dotnet-target: ["3.1.x", "6.0.x", "8.0.x"]
exclude:
- os: macOS-latest
dotnet-target: "3.1.x"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.x
8.0.x
if: ${{ !startsWith(matrix.os, 'macOS') }}
- name: Set up dotnet macOS ARM
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
if: startsWith(matrix.os, 'macOS')
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: |
dotnet restore
- name: Build
run: |
dotnet build --configuration Release --version-suffix "$GITHUB_RUN_ID-prerelease" --no-restore
- name: Run tests (Linux and macOS)
if: runner.os != 'Windows'
run: |
if [ "${{ matrix.dotnet-target }}" == "3.1.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests
elif [ "${{ matrix.dotnet-target }}" == "6.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
elif [ "${{ matrix.dotnet-target }}" == "8.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
else
echo "Error: Unsupported .NET version ${{ matrix.dotnet-target }}" && exit 1
fi
- name: Run tests (Windows)
if: runner.os == 'Windows'
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if ("${{ matrix.dotnet-target }}" -eq "3.1.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "5.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net5.0 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "6.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests
} elseif ("${{ matrix.dotnet-target }}" -eq "8.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests
} else {
Write-Error "Unsupported .NET version $env:MATRIX_DOTNET_VERSION"
exit 1
}
integrationTests:
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
needs:
- "tests"
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
dotnet-version: [3.1.x, 8.0.x]
exclude:
- os: macOS-latest
dotnet-version: 3.1.x
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: |
dotnet restore
- name: Build
run: |
dotnet build --configuration Release --version-suffix "$GITHUB_RUN_ID-prerelease" --no-restore
- name: Run tests on mac and linux
if: ${{ !startsWith(matrix.os, 'windows') }}
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if [ ${{ matrix.dotnet-version }} == "3.1.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests.Integration
elif [ ${{ matrix.dotnet-version }} == "6.0.x" ]; then
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
else
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests.Integration
fi
- name: Run tests on windows
if: startsWith(matrix.os, 'windows')
env:
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
run: |
if ("${{ matrix.dotnet-version }}" -eq "6.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net6.0 test/Tinify.Tests.Integration
} elseif ("${{ matrix.dotnet-version }}" -eq "3.1.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework netcoreapp3.1 test/Tinify.Tests.Integration
} elseif ("${{ matrix.dotnet-version }}" -eq "8.0.x") {
dotnet test --configuration Release --no-build --verbosity normal --framework net8.0 test/Tinify.Tests.Integration
} else {
Write-Error "Unsupported .NET version $env:MATRIX_DOTNET_VERSION"
exit 1
}
publish:
if: |
github.repository == 'tinify/tinify-net' &&
startsWith(github.ref, 'refs/tags') &&
github.event_name == 'push'
needs:
- "tests"
- "integrationTests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Check if properly tagged
run: |
PACKAGE_VERSION="$(sed 's/\s*<VersionPrefix>\(.*\)<\/VersionPrefix>/\1/p' -n < src/Tinify/Tinify.csproj | tr -d '\n\r')";
CURRENT_TAG="${GITHUB_REF#refs/*/}";
if [[ "${PACKAGE_VERSION}" != "${CURRENT_TAG}" ]]; then
>&2 echo "Tag mismatch"
>&2 echo "Version in tinify/version.py (${PACKAGE_VERSION}) does not match the current tag=${CURRENT_TAG}"
>&2 echo "Skipping deploy"
exit 1;
fi
- name: Create Release NuGet package
run: |
CURRENT_TAG="${GITHUB_REF#refs/*/}";
echo "Clean Version: ${CURRENT_TAG}"
dotnet pack src/Tinify/Tinify.csproj -v normal -c Release --include-symbols --include-source -p:PackageVersion="${CURRENT_TAG}" -o .
- name: Push to Nuget
run: |
dotnet nuget push *.nupkg --skip-duplicate -s https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}}