Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Update pipelines / changes in git version and branch name

Krzysztof Pajak3d4666ae403c
diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
new file mode 100644
index 000000000..c66ab796c
--- /dev/null
+++ b/.github/workflows/docker-image.yml
@@ -0,0 +1,40 @@
+name: Docker Image CI
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+
+ build:
+
+ runs-on: ubuntu-latest
+ name: Build image
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - id: Commit
+ name: Commit-tag
+ uses: pr-mpt/actions-commit-hash@v2
+ - name: Buildx
+ id: buildx
+ uses: docker/setup-buildx-action@v1
+
+ - name: Login to Docker Hub
+ uses: docker/login-action@v2
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_PASS }}
+
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: .
+ build-args: |
+ GIT_COMMIT=${{ steps.commit.outputs.long }}
+ GIT_BRANCH=master
+ push: true
+ tags: grandnode/grandnode2:latest
\ No newline at end of file
diff --git a/.github/workflows/grandnode.yml b/.github/workflows/grandnode.yml
index 297ca8d82..84d39cc9d 100644
--- a/.github/workflows/grandnode.yml
+++ b/.github/workflows/grandnode.yml
@@ -1,8 +1,6 @@
name: Build and deploy .NET Core app to Linux WebApp grandnode
-on:
- push:
- branches:
- - master
+on: [push]
+
env:
AZURE_WEBAPP_NAME: grandnode-dev
AZURE_WEBAPP_PACKAGE_PATH: src/Web/Grand.Web/publish
@@ -26,7 +24,7 @@ jobs:
- name: Build sln
run: dotnet build "GrandNode.sln"
- name: Build
- run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
+ run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore -p:SourceRevisionId=${{ GITHUB_SHA }} -p:GitBranch=${GITHUB_REF#refs/heads/}
- name: Grand.Business.Authentication Unit Tests
run: dotnet test ./src/Tests/Grand.Business.Authentication.Tests/Grand.Business.Authentication.Tests.csproj
- name: Grand.Business.Catalog Unit Tests
@@ -56,7 +54,7 @@ jobs:
- name: Grand.SharedKernel.Tests Unit Tests
run: dotnet test ./src/Tests/Grand.SharedKernel.Tests/Grand.SharedKernel.Tests.csproj
- name: Publish
- run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
+ run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}" -p:SourceRevisionId=${{ GITHUB_SHA }} -p:GitBranch=${GITHUB_REF#refs/heads/}
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v2
with:
diff --git a/Dockerfile b/Dockerfile
index a093df187..5cee47667 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,25 +5,28 @@ WORKDIR /app
# Copy and build
COPY ./src /app
+ARG GIT_COMMIT
+ARG GIT_BRANCH
+
# build plugins
-RUN dotnet build /app/Plugins/Authentication.Facebook -c Release
-RUN dotnet build /app/Plugins/Authentication.Google -c Release
-RUN dotnet build /app/Plugins/DiscountRules.Standard -c Release
-RUN dotnet build /app/Plugins/ExchangeRate.McExchange -c Release
-RUN dotnet build /app/Plugins/Payments.BrainTree -c Release
-RUN dotnet build /app/Plugins/Payments.CashOnDelivery -c Release
-RUN dotnet build /app/Plugins/Payments.PayPalStandard -c Release
-RUN dotnet build /app/Plugins/Shipping.ByWeight -c Release
-RUN dotnet build /app/Plugins/Shipping.FixedRateShipping -c Release
-RUN dotnet build /app/Plugins/Shipping.ShippingPoint -c Release
-RUN dotnet build /app/Plugins/Tax.CountryStateZip -c Release
-RUN dotnet build /app/Plugins/Tax.FixedRate -c Release
-RUN dotnet build /app/Plugins/Widgets.FacebookPixel -c Release
-RUN dotnet build /app/Plugins/Widgets.GoogleAnalytics -c Release
-RUN dotnet build /app/Plugins/Widgets.Slider -c Release
+RUN dotnet build /app/Plugins/Authentication.Facebook -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Authentication.Google -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/DiscountRules.Standard -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/ExchangeRate.McExchange -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Payments.BrainTree -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Payments.CashOnDelivery -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Payments.PayPalStandard -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Shipping.ByWeight -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Shipping.FixedRateShipping -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Shipping.ShippingPoint -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Tax.CountryStateZip -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Tax.FixedRate -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Widgets.FacebookPixel -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Widgets.GoogleAnalytics -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
+RUN dotnet build /app/Plugins/Widgets.Slider -c Release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
# build Web
-RUN dotnet publish /app/Web/Grand.Web -c Release -o ./build/release
+RUN dotnet publish /app/Web/Grand.Web -c Release -o ./build/release -p:SourceRevisionId=$GIT_COMMIT -p:GitBranch=$GIT_BRANCH
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index c7d721376..cda69941b 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -57,17 +57,6 @@ steps:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
-# disabled
-#- task: Docker@2
-# displayName: 'Build and push to dockerhub'
-# inputs:
-# containerRegistry: 'DockerHub'
-# repository: 'grandnode/grandnode2'
-# command: 'buildAndPush'
-# tags: |
-# latest
-# Dockerfile: '**/Dockerfile'
-
- task: DotNetCoreCLI@2
inputs:
command: publish
diff --git a/src/Build/Grand.Common.props b/src/Build/Grand.Common.props
index 1912e2c06..b124f24ba 100644
--- a/src/Build/Grand.Common.props
+++ b/src/Build/Grand.Common.props
@@ -18,4 +18,17 @@
<Using Include="System.Threading"/>
<Using Include="System.Threading.Tasks"/>
</ItemGroup>
+ <Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
+ <Exec Command="git describe --long --always --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="True">
+ <Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
+ </Exec>
+ </Target>
+ <Target Name="SetRepositoryBranch" BeforeTargets="InitializeSourceControlInformation">
+ <Exec Command="git rev-parse --abbrev-ref HEAD" ConsoleToMSBuild="True" IgnoreExitCode="True">
+ <Output PropertyName="GitBranch" TaskParameter="ConsoleOutput" />
+ </Exec>
+ <ItemGroup>
+ <AssemblyMetadata Include="BranchName" Value="$(GitBranch)" />
+ </ItemGroup>
+ </Target>
</Project>
diff --git a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
index 52ec0d06f..a7564f2b0 100644
--- a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
+++ b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="..\..\Build\Grand.Common.props" />
+ <Import Project="..\..\Build\Grand.Common.props" />
<ItemGroup>
- <PackageReference Include="GitInfo" Version="3.0.4">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
- </PackageReference>
<PackageReference Include="GoogleAuthenticator" Version="3.0.0" />
<PackageReference Include="MassTransit" Version="8.0.12" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.12" />
diff --git a/src/Core/Grand.Infrastructure/GrandVersion.cs b/src/Core/Grand.Infrastructure/GrandVersion.cs
index 6faa5f5ee..36ca00a6d 100644
--- a/src/Core/Grand.Infrastructure/GrandVersion.cs
+++ b/src/Core/Grand.Infrastructure/GrandVersion.cs
@@ -1,8 +1,9 @@
-namespace Grand.Infrastructure
+using System.Reflection;
+
+namespace Grand.Infrastructure
{
public static class GrandVersion
{
-
/// <summary>
/// Gets the major version
/// </summary>
@@ -36,11 +37,42 @@
/// <summary>
/// Gets the git branch
/// </summary>
- public const string GitBranch = ThisAssembly.Git.Branch;
-
+ public static string GitBranch = GetGitBranch();
+
/// <summary>
/// Gets the git commit
/// </summary>
- public const string GitCommit = ThisAssembly.Git.Commit;
+ public static string GitCommit = GetGitHash();
+
+ private static string GetGitHash()
+ {
+ if (!string.IsNullOrEmpty(_gitHash)) return _gitHash;
+
+ var version = "1.0.0+LOCALBUILD";
+ var appAssembly = typeof(GrandVersion).Assembly;
+ var infoVerAttr = (AssemblyInformationalVersionAttribute)appAssembly
+ .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute)).FirstOrDefault();
+ if (infoVerAttr is { InformationalVersion.Length: > 6 })
+ {
+ version = infoVerAttr.InformationalVersion;
+ }
+ _gitHash = version[(version.IndexOf('+') + 1)..];
+ return _gitHash;
+ }
+
+ private static string _gitHash { get; set; }
+
+ private static string GetGitBranch()
+ {
+ if (!string.IsNullOrEmpty(_gitBranch)) return _gitBranch;
+
+ var appAssembly = typeof(GrandVersion).Assembly;
+ var infoBranchAttr = appAssembly.GetCustomAttributes(typeof(AssemblyMetadataAttribute))
+ .FirstOrDefault(x => ((AssemblyMetadataAttribute)x).Key == "BranchName");
+ _gitBranch = infoBranchAttr != null ? ((AssemblyMetadataAttribute)infoBranchAttr).Value : "UNKNOWN";
+ return _gitBranch;
+ }
+
+ private static string _gitBranch { get; set; }
}
-}
+}
\ No newline at end of file