Skip to content

Remove multi stage docker builds and reuse GitHub build, fixing container build when running in GitHub workflows #133

Remove multi stage docker builds and reuse GitHub build, fixing container build when running in GitHub workflows

Remove multi stage docker builds and reuse GitHub build, fixing container build when running in GitHub workflows #133

Workflow file for this run

name: Application - Build and Deploy
on:
push:
branches:
- main
paths:
- "application/**"
- ".github/workflows/application.yml"
- "!**.md"
pull_request:
paths:
- "application/**"
- ".github/workflows/application.yml"
- "!**.md"
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generate_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Generate version
id: generate_version
run: |
VERSION=$(date +"%Y.%m.%d").$GITHUB_RUN_NUMBER
echo "Generated version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Install Node modules
working-directory: application/account-management/WebApp
run: bun install --frozen-lockfile
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore .NET tools
working-directory: application
run: dotnet tool restore
- name: Restore .NET dependencies
run: dotnet restore application/PlatformPlatform.sln
- name: Build
run: dotnet build application/PlatformPlatform.sln --no-restore --configuration Release /p:Version=${{ steps.generate_version.outputs.version }}
- name: Publish Account Management API build
working-directory: application/account-management
run: |
dotnet publish ./Api/Api.csproj --no-restore --configuration Release --output ./Api/publish --version-suffix ${{ steps.generate_version.outputs.version }}
mkdir ./Api/publish/WebApp
cp -r ./WebApp/dist ./Api/publish/WebApp/dist
- name: Save Account Management API artifacts
uses: actions/upload-artifact@v3
with:
name: account-management-api
path: application/account-management/Api/publish
test-with-code-coverage:
name: Test and Code Coverage
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Restore Node modules
working-directory: application/account-management/WebApp
run: bun install --frozen-lockfile
- name: Restore .NET tools
working-directory: application
run: dotnet tool restore
- name: Install dotCover
run: dotnet tool install --global JetBrains.dotCover.GlobalTool
- name: Setup-java
uses: actions/setup-java@v3
with:
distribution: "microsoft"
java-version: "17"
- name: Install SonarScanner
run: dotnet tool install --global dotnet-sonarscanner
- name: Run Test with dotCover and SonarScanner reporting
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="application/coverage/dotCover.html"
dotnet dotcover test application/PlatformPlatform.sln --dcOutput="application/coverage/dotCover.html" --dcReportType=HTML
dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
jetbrains-code-inspection:
name: JetBrains Code Inspections
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Run code inspections
working-directory: application
run: |
dotnet tool restore
dotnet jb inspectcode PlatformPlatform.sln --build --output=result.xml --severity=WARNING
account-management-api-publish:
name: Account Management API Publish
needs: [build]
uses: ./.github/workflows/_publish-container.yml
secrets: inherit
with:
image_name: account-management-api
version: ${{ needs.build.outputs.version }}
docker_context: ./application/account-management
docker_file: ./Api/Dockerfile
account-management-api-deploy:
name: Account Management API Deploy
if: github.ref == 'refs/heads/main'
needs:
[
build,
test-with-code-coverage,
jetbrains-code-inspection,
account-management-api-publish,
]
uses: ./.github/workflows/_deploy-container.yml
secrets: inherit
with:
image_name: account-management-api
version: ${{ needs.build.outputs.version }}