|
| 1 | +name: Docker Web API Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ dev, main ] |
| 6 | + pull_request: |
| 7 | + branches: [ dev, main ] |
| 8 | + paths: |
| 9 | + - 'src/**' |
| 10 | + - '.github/workflows/**' |
| 11 | + |
| 12 | +env: |
| 13 | + DOCKERFILE_PATH: "CarbonAware.WebApi/src/Dockerfile" |
| 14 | + HEALTH_ENDPOINT: "0.0.0.0:8080/health" |
| 15 | + DATA_ENDPOINT: "0.0.0.0:8080/emissions/bylocation?location=eastus" |
| 16 | + DLL_FILE_PATH: "./bin/Release/net6.0/CarbonAware.WebApi.dll" |
| 17 | + DOTNET_SRC_DIR: "./src" |
| 18 | + |
| 19 | +jobs: |
| 20 | + container-dotnet-build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + container: |
| 23 | + image: mcr.microsoft.com/dotnet/sdk:6.0 |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + |
| 27 | + - name: Setup .NET Core SDK 6 |
| 28 | + uses: actions/setup-dotnet@v2 |
| 29 | + with: |
| 30 | + dotnet-version: '6.0.x' |
| 31 | + include-prerelease: false |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: dotnet restore |
| 35 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 36 | + |
| 37 | + - name: Install tools |
| 38 | + run: dotnet tool restore |
| 39 | + working-directory: ${{ env.DOTNET_SRC_DIR }}/CarbonAware.WebApi/src |
| 40 | + |
| 41 | + - name: Build |
| 42 | + run: dotnet build --configuration Release --no-restore |
| 43 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 44 | + |
| 45 | + - name: Unit Test + Code Coverage |
| 46 | + run: dotnet test --filter TestCategory=Unit --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=json |
| 47 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 48 | + |
| 49 | + - name: Integration Test + Code Coverage |
| 50 | + run: dotnet test --filter TestCategory=Integration --no-restore --verbosity normal /p:CollectCoverage=true /p:MergeWith=\"./coverage.json\" /p:CoverletOutputFormat=\"json,opencover\" |
| 51 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 52 | + |
| 53 | + - name: Codecov |
| 54 | + uses: codecov/codecov-action@v2 |
| 55 | + with: |
| 56 | + directory: ${{ env.DOTNET_SRC_DIR }} |
| 57 | + |
| 58 | + - name: Generate Open API |
| 59 | + run: dotnet tool run swagger tofile --output ./api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1 |
| 60 | + working-directory: ./src/CarbonAware.WebApi/src |
| 61 | + |
| 62 | + - name: Upload artifact |
| 63 | + uses: actions/upload-artifact@v1 |
| 64 | + with: |
| 65 | + name: pr-swagger.yaml |
| 66 | + path: src/CarbonAware.WebApi/src/api/v1/swagger.yaml |
| 67 | + |
| 68 | + container-validation: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - name: Checkout Repository |
| 72 | + uses: actions/checkout@v2 |
| 73 | + |
| 74 | + - name: Docker Target Final |
| 75 | + run: docker build . -f ${DOCKERFILE_PATH} -t ca-api |
| 76 | + working-directory: ./src |
| 77 | + |
| 78 | + - name: Docker Run Container |
| 79 | + run: | |
| 80 | + docker run -d --name runnable-container -p 8080:80 ca-api |
| 81 | + docker container ls |
| 82 | +
|
| 83 | + - name: Docker WGET Health Endpoint |
| 84 | + run: | |
| 85 | + wget -t 5 --waitretry=5 ${HEALTH_ENDPOINT} |
| 86 | +
|
| 87 | + - name: Docker WGET Data Endpoint |
| 88 | + run: | |
| 89 | + wget -t 5 --waitretry=5 ${DATA_ENDPOINT} |
| 90 | +
|
| 91 | + api-comparison: |
| 92 | + needs: container-dotnet-build |
| 93 | + runs-on: ubuntu-latest |
| 94 | + defaults: |
| 95 | + run: |
| 96 | + working-directory: ./src/CarbonAware.WebApi/src |
| 97 | + container: |
| 98 | + image: mcr.microsoft.com/dotnet/sdk |
| 99 | + steps: |
| 100 | + - name: Checkout Dev Branch |
| 101 | + uses: actions/checkout@v3 |
| 102 | + with: |
| 103 | + ref: dev |
| 104 | + - name: Setup .NET Core SDK 6 |
| 105 | + uses: actions/setup-dotnet@v2 |
| 106 | + with: |
| 107 | + dotnet-version: '6.0.x' |
| 108 | + include-prerelease: false |
| 109 | + - name: Install dependencies |
| 110 | + run: dotnet restore |
| 111 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 112 | + - name: Install tools |
| 113 | + run: dotnet tool restore |
| 114 | + - name: Build |
| 115 | + run: dotnet build --configuration Release --no-restore |
| 116 | + working-directory: ${{ env.DOTNET_SRC_DIR }} |
| 117 | + - name: Generate Open API |
| 118 | + run: dotnet tool run swagger tofile --output ./api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1 |
| 119 | + - name: Upload dev artifact |
| 120 | + uses: actions/upload-artifact@v1 |
| 121 | + with: |
| 122 | + name: dev-swagger.yaml |
| 123 | + path: src/CarbonAware.WebApi/src/api/v1/swagger.yaml |
| 124 | + - uses: actions/download-artifact@v3 |
| 125 | + with: |
| 126 | + name: pr-swagger.yaml |
| 127 | + path: ./src/CarbonAware.WebApi/src/api/v1/pr-swagger.yaml |
| 128 | + - name: API Diff Comparison |
| 129 | + run: | |
| 130 | + diff ./api/v1/pr-swagger.yaml ./api/v1/swagger.yaml && echo "No API Changes detected" || echo "::warning:: API Changed" |
0 commit comments