Skip to content

Implement Data Source Registration per ADR-0006 #27

Implement Data Source Registration per ADR-0006

Implement Data Source Registration per ADR-0006 #27

Workflow file for this run

name: 1-PR checks
on:
pull_request:
branches: [ dev, main ]
workflow_dispatch:
env:
# web app
DOCKERFILE_PATH: "CarbonAware.WebApi/src/Dockerfile"
HEALTH_ENDPOINT: "0.0.0.0:8080/health"
DLL_FILE_PATH: "./bin/Release/net6.0/CarbonAware.WebApi.dll"
DOTNET_SRC_DIR: "./src"
# console app packages
DOTNET_SOLUTION: "src/CarbonAwareSDK.sln"
OUTPUT_DIR: "packages"
CONSOLE_APP: "samples/lib-integration/ConsoleApp/ConsoleApp.csproj"
CREATE_PKGS: "scripts/package/create_packages.ps1"
ADD_PKGS: "scripts/package/add_packages.ps1"
jobs:
sln-build-and-test:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
defaults:
run:
working-directory: ./src
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Unit Tests
run: dotnet test --no-build --verbosity normal
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
webapp-container-dotnet-build:
needs: sln-build-and-test
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:6.0
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Install dependencies
run: dotnet restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Install tools
run: dotnet tool restore
working-directory: ${{ env.DOTNET_SRC_DIR }}/CarbonAware.WebApi/src
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Unit Test + Code Coverage
run: dotnet test --filter TestCategory=Unit --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=json
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Integration Test + Code Coverage
run: dotnet test --filter TestCategory=Integration --no-restore --verbosity normal /p:CollectCoverage=true /p:MergeWith=\"./coverage.json\" /p:CoverletOutputFormat=\"json,opencover\"
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Codecov
uses: codecov/codecov-action@v2
with:
directory: ${{ env.DOTNET_SRC_DIR }}
- name: Generate Open API
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
working-directory: ./src/CarbonAware.WebApi/src
- name: Upload swagger artifact
uses: actions/upload-artifact@v1
with:
name: pr-swagger.yaml
path: src/CarbonAware.WebApi/src/wwwroot/api/v1/swagger.yaml
webapp-container-validation:
needs: sln-build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Docker Target Final
run: docker build . -f ${DOCKERFILE_PATH} -t ca-api
working-directory: ./src
- name: Docker Run Container
run: |
docker run -d --name runnable-container -p 8080:80 ca-api
docker container ls
- name: Docker WGET Health Endpoint
run: |
wget -t 5 --waitretry=5 ${HEALTH_ENDPOINT}
api-comparison:
needs: webapp-container-dotnet-build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/CarbonAware.WebApi/src
container:
image: mcr.microsoft.com/dotnet/sdk
steps:
- name: Checkout Dev Branch
uses: actions/checkout@v3
with:
ref: dev
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Install dependencies
run: dotnet restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Install tools
run: dotnet tool restore
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Generate Open API
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
- name: Upload dev artifact
uses: actions/upload-artifact@v1
with:
name: dev-swagger.yaml
path: src/CarbonAware.WebApi/src/wwwroot/api/v1/swagger.yaml
- uses: actions/download-artifact@v3
with:
name: pr-swagger.yaml
path: ./src/CarbonAware.WebApi/src/wwwroot/api/v1/pr-swagger.yaml
- name: API Diff Comparison
run: |
diff ./wwwroot/api/v1/pr-swagger.yaml ./wwwroot/api/v1/swagger.yaml && echo "No API Changes detected" || echo "::warning:: API Changed"
dotnet-pack:
needs: sln-build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Create packages
shell: pwsh
run: ${{ env.CREATE_PKGS }} ${{ env.DOTNET_SOLUTION }} ${{ env.OUTPUT_DIR }}
- name: Restore current packages for ConsoleApp
run: dotnet restore ${{ env.CONSOLE_APP }}
- name: Add packages to ConsoleApp
shell: pwsh
run: ${{ env.ADD_PKGS }} ${{ env.CONSOLE_APP}} ${{ env.OUTPUT_DIR }}
- name: Cat ConsoleApp project file
run: cat ${{ env.CONSOLE_APP }}
- name: Restore packages for ConsoleApp
run: dotnet restore ${{ env.CONSOLE_APP }}
- name: Build ConsoleApp
run: dotnet build ${{ env.CONSOLE_APP }}
# Non-blocking job that checks .md file locations and also lints them
markdown-linting:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
# See the script for details about exceptions to this check
- name: Markdown files should be located in docs folder
continue-on-error: true
run: "scripts/markdown/check-markdown-files.sh"
- name: markdownlint-cli2-action
uses: DavidAnson/markdownlint-cli2-action@v9
continue-on-error: true
with:
command: config
globs: |
./custom.markdownlint.jsonc
{"*[^.github]/**,*"}.md