From 5bc9c6c75177c1e0bed492f38824ddaf98f62b19 Mon Sep 17 00:00:00 2001 From: Ivan Blazhko Date: Tue, 19 Mar 2024 00:12:37 +0000 Subject: [PATCH 1/2] feat: Migrate to .NET8 * Using .NET 8.0 SDK * Added `net8.0` target framework, dropped `net5.0` * Simplified DevContainer Dockerfile * Updated Github Actions workflow --- .devcontainer/Dockerfile | 7 +-- .devcontainer/devcontainer.json | 53 +++---------------- .devcontainer/library-scripts/azcli-debian.sh | 34 ------------ .../continuous-integration-workflow.yml | 16 +++--- global.json | 2 +- .../WebApplicationFillForm.csproj | 6 +-- src/Kevsoft.PDFtk/Kevsoft.PDFtk.csproj | 2 +- test/Kevsoft.PDFtk.Tests/FillFormTests.cs | 6 +-- .../Kevsoft.PDFtk.Tests.csproj | 21 ++++---- 9 files changed, 36 insertions(+), 111 deletions(-) delete mode 100644 .devcontainer/library-scripts/azcli-debian.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c3df665..3ba55b4 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,5 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.166.1/containers/dotnet/.devcontainer/base.Dockerfile - -# [Choice] .NET version: 5.0, 3.1, 2.1 -ARG VARIANT="5.0" -FROM mcr.microsoft.com/vscode/devcontainers/dotnet:${VARIANT} +ARG SDK_VERSION="8.0" +FROM mcr.microsoft.com/dotnet/sdk:${SDK_VERSION} RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends pdftk diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b7480b..9545ca3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,53 +1,16 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.166.1/containers/dotnet { "name": "C# (.NET)", "build": { "dockerfile": "Dockerfile", "args": { - "VARIANT": "5.0", + "SDK_VERSION": "8.0", } }, - - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "ms-dotnettools.csharp" - ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [5000, 5001], - - // [Optional] To reuse of your local HTTPS dev cert: - // - // 1. Export it locally using this command: - // * Windows PowerShell: - // dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" - // * macOS/Linux terminal: - // dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" - // - // 2. Uncomment these 'remoteEnv' lines: - // "remoteEnv": { - // "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere", - // "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx", - // }, - // - // 3. Do one of the following depending on your scenario: - // * When using GitHub Codespaces and/or Remote - Containers: - // 1. Start the container - // 2. Drag ~/.aspnet/https/aspnetapp.pfx into the root of the file explorer - // 3. Open a terminal in VS Code and run "mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https" - // - // * If only using Remote - Containers with a local container, uncomment this line instead: - // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "dotnet restore", - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + "customizations": { + "vscode": { + "extensions": [ + "ms-dotnettools.csdevkit" + ] + } + } } diff --git a/.devcontainer/library-scripts/azcli-debian.sh b/.devcontainer/library-scripts/azcli-debian.sh deleted file mode 100644 index dec519b..0000000 --- a/.devcontainer/library-scripts/azcli-debian.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- -# -# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/azcli.md -# Maintainer: The VS Code and Codespaces Teams -# -# Syntax: ./azcli-debian.sh - -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 -fi - -export DEBIAN_FRONTEND=noninteractive - -# Install curl, apt-transport-https, lsb-release, or gpg if missing -if ! dpkg -s apt-transport-https curl ca-certificates lsb-release > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then - if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then - apt-get update - fi - apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release gnupg2 -fi - -# Install the Azure CLI -echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list -curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) -apt-get update -apt-get install -y azure-cli -echo "Done!" \ No newline at end of file diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 3dbb2ed..84e69f0 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -17,19 +17,19 @@ jobs: run: sudo apt-get install pdftk - name: Install PDFtk Server CLI if: ${{ matrix.os == 'windows-latest' }} - run: | + run: | choco install pdftk-server refreshenv echo "C:\Program Files (x86)\PDFtk Server\bin\" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - uses: actions/checkout@v2 - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1.x + - uses: actions/checkout@v4 - name: Setup .NET 6 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 6.0.x + - name: Setup .NET 8 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -44,7 +44,7 @@ jobs: dotnet nuget push ./artifacts/*.nupkg --source NuGet.org --api-key ${{ secrets.NUGET_API_KEY }} - name: Upload Release Asset if: ${{ fromJSON(env.RUN_DEPLOY) }} - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/global.json b/global.json index c077e9f..501e79a 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.101", + "version": "8.0.100", "rollForward": "latestFeature" } } \ No newline at end of file diff --git a/samples/WebApplicationFillForm/WebApplicationFillForm.csproj b/samples/WebApplicationFillForm/WebApplicationFillForm.csproj index 6a1a633..20deae0 100644 --- a/samples/WebApplicationFillForm/WebApplicationFillForm.csproj +++ b/samples/WebApplicationFillForm/WebApplicationFillForm.csproj @@ -1,15 +1,15 @@ - net5.0 + net8.0 58e1799c-a4c0-41aa-9399-ac70ecee6ba2 Linux ..\.. - - + + diff --git a/src/Kevsoft.PDFtk/Kevsoft.PDFtk.csproj b/src/Kevsoft.PDFtk/Kevsoft.PDFtk.csproj index f4b95ac..3d013b1 100644 --- a/src/Kevsoft.PDFtk/Kevsoft.PDFtk.csproj +++ b/src/Kevsoft.PDFtk/Kevsoft.PDFtk.csproj @@ -1,7 +1,7 @@ - netstandard2.0;netstandard2.1;net5.0;net6.0 + netstandard2.0;netstandard2.1;net6.0;net8.0 diff --git a/test/Kevsoft.PDFtk.Tests/FillFormTests.cs b/test/Kevsoft.PDFtk.Tests/FillFormTests.cs index 57c88e0..d53f53b 100644 --- a/test/Kevsoft.PDFtk.Tests/FillFormTests.cs +++ b/test/Kevsoft.PDFtk.Tests/FillFormTests.cs @@ -27,7 +27,7 @@ public async Task ShouldFillPdfForm_ForInputFileAsBytes() result.Success.Should().BeTrue(); var dumpDataFields = await _pdFtk.GetDataFieldsAsync(result.Result); - dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName)) + dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName ?? string.Empty)) .ToDictionary(x => x.FieldName!, field => field.FieldValue) .Should() .BeEquivalentTo(FieldData); @@ -42,7 +42,7 @@ public async Task ShouldFillPdfForm_ForInputFileAsStream() result.Success.Should().BeTrue(); var dumpDataFields = await _pdFtk.GetDataFieldsAsync(result.Result); - dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName)) + dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName ?? string.Empty)) .ToDictionary(x => x.FieldName!, field => field.FieldValue) .Should() .BeEquivalentTo(FieldData); @@ -55,7 +55,7 @@ public async Task ShouldFillPdfForm_ForInputFileAsFilePath() result.Success.Should().BeTrue(); var dumpDataFields = await _pdFtk.GetDataFieldsAsync(result.Result); - dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName)) + dumpDataFields.Result.Where(x => FieldData.Keys.Contains(x.FieldName ?? string.Empty)) .ToDictionary(x => x.FieldName!, field => field.FieldValue) .Should() .BeEquivalentTo(FieldData); diff --git a/test/Kevsoft.PDFtk.Tests/Kevsoft.PDFtk.Tests.csproj b/test/Kevsoft.PDFtk.Tests/Kevsoft.PDFtk.Tests.csproj index dd846bb..3d30bca 100644 --- a/test/Kevsoft.PDFtk.Tests/Kevsoft.PDFtk.Tests.csproj +++ b/test/Kevsoft.PDFtk.Tests/Kevsoft.PDFtk.Tests.csproj @@ -1,25 +1,28 @@ - netcoreapp3.1;net6.0 - + net8.0 false - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all + + + + PreserveNewest @@ -41,8 +44,4 @@ - - - - From 5ed1f22f0a6d13cbd4c1186f6cf7db9328de8c90 Mon Sep 17 00:00:00 2001 From: Ivan Blazhko Date: Tue, 19 Mar 2024 00:20:02 +0000 Subject: [PATCH 2/2] Update Windows build step --- .github/workflows/continuous-integration-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 84e69f0..02b7c65 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -18,8 +18,8 @@ jobs: - name: Install PDFtk Server CLI if: ${{ matrix.os == 'windows-latest' }} run: | + Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 choco install pdftk-server - refreshenv echo "C:\Program Files (x86)\PDFtk Server\bin\" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - uses: actions/checkout@v4 - name: Setup .NET 6