131 lines
4.3 KiB
YAML
131 lines
4.3 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master # Change to your default branch if different
|
|
workflow_dispatch:
|
|
inputs:
|
|
environment:
|
|
description: 'Environment to deploy to'
|
|
required: true
|
|
default: 'prod'
|
|
type: choice
|
|
options:
|
|
- prod
|
|
- dev
|
|
- test
|
|
restart_iis:
|
|
description: 'Restart IIS after deployment'
|
|
required: true
|
|
default: true
|
|
type: boolean
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: self-hosted # Ensure your self-hosted runner is configured
|
|
environment: ${{ github.event.inputs.environment || 'prod' }}
|
|
steps:
|
|
- name: Get Current User
|
|
run: |
|
|
$env:USERNAME
|
|
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Set up .NET
|
|
uses: actions/setup-dotnet@v2
|
|
with:
|
|
dotnet-version: '9.0' # Change to your required .NET version
|
|
|
|
- name: Restore .NET Dependencies
|
|
run: dotnet restore ./HomeApi.sln
|
|
|
|
- name: Build .NET Project
|
|
run: dotnet build --configuration Release ./HomeApi/HomeApi.csproj
|
|
|
|
- name: Publish .NET Project
|
|
run: dotnet publish ./HomeApi/HomeApi.csproj --configuration Release --output ./output/dotnet
|
|
|
|
- name: Generate appsettings.json
|
|
run: |
|
|
$appSettings = @{
|
|
Logging = @{
|
|
LogLevel = @{
|
|
Default = "Information"
|
|
"Microsoft.AspNetCore" = "Warning"
|
|
}
|
|
}
|
|
ApiConfiguration = @{
|
|
EspConfiguration = @{
|
|
InformationBoardImageUrl = "${{ vars.ESP_IMAGE_URL }}"
|
|
UpdateIntervalMinutes = [int]"${{ vars.ESP_UPDATE_INTERVAL }}"
|
|
BlackTextThreshold = [int]"${{ vars.ESP_BLACK_TEXT_THRESHOLD }}"
|
|
EnableDithering = [System.Convert]::ToBoolean("${{ vars.ESP_ENABLE_DITHERING }}")
|
|
DitheringStrength = [int]"${{ vars.ESP_DITHERING_STRENGTH }}"
|
|
EnhanceContrast = [System.Convert]::ToBoolean("${{ vars.ESP_ENHANCE_CONTRAST }}")
|
|
ContrastStrength = [int]"${{ vars.ESP_CONTRAST_STRENGTH }}"
|
|
IsHighContrastMode = [System.Convert]::ToBoolean("${{ vars.ESP_HIGH_CONTRAST_MODE }}")
|
|
}
|
|
Keys = @{
|
|
Weather = "${{ secrets.WEATHER_API_KEY }}"
|
|
ResRobot = "${{ secrets.RES_ROBOT_API_KEY }}"
|
|
}
|
|
BaseUrls = @{
|
|
Nominatim = "${{ vars.NOMINATIM_URL }}"
|
|
Aurora = "${{ vars.AURORA_URL }}"
|
|
Weather = "${{ vars.WEATHER_URL }}"
|
|
ResRobot = "${{ vars.RES_ROBOT_URL }}"
|
|
}
|
|
DefaultCity = "${{ vars.DEFAULT_CITY }}"
|
|
DefaultStation = "${{ vars.DEFAULT_STATION }}"
|
|
}
|
|
AllowedHosts = "*"
|
|
}
|
|
|
|
$appSettings | ConvertTo-Json -Depth 10 | Set-Content -Path "./output/dotnet/appsettings.json"
|
|
Write-Host "Generated appsettings.json successfully"
|
|
|
|
- name: Upload Artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: dotnet-artifacts
|
|
path: ./output/dotnet
|
|
|
|
deploy:
|
|
runs-on: self-hosted # Ensure your self-hosted runner is configured
|
|
needs: build
|
|
environment: ${{ github.event.inputs.environment || 'prod' }}
|
|
|
|
steps:
|
|
- name: Download .NET Artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: dotnet-artifacts
|
|
path: ./output/dotnet
|
|
|
|
- name: Check Output Files
|
|
run: |
|
|
dir ./output/dotnet
|
|
|
|
- name: Copy .NET Publish Files to IIS Server
|
|
run: |
|
|
xcopy ".\output\dotnet\*" "C:\inetpub\applications\HomeApi" /s /i /y
|
|
|
|
- name: Restart IIS Application Pool
|
|
if: ${{ github.event.inputs.restart_iis != 'false' }}
|
|
run: |
|
|
Import-Module WebAdministration
|
|
$appPoolName = "${{ vars.IIS_APP_POOL_NAME }}" -or "HomeApi"
|
|
Write-Host "Restarting application pool: $appPoolName"
|
|
|
|
# Check if app pool exists
|
|
if (Test-Path "IIS:\AppPools\$appPoolName") {
|
|
Restart-WebAppPool -Name $appPoolName
|
|
Write-Host "Application pool restarted successfully"
|
|
} else {
|
|
Write-Host "Warning: Application pool '$appPoolName' not found. Using IISReset instead."
|
|
iisreset /restart
|
|
Write-Host "IIS restarted successfully"
|
|
}
|