From 76462a82d0bd1b2aa1095b30a4c47cbeb1cb4862 Mon Sep 17 00:00:00 2001 From: Kurt Monge Date: Thu, 7 Nov 2024 19:50:07 +0100 Subject: [PATCH] #722: Optimized CI/CD for all envs. --- .../workflows/CI-CD-Feedpoller-function.yaml | 95 +++++++++++++++++++ .../prod-build_n_deploy-feedpoller-func.yml | 47 --------- .../test-build_n_deploy-feedpoller-func.yml | 47 --------- 3 files changed, 95 insertions(+), 94 deletions(-) create mode 100644 .github/workflows/CI-CD-Feedpoller-function.yaml delete mode 100644 .github/workflows/prod-build_n_deploy-feedpoller-func.yml delete mode 100644 .github/workflows/test-build_n_deploy-feedpoller-func.yml diff --git a/.github/workflows/CI-CD-Feedpoller-function.yaml b/.github/workflows/CI-CD-Feedpoller-function.yaml new file mode 100644 index 0000000..c1151bd --- /dev/null +++ b/.github/workflows/CI-CD-Feedpoller-function.yaml @@ -0,0 +1,95 @@ +name: CI/CD feedpoller-func + +on: + push: + branches: + - main + +env: + DOTNET_VERSION: '6.0.x' # Global environment variables + TEST_FUNC_NAME: 'oed-test-feedpoller-func' + PROD_FUNC_NAME: 'oed-feedpoller-func' + +jobs: + build: + name: Build and Test + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: GitHub metadata + run: | + echo "$GITHUB_REPOSITORY on $GITHUB_REF_NAME by $GITHUB_ACTOR" + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet publish -c Release -o ./publish + + - name: Run Tests + run: dotnet test --verbosity normal + + - name: Upload Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: published-artifacts + path: ./publish/ + + deploy-to-test: + name: Deploy to Test Environment + needs: build + runs-on: ubuntu-latest + environment: + name: test + + steps: + - name: Download Build Artifacts + uses: actions/download-artifact@v3 + with: + name: published-artifacts + path: ./publish/ + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1 + id: deploy-to-function + with: + app-name: '${{ env.TEST_FUNC_NAME }}' + slot-name: 'Production' + package: "${{env.GITHUB_WORKSPACE}}/publish/" + publish-profile: ${{ secrets.PUBLISH_PROFILE }} + + deploy-to-prod: + name: Deploy to Production Environment + needs: deploy-to-test + runs-on: ubuntu-latest + environment: + name: production + + steps: + - name: Await Manual Approval + if: ${{ github.ref == 'refs/heads/main' }} + run: | + echo "Waiting for manual approval" + echo "::pause::" + - name: Download Build Artifacts + uses: actions/download-artifact@v3 + with: + name: published-artifacts + path: ./publish/ + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1 + id: deploy-to-function + with: + app-name: '${{ env.PROD_FUNC_NAME}}' + slot-name: 'Production' + package: "${{env.GITHUB_WORKSPACE}}/publish/" + publish-profile: ${{ secrets.PUBLISH_PROFILE }} diff --git a/.github/workflows/prod-build_n_deploy-feedpoller-func.yml b/.github/workflows/prod-build_n_deploy-feedpoller-func.yml deleted file mode 100644 index b015bf0..0000000 --- a/.github/workflows/prod-build_n_deploy-feedpoller-func.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Build and deploy feedpoller-func to production - -on: - push: - branches: - - main - workflow_dispatch: - -env: - DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use - -jobs: - build-and-deploy: - runs-on: windows-latest - environment: Production - steps: - - name: 'Checkout GitHub Action' - uses: actions/checkout@v4 - - - name: Skriv ut GitHub metadata - run: | - echo "Repo: $GITHUB_REPOSITORY" - echo "Branch: $GITHUB_REF_NAME" - echo "Commit SHA: $GITHUB_SHA" - echo "Actor: $GITHUB_ACTOR" - echo "Run #: $GITHUB_RUN_NUMBER" - - - name: Set up .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - include-prerelease: true - - - name: dotnet publish - run: dotnet publish -c Release -o "${{env.GITHUB_WORKSPACE}}\myapp" - - - name: 'Run Azure Functions Action' - uses: Azure/functions-action@v1 - id: deploy-to-function - with: - app-name: 'oed-test-feedpoller-func' - slot-name: 'Production' - package: "${{env.GITHUB_WORKSPACE}}\\myapp" - publish-profile: ${{ secrets.PUBLISH_PROFILE }} diff --git a/.github/workflows/test-build_n_deploy-feedpoller-func.yml b/.github/workflows/test-build_n_deploy-feedpoller-func.yml deleted file mode 100644 index 61b0fb7..0000000 --- a/.github/workflows/test-build_n_deploy-feedpoller-func.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Build and deploy feedpoller-func to test - -on: - push: - branches: - - main - workflow_dispatch: - -env: - DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use - -jobs: - build-and-deploy: - runs-on: windows-latest - environment: Test - steps: - - name: 'Checkout GitHub Action' - uses: actions/checkout@v4 - - - name: Skriv ut GitHub metadata - run: | - echo "Repo: $GITHUB_REPOSITORY" - echo "Branch: $GITHUB_REF_NAME" - echo "Commit SHA: $GITHUB_SHA" - echo "Actor: $GITHUB_ACTOR" - echo "Run #: $GITHUB_RUN_NUMBER" - - - name: Set up .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - include-prerelease: true - - - name: dotnet publish - run: dotnet publish -c Release -o "${{env.GITHUB_WORKSPACE}}\myapp" - - - name: 'Run Azure Functions Action' - uses: Azure/functions-action@v1 - id: deploy-to-function - with: - app-name: 'oed-test-feedpoller-func' - slot-name: 'Production' - package: "${{env.GITHUB_WORKSPACE}}\\myapp" - publish-profile: ${{ secrets.PUBLISH_PROFILE }}