From 73bf54f8f9b94dc1e7b4ef57418f372a19636a97 Mon Sep 17 00:00:00 2001 From: David Thompson <47348983+DavidAtBede@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:45:28 +0100 Subject: [PATCH] [Patch] [DX-375] Add GHA Workflow (DX automation) --- .github/workflows/workflow.yml | 220 +++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..c91baf4 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,220 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + pull_request: + branches: + - develop + - hotfix(es)/** + push: + branches: + - develop + - hotfix(es)/** + workflow_dispatch: + +jobs: + build: + runs-on: arc-runner + permissions: + contents: write + checks: write + pull-requests: write + outputs: + build-version: ${{ steps.semver.outputs.version }} + od-package-name-api: ${{ steps.od-package-api.outputs.od-package-name }} + od-package-name-service: ${{ steps.od-package-service.outputs.od-package-name }} + + services: + sqlserver: + image: mcr.microsoft.com/mssql/server + env: + ACCEPT_EULA: Y + MSSQL_SA_PASSWORD: Testing123! + ports: + - 1433:1433 + options: >- + --health-cmd "opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U sa -P Testing123! -Q 'CREATE DATABASE [Test]' " + --health-interval 3s + --health-timeout 5s + --health-retries 20 + steps: + - name: Install Prerequisites + run: | + sudo apt-get update + sudo apt-get install curl libevent-dev git jq -y + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + env: + DOTNET_INSTALL_DIR: ./ + + - name: SemVer + id: semver + uses: BedeGaming/gha-semver@v1 + with: + default-branch: develop + + - name: json rewrite action step + id: json-rewrite + uses: BedeGaming/gha-rewrite-json@initial-version + with: + input-file-pattern: './src/**/*.Tests.**/appsettings.json' + json-data: + '{ + "Db.ConnectionStringTemplate": "Data Source=localhost,1433;Initial Catalog=Test;User=sa;Password=Testing123!;" + }' + + - name: Nuget Cache + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- + - name: Restore + working-directory: ./src + run: dotnet restore --configfile "Nuget.Config" + + - name: Build + working-directory: ./src + run: dotnet build --no-restore -c Release -p:Version=${{ steps.semver.outputs.version }} + + - name: Test + working-directory: ./src + run: dotnet test --no-build -c Release --logger "trx;LogFileName=test-results.trx;verbosity=detailed" --collect:"XPlat Code Coverage" -m:1 -p:Exclude=\"[*Test*]*%2c[*]*Swagger*\" -p:Version=${{ steps.semver.outputs.version }} + + - name: Generate Test Reports + if: ${{ !cancelled() }} + uses: bedegaming/gha-test-reports@v1 + with: + tag: ${{ steps.semver.outputs.version }} + include-code-coverage: true + + - name: Upload nugets as artifacts + uses: actions/upload-artifact@v4 + with: + name: nugets + path: 'src/**/*.nupkg' + if-no-files-found: error + compression-level: 0 + + - name: Create API package for OD + id: od-package-api + uses: BedeGaming/gha-package-for-od@v1 + with: + app-name: 'bede-loyalty-api' # 'bede-loyalty-api' + app-folder: 'src/Bede.Loyalty.Api' # 'src/Bede.Loyalty.Api' + package-version: ${{ steps.semver.outputs.version }} + - name: Upload API package for OD as artifact + uses: actions/upload-artifact@v4 + with: + name: od-package-api + path: ${{ steps.od-package-api.outputs.od-package-path }} + if-no-files-found: error + compression-level: 0 + + - name: Create Service package for OD + id: od-package-service + uses: BedeGaming/gha-package-for-od@v1 + with: + app-name: 'bede-loyalty-service' # 'bede-loyalty-service' + app-folder: 'src/Bede.Loyalty.Service' # 'src/Bede.Loyalty.Service' + package-version: ${{ steps.semver.outputs.version }} + - name: Upload Service package for OD as artifact + uses: actions/upload-artifact@v4 + with: + name: od-package-service + path: ${{ steps.od-package-service.outputs.od-package-path }} + if-no-files-found: error + compression-level: 0 + + docker_publish_api: + needs: build + runs-on: arc-runner + steps: + - name: docker build and publish + uses: BedeGaming/gha-docker-build-and-publish@v1 + with: + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + dockerfile: '@{docker-api-dockerfile-path}' # Bede.Loyalty.Api/Dockerfile + image-name: '@{docker-api-image-name}' # + image-version: ${{ needs.build.outputs.build-version }} + + + docker_publish_service: + needs: build + runs-on: arc-runner + steps: + - name: docker build and publish + uses: BedeGaming/gha-docker-build-and-publish@v1 + with: + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + dockerfile: 'Bede.Loyalty.Service/Dockerfile' # Bede.Loyalty.Service/Dockerfile + image-name: 'bede-loyalty-service' # bede-loyalty-service + image-version: ${{ needs.build.outputs.build-version }} + + + nuget_publish: + runs-on: arc-runner + needs: build + steps: + - name: nuget publish + uses: BedeGaming/gha-nuget-publish@v1 + with: + artifact-name: nugets + api-key: ${{ secrets.NEXUS_API_KEY }} + + + od_publish_api: + runs-on: arc-runner + needs: + - build + - docker_publish_api + - docker_publish_service + - nuget_publish + steps: + - name: Push API packages to OD + uses: BedeGaming/gha-od-publish-package@v1 + with: + artifact-name: od-package-api + od-api-key: ${{ secrets.OD_API_KEY }} + od-package: ${{ needs.build.outputs.od-package-name-api }} + + od_publish_service: + runs-on: arc-runner + needs: + - build + - docker_publish_api + - docker_publish_service + - nuget_publish + steps: + - name: Push Service packages to OD + uses: BedeGaming/gha-od-publish-package@v1 + with: + artifact-name: od-package-service + od-api-key: ${{ secrets.OD_API_KEY }} + od-package: ${{ needs.build.outputs.od-package-name-service }} + + od_create_release: + runs-on: arc-runner + needs: + - build + - od_publish_api + - od_publish_service + steps: + - name: Create OD Release + uses: BedeGaming/gha-od-create-release@v1 + with: + od-api-key: ${{ secrets.OD_API_KEY }} + od-project: 'Bede.loyalty' # Bede.Loyalty + version: ${{ needs.build.outputs.build-version }}