From a11f1110106263a19d9ab24060be3851092fa7c6 Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 19:36:26 +0200 Subject: [PATCH 1/7] cleanup: Check for CS8604 -- Possible null reference argument in m.media_attachments! Possibly it is connected with the missing Null annotations in Messages.cs! This whole assignment makes the compiler 'mad' in several parts with multiple different Warnings. At a first glance I wasn't clear to me how to fix these warnings! --- src/TagzApp.Providers.Mastodon/MastodonProvider.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TagzApp.Providers.Mastodon/MastodonProvider.cs b/src/TagzApp.Providers.Mastodon/MastodonProvider.cs index 24826282..b23d2dff 100644 --- a/src/TagzApp.Providers.Mastodon/MastodonProvider.cs +++ b/src/TagzApp.Providers.Mastodon/MastodonProvider.cs @@ -53,8 +53,9 @@ public async Task> GetContentForHashtag(Hashtag tag, DateTi _NewestId = messages.OrderByDescending(m => m.id).First().id; - var baseServerAddress = _HttpClient.BaseAddress.Host.ToString(); + var baseServerAddress = _HttpClient.BaseAddress?.Host.ToString(); +#pragma warning disable CS8604 // Possible null reference argument. return messages!.Select(m => new Content { Provider = Id, @@ -72,8 +73,12 @@ public async Task> GetContentForHashtag(Hashtag tag, DateTi }, Text = m.content, HashtagSought = tag.Text, - PreviewCard = m.card is null ? m.media_attachments.Any() ? (Common.Models.Card)Message.GetMediaAttachment(m.media_attachments.First().ToString()) : null : (Common.Models.Card)m.card + // TODO: Check for CS8604 -- Possible null reference argument in m.media_attachments! Possibly it is connected with the missing Null annotations in Messages.cs! This whole assignment makes the compiler "mad" in several parts with multiple different Warnings. At a first glance I wasn't clear how to fix these warnings! + PreviewCard = m.card is null ? m.media_attachments.Any() + ? (Common.Models.Card)Message.GetMediaAttachment(m.media_attachments.First().ToString()) + : null : (Common.Models.Card)m.card! }).ToArray(); +#pragma warning restore CS8604 // Possible null reference argument. } From e5d30f0c3890f0f440651faa2b762986025f1f99 Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:28:53 +0200 Subject: [PATCH 2/7] cleanup: Check for CS8618 -- Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. --- src/TagzApp.Providers.Blazot/Events/AuthEvents.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/TagzApp.Providers.Blazot/Events/AuthEvents.cs b/src/TagzApp.Providers.Blazot/Events/AuthEvents.cs index 3adcfcd8..61e4ecc4 100644 --- a/src/TagzApp.Providers.Blazot/Events/AuthEvents.cs +++ b/src/TagzApp.Providers.Blazot/Events/AuthEvents.cs @@ -1,15 +1,18 @@ namespace TagzApp.Providers.Blazot.Events; -internal interface IAuthEvents +internal interface IAuthEvents { - event EventHandler AccessTokenUpdated; + event EventHandler AccessTokenUpdated; - void NotifyAccessTokenUpdated(); + void NotifyAccessTokenUpdated(); } internal class AuthEvents : IAuthEvents { - public event EventHandler AccessTokenUpdated; + // TODO: Check CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public event EventHandler AccessTokenUpdated; +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - public void NotifyAccessTokenUpdated() => AccessTokenUpdated.Invoke(this, EventArgs.Empty); + public void NotifyAccessTokenUpdated() => AccessTokenUpdated.Invoke(this, EventArgs.Empty); } From 35a60991dd8f61c3a438f7b09e9fdc028540a2be Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:31:35 +0200 Subject: [PATCH 3/7] cleanup: Providers.Blazot.Models.Author CS8618 -- Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. --- src/TagzApp.Providers.Blazot/Models/Author.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/TagzApp.Providers.Blazot/Models/Author.cs b/src/TagzApp.Providers.Blazot/Models/Author.cs index 822770dd..eb4679d7 100644 --- a/src/TagzApp.Providers.Blazot/Models/Author.cs +++ b/src/TagzApp.Providers.Blazot/Models/Author.cs @@ -1,9 +1,15 @@ namespace TagzApp.Providers.Blazot.Models; + +// TODO: Check CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public class Author { - public string UserName { get; set; } - public string DisplayName { get; set; } - public bool IsSubscriber { get; set; } - public int? SubscriptionLevel { get; set; } - public string ProfileImageUrl { get; set; } + + public string UserName { get; set; } + + public string DisplayName { get; set; } + public bool IsSubscriber { get; set; } + public int? SubscriptionLevel { get; set; } + public string ProfileImageUrl { get; set; } } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. \ No newline at end of file From accab8965fadec89c1474b4b9edb7df382863aed Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:33:47 +0200 Subject: [PATCH 4/7] cleanup: Providers.Blazot.Models.Transmission CS8618 -- Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. --- .../Models/Transmission.cs | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/TagzApp.Providers.Blazot/Models/Transmission.cs b/src/TagzApp.Providers.Blazot/Models/Transmission.cs index e6971eb9..a965b5fb 100644 --- a/src/TagzApp.Providers.Blazot/Models/Transmission.cs +++ b/src/TagzApp.Providers.Blazot/Models/Transmission.cs @@ -1,38 +1,43 @@ namespace TagzApp.Providers.Blazot.Models; - public class Transmission - { - /// - /// The unique identifier for the transmission. - /// - public Guid TransmissionId { get; set; } - - /// - /// The unique identifier for the parent transmission that this transmission is a response to. - /// - public Guid? ParentItemId { get; set; } - - /// - /// The UTC date/time this transmission was transmitted. - /// - public DateTime DateTransmitted { get; set; } - - /// - /// The transmission text. - /// - public string Body { get; set; } - - /// - /// The author object. - /// - public Author Author { get; set; } - - /// - /// Video or images within this transmission. - /// - public List Media { get; set; } - - public WebLink WebLink { get; set; } - - public Transmission RelayedTransmission { get; set; } +// TODO: Check CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +public class Transmission +{ + /// + /// The unique identifier for the transmission. + /// + public Guid TransmissionId { get; set; } + + /// + /// The unique identifier for the parent transmission that this transmission is a response to. + /// + public Guid? ParentItemId { get; set; } + + /// + /// The UTC date/time this transmission was transmitted. + /// + public DateTime DateTransmitted { get; set; } + + /// + /// The transmission text. + /// + + public string Body { get; set; } + + + /// + /// The author object. + /// + public Author Author { get; set; } + + /// + /// Video or images within this transmission. + /// + public List Media { get; set; } + + public WebLink WebLink { get; set; } + + public Transmission RelayedTransmission { get; set; } } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. \ No newline at end of file From 16f1fa834d283a55ef4731131f14577e6ce0d106 Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:35:24 +0200 Subject: [PATCH 5/7] cleanup: Providers.Blazot.Models.WebLink CS8618 -- Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. --- src/TagzApp.Providers.Blazot/Models/WebLink.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/TagzApp.Providers.Blazot/Models/WebLink.cs b/src/TagzApp.Providers.Blazot/Models/WebLink.cs index ee724410..e453049e 100644 --- a/src/TagzApp.Providers.Blazot/Models/WebLink.cs +++ b/src/TagzApp.Providers.Blazot/Models/WebLink.cs @@ -1,8 +1,14 @@ namespace TagzApp.Providers.Blazot.Models; + +// TODO: Check CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public class WebLink { - public string LinkUrl { get; set; } - public string ImageUrl { get; set; } - public string Title { get; set; } - public string Description { get; set; } + + public string LinkUrl { get; set; } + + public string ImageUrl { get; set; } + public string Title { get; set; } + public string Description { get; set; } } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. \ No newline at end of file From 9c4f0e4baa9218fc6ed8f3c7865f6b9729250ecf Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Tue, 5 Sep 2023 22:20:22 +0200 Subject: [PATCH 6/7] fix: workflow dotnet.yml --- .github/workflows/dotnet.yml | 151 +++++++++++++++++------------------ 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 4ae3a3a3..f42f7197 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -5,92 +5,91 @@ name: Build and Test .NET projects on: push: - branches: [ "main" ] - paths: [ "src/**" ] + branches: ["main"] + paths: ["src/**"] pull_request: - branches: [ "main" ] + branches: ["main"] types: [opened, synchronize, reopened, closed] - paths: [ "src/**" ] + paths: ["src/**"] workflow_dispatch: - branches: [ "main" ] - + branches: ["main"] jobs: build: - if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') - runs-on: self-hosted + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + runs-on: ubuntu-latest defaults: run: working-directory: ./src steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 7.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Unit Test - run: dotnet test --no-build --verbosity normal - working-directory: ./src/TagzApp.UnitTest + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Unit Test + run: dotnet test --no-build --verbosity normal + working-directory: ./src/TagzApp.UnitTest playwright: - if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') - name: 'Playwright Tests' - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./src/TagzApp.WebTest - timeout-minutes: 10 - container: - image: mcr.microsoft.com/playwright/dotnet:v1.37.1-jammy - options: --ipc=host - steps: - - uses: actions/checkout@v3 - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 7.0.x - - run: dotnet build - - name: Execute Playwright tests - env: - TestHostStartDelay: 1000 - run: dotnet test --no-build - image: - if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'FritzAndFriends') - name: 'Create docker image for Web' - runs-on: ubuntu-latest - needs: [playwright] - steps: - - uses: actions/checkout@v3 - - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y%m%d')" - - - name: Docker Login - uses: docker/login-action@v2.2.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker Metadata action - id: meta - uses: docker/metadata-action@v4.6.0 - with: - images: ghcr.io/${{ github.repository }} - tags: | - latest - ${{ steps.date.outputs.date }}.${{ github.run_attempt }} + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + name: "Playwright Tests" + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./src/TagzApp.WebTest + timeout-minutes: 10 + container: + image: mcr.microsoft.com/playwright/dotnet:v1.37.1-jammy + options: --ipc=host + steps: + - uses: actions/checkout@v3 + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - run: dotnet build + - name: Execute Playwright tests + env: + TestHostStartDelay: 1000 + run: dotnet test --no-build + image: + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'FritzAndFriends') + name: "Create docker image for Web" + runs-on: ubuntu-latest + needs: [playwright] + steps: + - uses: actions/checkout@v3 + + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y%m%d')" + + - name: Docker Login + uses: docker/login-action@v2.2.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker Metadata action + id: meta + uses: docker/metadata-action@v4.6.0 + with: + images: ghcr.io/${{ github.repository }} + tags: | + latest + ${{ steps.date.outputs.date }}.${{ github.run_attempt }} - - uses: docker/build-push-action@v4.1.1 - with: - context: . - file: ./src/TagzApp.Web/dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - build-args: | - Build_Version: ${{ steps.date.outputs.date }}.${{ github.run_attempt }} + - uses: docker/build-push-action@v4.1.1 + with: + context: . + file: ./src/TagzApp.Web/dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + build-args: | + Build_Version: ${{ steps.date.outputs.date }}.${{ github.run_attempt }} From ebdc18f3c50f2643bdb9299b3e5bb966fdca5085 Mon Sep 17 00:00:00 2001 From: Stelzi79 <969932+Stelzi79@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:20:26 +0200 Subject: [PATCH 7/7] reverting any changes to dotnet.yml --- .github/workflows/dotnet.yml | 91 +++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d942c13b..475b49b6 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -16,7 +16,7 @@ on: jobs: build: - if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') needs: [code-formatting] runs-on: ubuntu-latest defaults: @@ -38,6 +38,7 @@ jobs: playwright: if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + needs: [code-formatting] name: "Playwright Tests" runs-on: ubuntu-latest defaults: @@ -94,3 +95,91 @@ jobs: tags: ${{ steps.meta.outputs.tags }} build-args: | Build_Version: ${{ steps.date.outputs.date }}.${{ github.run_attempt }} + + code-formatting: + if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get git diff + id: diff + run: | + git fetch origin main + { + echo 'files<> "$GITHUB_OUTPUT" + + - name: Get changed C# files + id: changed_cs + run: | + { + echo 'files<> "$GITHUB_OUTPUT" + - name: Add formatting rules to .editorconfig + if: steps.changed_cs.outputs.files != '' + run: | + echo "" >> src/.editorconfig + echo "[*.cs]" >> src/.editorconfig + echo "dotnet_diagnostic.IDE0005.severity = error" >> src/.editorconfig # Remove unnecessary using directives + echo "dotnet_diagnostic.IDE0090.severity = error" >> src/.editorconfig # Simplify new expression + echo "dotnet_diagnostic.IDE0003.severity = error" >> src/.editorconfig # this and Me preferences + echo "dotnet_diagnostic.IDE0009.severity = error" >> src/.editorconfig # this and Me preferences + - name: Setup .NET + if: steps.changed_cs.outputs.files != '' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + - name: Run dotnet format + if: steps.changed_cs.outputs.files != '' + id: dotnet-format + run: | + echo "Running dotnet format on: ${{ steps.changed_cs.outputs.files }}" + result=$(dotnet format src/TagzApp.sln --verbosity normal --exclude src/TagzApp.Web/Migrations --include ${{ steps.changed_cs.outputs.files }}) + echo "Format result:" + echo "$result" + count=$(echo "$result" | grep -c "Formatted code file" || true) + echo "Number of files Format formatted: $count" + echo "count=$count" >> "$GITHUB_OUTPUT" + + - name: Get changed JS/CSS files + id: changed_js_css + run: | + { + echo 'files<> "$GITHUB_OUTPUT" + - name: Setup Node + if: steps.changed_js_css.outputs.files != '' + uses: actions/setup-node@v3 + with: + node-version: lts/* + - name: Run prettier + if: steps.changed_js_css.outputs.files != '' + id: prettier + run: | + echo "Running prettier on: ${{ steps.changed_js_css.outputs.files }}" + npm install prettier + result=$(npx prettier --write --list-different ${{ steps.changed_js_css.outputs.files }}) + echo "Prettier result:" + echo "$result" + count=$(echo "$result" | grep -cE "\.(js|css)$" || true) + echo "Number of files Prettier formatted: $count" + echo "count=$count" >> "$GITHUB_OUTPUT" + + - name: Commit if changes + if: steps.prettier.outputs.count > 0 || steps.dotnet-format.outputs.count > 0 + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + git add *.cs *.js *.css + echo "$(git status)" + git commit -m "Applying formatting changes through GitHub Actions" + git push origin HEAD:${{ github.head_ref }}