Skip to content

Build, Test, Cover, Deploy #153

Build, Test, Cover, Deploy

Build, Test, Cover, Deploy #153

name: Build, Test, Cover, Deploy
on:
workflow_dispatch:
workflow_call:
workflow_run:
workflows: ["Workflow Controller"]
types: [completed]
branches-ignore: [master]
env:
AZURE_WEBAPP_NAME: TrueVoteApiAppService
AZURE_WEBAPP_PACKAGE_PATH: TrueVote.Api\publish
SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION: 6.5.0
SWASHBUCKLE_DOTNET_CORE_VERSION: 3.1.x
API_IMPORT_SPECIFICATION_PATH: TrueVote.Api\publish\swagger.json
API_IMPORT_DLL: TrueVote.Api\publish\TrueVote.Api.dll
API_IMPORT_VERSION: v1
DOTNET_CORE_VERSION: 8.0.x
WORKING_DIRECTORY: TrueVote.Api
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
- name: Setup SwashBuckle .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.SWASHBUCKLE_DOTNET_CORE_VERSION }}
- name: Setup Nuget cache
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore
run: |
dotnet restore
dotnet tool restore
- name: Fixups
run: |
git fetch --tags
git update-index --chmod=+x ./scripts/*
chmod +x ./scripts/*
# ./scripts/update-git.sh
- name: Versions
run: |
dotnet --version
git --version
az --version
bash --version
# This step is necessary because during the build step, the bash -c invoke of build-version.vbs fails.
- name: Run Build Version Script
run: bash -c ./scripts/build-version.sh
shell: bash
- name: Build
run: dotnet build --no-restore
- name: Test
shell: pwsh
run: |
./scripts/RunTests.ps1 -ci true
- name: Publish Coverage to Coveralls
if: github.ref == 'refs/heads/master'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: TrueVote.Api.Tests/TestResults/coverage.info
- name: Build and Publish Release Version
run: |
dotnet publish ${{ env.WORKING_DIRECTORY }} --configuration Release --output ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Install Swashbuckle CLI .NET Global Tool
run: dotnet tool install --global Swashbuckle.AspNetCore.Cli --version ${{ env.SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION }}
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: Generate Open API Specification Document
run: swagger tofile --output "${{ env.API_IMPORT_SPECIFICATION_PATH }}" "${{ env.API_IMPORT_DLL }}" "${{ env.API_IMPORT_VERSION }}"
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
name: webapp
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
deploy:
runs-on: windows-latest
needs: build
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: webapp
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.TrueVoteApiAppService_D74C }}