-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mehdihadeli
committed
Jan 20, 2023
1 parent
0c39a1f
commit 7fd3394
Showing
93 changed files
with
568 additions
and
260 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Build dotnet application | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dotnet-version: | ||
description: Version of dotnet to use | ||
type: string | ||
default: 7.X.x | ||
|
||
runs-on: | ||
description: Platform to execute on | ||
type: string | ||
default: ubuntu-latest | ||
|
||
project-folder: | ||
description: The folder containing the project to build | ||
type: string | ||
default: . | ||
|
||
run-tests: | ||
description: Run tests | ||
type: boolean | ||
default: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
name: Reusable deployment workflow | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment_name: | ||
type: string | ||
description: environment to deploy to | ||
required: true | ||
environment_tag: | ||
type: string | ||
description: environment tag fo publishing | ||
required: true | ||
secrets: | ||
token: | ||
required: true | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy to ${{ inputs.environment_name }} | ||
runs-on: ubuntu-latest | ||
|
||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif | ||
if: ${{ contains(fromJson('["develop", "devops/ci", "main", "beta", "preview"]'), github.ref_name) && github.event_name != 'pull_request' }} | ||
|
||
# https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment | ||
environment: | ||
name: ${{ inputs.environment_name }} | ||
# url: ${{ steps.deploy-to-heroku.outputs.webapp-url }} | ||
|
||
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs | ||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions | ||
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions | ||
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio | ||
permissions: | ||
contents: write # to be able to publish a GitHub release | ||
issues: write # to be able to comment on released issues | ||
pull-requests: write # to be able to comment on released pull requests | ||
packages: write # for publishing packages | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
|
||
- 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: create output dir | ||
run: mkdir "output" | ||
|
||
# https://github.com/actions/download-artifact#download-all-artifacts | ||
# download artifacts without name will download all artifacts | ||
- name: Download All Artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: artifacts | ||
|
||
- name: dir | ||
run: ls -R "${{ github.workspace }}/artifacts/build-test-artifacts" | ||
|
||
# https://askubuntu.com/questions/86849/how-to-unzip-a-zip-file-from-the-terminal | ||
- name: unzip artifacts | ||
run: | | ||
unzip "artifacts/build-test-artifacts/test-results.zip" -d "output" | ||
- name: Ls Output Files | ||
if: success() | ||
run: ls -R ${{ github.workspace }}/output | ||
|
||
# merging all coverage in a single coverage file and generating html files for downloading as artifacts | ||
- name: Publish coverage report to coveralls.io | ||
if: success() | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.token }} | ||
path-to-lcov: "output/test-results/lcov.info" | ||
|
||
# https://thecodinganalyst.github.io/knowledgebase/Basic-guide-to-Semantic-Release/ | ||
# https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b | ||
# https://github.com/michael-wolfenden/Cake.Npx/blob/master/src/Cake.Npx.Tests/NpxAliasesTests.cs#L59 | ||
# https://medium.com/@michael.wolfenden/simplified-versioning-and-publishing-for-net-libraries-a28e5e740fa6 | ||
# https://github.com/semantic-release/semantic-release/issues/753#issuecomment-706971174 | ||
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions | ||
# will assmblies versions and push them to git | ||
- name: Semantic Release | ||
id: semantic | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.token }} | ||
# because of using none default (conventionalcommits) `preset` for `semantic-release`, we should add dependency `conventional-changelog-conventionalcommits` | ||
run: npx -p conventional-changelog-conventionalcommits -p @semantic-release/git -p @semantic-release/changelog -p @semantic-release/exec semantic-release | ||
|
||
- name: Semantic Release Outputs | ||
run: | | ||
echo ${{ steps.semantic.outputs.semantic_nextRelease_version }} | ||
echo ${{ steps.semantic.outputs.semantic_nextRelease_channel }} | ||
echo ${{ steps.semantic.outputs.semantic_nextRelease_gitTag }} | ||
echo ${{ steps.semantic.outputs.semantic_lastRelease_version }} | ||
echo ${{ steps.semantic.outputs.semantic_lastRelease_channel }} | ||
echo ${{ steps.semantic.outputs.semantic_lastRelease_gitTag }} | ||
- name: Restore NuGet packages | ||
continue-on-error: false | ||
run: dotnet restore | ||
|
||
# https://garywoodfine.com/how-to-use-github-actions-to-build-deploy-github-nuget-packages/ | ||
# https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-7.0#the-dockerfile | ||
# or calling dotnet publish on solution - we marked `publishable` and `packable` projects in their .csproj | ||
- name: dotnet publish | ||
continue-on-error: false | ||
id: publish-services | ||
if: success() | ||
run: | | ||
dotnet publish -c Release --no-restore ${{ env.CATALOG_SVC_PATH }} -o ${{ github.workspace }}/output/publish-services/Catalogs /p:Version=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:AssemblyVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:InformationalVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} | ||
dotnet publish -c Release --no-restore ${{ env.CUSTOMERS_SVC_PATH }} -o ${{ github.workspace }}/output/publish-services/Customers /p:Version=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:AssemblyVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:InformationalVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} | ||
dotnet publish -c Release --no-restore ${{ env.IDENTITY_SVC_PATH }} -o ${{ github.workspace }}/output/publish-services/Identity /p:Version=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:AssemblyVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} /p:InformationalVersion=${{ steps.semantic.outputs.semantic_nextRelease_version }} | ||
# https://unix.stackexchange.com/questions/57013/zip-all-files-in-directory | ||
# https://limeii.github.io/2022/11/deploy-to-azure-appservice-with-github-actions/ | ||
# https://stackoverflow.com/questions/68470162/how-to-archive-files-in-artifact-for-github-workflow-actions-in-order-to-fix-thi | ||
# note: we should zip inner (publish-services) folder and for doing this we use `cd output` first then zip | ||
# `publish-services/*` folder, otherwise with zip `output/publish-services` it zip output folder and inner `publish-services`folder together | ||
- name: Zip publish-services Artifacts | ||
run: | | ||
cd output | ||
zip -r publish-services.zip publish-services/* | ||
# https://github.com/actions/runner/issues/946#issuecomment-900193569 | ||
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context | ||
- name: Ls Output Files | ||
if: success() | ||
run: ls -R | ||
working-directory: ${{ github.workspace }}/output | ||
|
||
- name: Upload Publish Services Artifacts For Deployment Jobs | ||
uses: actions/upload-artifact@v3 | ||
if: (steps.publish-services.outcome == 'success') | ||
with: | ||
name: publish-services | ||
retention-days: 1 | ||
path: | | ||
output/publish-services.zip | ||
# https://docs.docker.com/engine/reference/commandline/build/ | ||
# https://dev.to/willvelida/pushing-container-images-to-github-container-registry-with-github-actions-1m6b | ||
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio | ||
- name: docker build | ||
run: | | ||
docker build . --tag ${{ env.REGISTRY }}/${{ github.repository }}/catalogs-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} -f "${{ github.workspace }}/src/Services/Catalogs/Dockerfile" | ||
docker build . --tag ${{ env.REGISTRY }}/${{ github.repository }}/customers-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} -f "${{ github.workspace }}/src/Services/Customers/Dockerfile" | ||
docker build . --tag ${{ env.REGISTRY }}/${{ github.repository }}/identity-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} -f "${{ github.workspace }}/src/Services/Identity/Dockerfile" | ||
- name: 'Login to GitHub Container Registry' | ||
uses: docker/login-action@v1 | ||
if: success() | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.token }} | ||
|
||
- name: docker publish | ||
if: success() | ||
run: | | ||
docker push ghcr.io/${{ github.repository }}/catalogs-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} | ||
docker push ghcr.io/${{ github.repository }}/customers-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} | ||
docker push ghcr.io/${{ github.repository }}/identity-service:${{ steps.semantic.outputs.semantic_nextRelease_version }}${{ inputs.environment_tag }} | ||
# release-production: | ||
# if: ${{ contains(fromJson('["main", "beta", "preview"]'), github.ref_name) }} | ||
# runs-on: ubuntu-latest | ||
# # https://docs.github.com/en/actions/using-workflows/about-workflows#creating-dependent-jobs | ||
# needs: build-test | ||
# environment: production | ||
# | ||
# steps: | ||
# # https://github.com/actions/download-artifact#download-all-artifacts | ||
# - name: Download Artifacts | ||
# uses: actions/download-artifact@v3 | ||
# with: | ||
# path: artifacts | ||
# | ||
# # merging all coverage in a single coverage file and generating html files for downloading as artifacts | ||
# - name: Publish coverage report to coveralls.io | ||
# uses: coverallsapp/github-action@master | ||
# with: | ||
# github-token: ${{ secrets.token }} | ||
# path-to-lcov: 'artifacts/test-results/lcov.info' | ||
# | ||
# # - name: publish docker image | ||
# # run: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"yaml.schemas": { | ||
"https://json.schemastore.org/github-workflow.json": "file:///d%3A/Github/ecommerce-microservices-sample/.github/workflows/composite/deploy/deploy.yml" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/BuildingBlocks/BuildingBlocks.Core/CQRS/MediatRExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/BuildingBlocks/BuildingBlocks.Core/Messaging/Extensions/HeadersExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/BuildingBlocks/BuildingBlocks.Core/Messaging/Extensions/MessageEnvelopeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/BuildingBlocks/BuildingBlocks.Core/Messaging/Extensions/MessageExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/BuildingBlocks/BuildingBlocks.Core/Persistence/EventStore/StreamEventExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.