Skip to content

Commit

Permalink
Rework building workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
acidicMercury8 committed Feb 21, 2024
1 parent 3d731a2 commit 2788071
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 35 deletions.
102 changes: 69 additions & 33 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,26 @@ defaults:

jobs:
build-app:
name: 'Build'
name: 'Build application'

strategy:
matrix:
system:
- windows-latest
- ubuntu-latest
framework:
- net6.0
- net7.0
- net8.0
config:
- Debug
- Release

runs-on: ${{ matrix.system }}

env:
HelpdeskSolution: HelpdeskSystem.sln

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -58,30 +65,31 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Setup Library Manager
run: |
dotnet tool install --global Microsoft.Web.LibraryManager.Cli
dotnet-version: '8.0.x'

- name: Restore dependencies
run: |
dotnet restore HelpdeskSystem.sln
dotnet tool restore
dotnet restore $env:HelpdeskSolution `
--locked-mode
cd src/Helpdesk.WebApp
libman restore
dotnet libman restore
- name: Build solution
run: |
dotnet build HelpdeskSystem.sln -p:Configuration=${{ matrix.config }} --no-restore
dotnet build $env:HelpdeskSolution `
--framework ${{ matrix.framework }} `
--configuration ${{ matrix.config }} `
--no-restore
- name: Upload artifacts
- name: Upload application
uses: actions/upload-artifact@v4
with:
name: bin-${{ matrix.config }}-${{ github.sha }}
path: bin/${{ matrix.config }}/
name: helpdesk-${{ matrix.system }}-${{ matrix.framework }}-${{ matrix.config }}-${{ github.sha }}
path: bin/${{ matrix.config }}/${{ matrix.framework }}/

test-app:
name: 'Test'
name: 'Test application'

needs: build-app

Expand All @@ -90,12 +98,19 @@ jobs:
system:
- windows-latest
- ubuntu-latest
framework:
- net6.0
- net7.0
- net8.0
config:
- Debug
- Release

runs-on: ${{ matrix.system }}

env:
HelpdeskSolution: HelpdeskSystem.sln

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -105,15 +120,17 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: '8.0.x'

- name: Restore dependencies
run: |
dotnet restore HelpdeskSystem.sln
dotnet restore $env:HelpdeskSolution `
--locked-mode
- name: Run tests
run: |
dotnet test HelpdeskSystem.sln --no-restore
dotnet test $env:HelpdeskSolution `
--no-restore
publish-docker:
name: 'Publish image'
Expand All @@ -125,7 +142,6 @@ jobs:
system:
- ubuntu-latest
config:
- Debug
- Release

runs-on: ${{ matrix.system }}
Expand All @@ -136,9 +152,24 @@ jobs:
with:
fetch-depth: 0

- name: Set tag
run: |
$tag = [math]::Round((New-TimeSpan -Start (Get-Date "1970-01-01") -End (Get-Date)).TotalSeconds)
Add-Content -Path $env:GITHUB_ENV -Value "tag=$tag"
- name: Build image
run: |
docker build . --file Dockerfile --tag helpdesksystem:$(date +%s)
docker build . --file Dockerfile --tag helpdesk:${{ env.tag }}
- name: Save image
run: |
docker save -o helpdesk-${{ env.tag }}.tar helpdesk:${{ env.tag }}
- name: Upload image
uses: actions/upload-artifact@v4
with:
name: helpdesk-${{ env.tag }}-${{ github.sha }}
path: helpdesk-${{ env.tag }}.tar

publish-dotnet:
name: 'Publish application'
Expand All @@ -149,15 +180,22 @@ jobs:
matrix:
system:
- windows-latest
config:
- Debug
- Release
framework:
- net6.0
- net7.0
- net8.0
runtime:
- win-x86
- win-x64
- linux-x64
config:
- Release

runs-on: ${{ matrix.system }}

env:
HelpdeskProject: src\Helpdesk.WebApp\Helpdesk.WebApp.csproj

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -167,22 +205,20 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Setup Library Manager
run: |
dotnet tool install --global Microsoft.Web.LibraryManager.Cli
dotnet-version: '8.0.x'

- name: Restore dependencies
run: |
dotnet tool restore
dotnet restore $env:HelpdeskSolution `
--locked-mode
cd src/Helpdesk.WebApp
libman restore
cd ../..
dotnet libman restore
- name: Publish application
run: |
dotnet publish src\Helpdesk.WebApp\Helpdesk.WebApp.csproj `
--framework net7.0 `
dotnet publish $env:HelpdeskProject `
--framework ${{ matrix.framework }} `
--runtime ${{ matrix.runtime }} `
--self-contained true `
-p:Configuration=${{ matrix.config }} `
Expand All @@ -192,8 +228,8 @@ jobs:
-p:DebugSymbols=false `
-p:DebugType=None
- name: Upload artifacts
- name: Upload application
uses: actions/upload-artifact@v4
with:
name: publish-${{ matrix.runtime }}-${{ matrix.config }}-${{ github.sha }}
path: bin/${{ matrix.config }}/net7.0/${{ matrix.runtime }}/publish/
name: helpdesk-${{ matrix.framework }}-${{ matrix.runtime }}-${{ matrix.config }}-${{ github.sha }}
path: bin/${{ matrix.config }}/${{ matrix.framework }}/${{ matrix.runtime }}/publish/
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ COPY ["src/Helpdesk.WebApp/Helpdesk.WebApp.csproj", "src/Helpdesk.WebApp/"]
RUN dotnet restore "src/Helpdesk.WebApp/Helpdesk.WebApp.csproj"
COPY . .
WORKDIR "/src/src/Helpdesk.WebApp"
RUN dotnet build "Helpdesk.WebApp.csproj" -c Release -o /app/build
RUN dotnet build "Helpdesk.WebApp.csproj" --framework net8.0 --configuration Release -o /app/build

FROM build AS publish
RUN dotnet publish "Helpdesk.WebApp.csproj" -c Release -o /app/publish /p:UseAppHost=false
RUN dotnet publish "Helpdesk.WebApp.csproj" --framework net8.0 --configuration Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
Expand Down

0 comments on commit 2788071

Please sign in to comment.