From af3ec2e2ab37f947941820b131959f1a9e135397 Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Tue, 24 Jan 2023 18:46:07 +0330 Subject: [PATCH] try for build-publish --- .github/workflows/build-publish.yml | 56 ++++++++++++++----- .github/workflows/dotnet.yml | 40 ++++++++----- .../Data/PersistMessageDbContext.cs | 31 +++++++--- 3 files changed, 93 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index e4babc3..45409fe 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -1,23 +1,53 @@ -name: Build and Push Docker Image +name: build-publish + on: + # run it on push to the default repository branch push: - branches: - - develop + branches: [develop] + # run it during pull request + pull_request: [develop] jobs: - build_and_push: + # define job to build and publish docker image + build-and-push-docker-image: + name: Build Docker image and push to repositories + # run only when code is compiling and tests are passing runs-on: ubuntu-latest + # steps to perform in job steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v3 - - name: Build Docker Image - run: | - docker build -t myimage:${{ github.sha }} -f ./src/Services/Flight/Dockerfile . + # setup Docker buld action + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Push to Docker Hub - run: docker push myimage:${{ github.sha }} + - name: Login to Github Packages + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build image and push to Docker Hub and GitHub Container Registry + uses: docker/build-push-action@v2 + with: + # relative path to the place where source code with Dockerfile is located + context: ./src/Services/Flight + # Note: tags has to be all lower-case + tags: | + meysamhadeli/booking-microservices/flight:latest + ghcr.io/meysamhadeli/booking-microservices/flight:latest + # build on feature branches, push only on develop branch + push: ${{ github.ref == 'refs/heads/develop' }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 731b8af..efda479 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -2,9 +2,9 @@ name: Build-Test on: push: - branches: [ "main" , "develop"] + branches: [ "main" , "develop" ] paths-ignore: - - "README.md" + - "README.md" pull_request: branches: [ "main" , "develop" ] @@ -14,15 +14,29 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v2 - with: - dotnet-version: 7.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build -c Release --no-restore - - name: Test - run: dotnet test -c Release --no-restore + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v2 + with: + dotnet-version: 7.0.x + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 'lts/*' + + - name: Cache NuGet Packages + uses: actions/cache@v3 + with: + key: ${{ runner.os }}-dotnet-nuget + path: ~/.nuget/packages + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build -c Release --no-restore + + - name: Test + run: dotnet test -c Release --no-restore diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/PersistMessageDbContext.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/PersistMessageDbContext.cs index 0b4df06..37a45cf 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/PersistMessageDbContext.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/PersistMessageDbContext.cs @@ -12,9 +12,17 @@ using Exception = System.Exception; public class PersistMessageDbContext : DbContext, IPersistMessageDbContext { + private readonly Lazy> _logger; + public PersistMessageDbContext(DbContextOptions options) : base(options) { + _logger = new Lazy>(() => + { + var factory = LoggerFactory.Create(b => b.AddConsole()); + var logger = factory.CreateLogger(); + return logger; + }); } public DbSet PersistMessages => Set(); @@ -37,10 +45,7 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext { if (exception != null) { - var factory = LoggerFactory.Create(b => b.AddConsole()); - var logger = factory.CreateLogger(); - - logger.LogError(exception, + _logger.Value.LogError(exception, "Request failed with {StatusCode}. Waiting {TimeSpan} before next retry. Retry attempt {RetryCount}.", HttpStatusCode.Conflict, timeSpan, @@ -55,12 +60,22 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext { foreach (var entry in ex.Entries) { - var currentEntity = entry.Entity; // we can use it for specific merging - var databaseValues = await entry.GetDatabaseValuesAsync(cancellationToken); + var currentValue = entry.Entity; // we can use it for specific merging + var databaseValue = await entry.GetDatabaseValuesAsync(cancellationToken); - if (databaseValues != null) + _logger.Value.LogInformation( + "Entry to entity with type: {Type}, database-value: {DatabaseValue} and current-value: {CurrentValue}", + entry.GetType().Name, + databaseValue, + currentValue); + + if (databaseValue != null) { - entry.OriginalValues.SetValues(databaseValues); + entry.OriginalValues.SetValues(databaseValue); + } + else + { + entry.OriginalValues.SetValues(currentValue); } }