diff --git a/Dockerfile.simplified b/Dockerfile.simplified new file mode 100644 index 0000000..3cd3349 --- /dev/null +++ b/Dockerfile.simplified @@ -0,0 +1,33 @@ +ARG SDK_VERSION +ARG RUNTIME_VERSION +FROM mcr.microsoft.com/dotnet/aspnet:${RUNTIME_VERSION}-jammy-chiseled-extra AS base + +FROM mcr.microsoft.com/dotnet/sdk:${SDK_VERSION}-jammy AS build +ARG PROJECT +WORKDIR /src/ +COPY . . +RUN <" ${PROJECT} +if [ $? -eq 0 ]; then + sed -i ${PROJECT} -e "s|.*|main|" +else + sed -i ${PROJECT} -e "s||main|" +fi +EOR +RUN dotnet tool restore || true +RUN dotnet restore +RUN dotnet build -c Release --no-restore +RUN dotnet publish ${PROJECT} -c Release -o /app/publish --no-restore --no-build +WORKDIR /app/publish +RUN rm -f appsettings.json appsettings.*.json || true + +FROM base AS final +WORKDIR /app +COPY --from=build /app/publish . +COPY migrations/* /migrations/ +COPY --from=busybox:uclibc /bin/cp /bin/cp +COPY --from=busybox:uclibc /bin/cat /bin/cat +COPY --from=busybox:uclibc /bin/ls /bin/ls +EXPOSE 8080 +EXPOSE 8081 +ENTRYPOINT ["/app/main"] diff --git a/actions/dotnet-validate-solution/action.yaml b/actions/dotnet-validate-solution/action.yaml new file mode 100644 index 0000000..95461bd --- /dev/null +++ b/actions/dotnet-validate-solution/action.yaml @@ -0,0 +1,106 @@ +name: Dotnet Validate + +description: Lints and tests a domain. + +inputs: + path: + description: The path of the parent folder of the solution. + required: true + + project: + description: The path of a project file that is used to generate migrations with, if needed. Both project and migrations must be present for the check to happen. + default: "" + required: false + + migrations: + description: The path of a commited sql file, that needs to be validated against. Both project and migrations must be present for the check to happen. + default: "" + required: false + + dotnet-version: + description: The version of dotnet to use + required: true + + pin-version: + description: Pin dotnet version + default: "false" + required: false + +runs: + using: composite + + steps: + - name: Setup dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ inputs.dotnet-version }} + + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- + + - name: Pin version + working-directory: ${{ inputs.path }} + shell: bash + if: ${{ inputs.pin-version == 'true' }} + run: printf '{"sdk":{"rollForward":"disable","version":"%s"}}' "${{ inputs.dotnet-version }}" > global.json + + - name: Print dotnet version + working-directory: ${{ inputs.path }} + shell: bash + run: dotnet --version + + - name: Print dotnet information + working-directory: ${{ inputs.path }} + shell: bash + run: dotnet --info + + - name: Restore + working-directory: ${{ inputs.path }} + shell: bash + env: + version: "" + run: | + dotnet tool restore || true + dotnet restore + + - name: Lint + working-directory: ${{ inputs.path }} + shell: bash + env: + version: "" + run: dotnet format --verify-no-changes -v diag + + - name: Test + working-directory: ${{ inputs.path }} + shell: bash + env: + version: "" + run: dotnet test --no-restore -warnaserror --logger:"console;verbosity=normal" + + - name: Validate migration + shell: bash + env: + VERSION: ${{ inputs.dotnet-version }} + PROJECT: ${{ inputs.project }} + COMMITED_SQL_FILE: ${{ inputs.migrations }} + if: ${{ '' != inputs.migrations && '' != inputs.project }} + run: | + GENERATED_SQL_FILE=/tmp/current.sql + version=$(echo $VERSION | cut -c 1) + if [ "$version" = "6" ]; then + argument="--version 6.0.25" + elif [ "$version" = "7" ]; then + argument="--version 7.0.14" + fi + dotnet list package --format=json | grep 'Microsoft.EntityFrameworkCore"' >/dev/null || exit 0 + dotnet tool install --global $argument dotnet-ef >/dev/null + dotnet ef migrations script --project "$PROJECT" -i -o "$GENERATED_SQL_FILE" + + cat < "$GENERATED_SQL_FILE" | sed '/INSERT INTO "__EFMigrationsHistory"/,/);$/d' > /tmp/a + cat < "$COMMITED_SQL_FILE" | sed '/INSERT INTO "__EFMigrationsHistory"/,/);$/d' > /tmp/b + diff -q /tmp/a /tmp/b >/dev/null || { echo "Unexpected difference:"; diff /tmp/a /tmp/b; exit 1; }