Files
bytefy/.github/workflows/build.yml
2025-09-27 23:36:11 +02:00

165 lines
4.7 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
restart_iis:
description: 'Restart IIS after deployment'
required: true
default: true
type: boolean
create_release:
description: 'Create release'
required: true
default: true
jobs:
build:
runs-on: self-hosted # Ensure your self-hosted runner is configured
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: '8.0' # Change to your required .NET version
- name: Restore .NET Dependencies
run: dotnet restore ./services/bytefy.image/bytefy.image/bytefy.image.csproj
- name: Build .NET Project
run: dotnet build --configuration Release ./services/bytefy.image/bytefy.image/bytefy.image.csproj
- name: Publish .NET Project
run: dotnet publish ./services/bytefy.image/bytefy.image/bytefy.image.csproj --configuration Release --output ./output/dotnet
- name: Create placeholder appsettings for release
if: ${{ github.event.inputs.create_release != 'false' }}
run: |
$appSettings = @{
Logging = @{
LogLevel = @{
Default = "Information"
"Microsoft.AspNetCore" = "Warning"
}
}
AllowedHosts = "*"
Cors = @{
AllowedOrigins = @(
"http://localhost:4200"
"https://localhost:4200"
"https://bytefy.net"
)
}
Seq = @{
ServerUrl = "${{ vars.SEQ_URL }}"
ApiKey = "${{ secrets.seq_api_key }}"
MinimumLevel = "Trace"
LevelOverride = @{
Microsoft = "Warning"
}
}
}
$appSettings | ConvertTo-Json -Depth 10 | Set-Content -Path "./output/dotnet/appsettings.json"
Write-Host "Created placeholder appsettings.json successfully"
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '22.12' # Change to your required Node.js version
- name: Install Angular CLI
run: npm install -g @angular/cli
- name: Install Angular Dependencies
run: |
cd ./bytefy.webapp
npm install --force
- name: Build Angular App
run: |
cd ./bytefy.webapp
ng build --configuration production --output-path=dist
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: dotnet-artifacts
path: ./output/dotnet
- name: Upload Angular Artifacts
uses: actions/upload-artifact@v4
with:
name: angular-artifacts
path: ./bytefy.webapp/dist
deploy:
runs-on: self-hosted # Ensure your self-hosted runner is configured
if: ${{ github.event.inputs.create_release != 'false' }}
needs: build
steps:
- name: Download .NET Artifacts
uses: actions/download-artifact@v4
with:
name: dotnet-artifacts
path: ./output/dotnet
- name: Download Angular Artifacts
uses: actions/download-artifact@v4
with:
name: angular-artifacts
path: ./bytefy.webapp/dist
- name: Check Output Files
run: |
dir ./output/dotnet
dir ./bytefy.webapp/dist
- name: Copy .NET Publish Files to IIS Server
run: |
xcopy ".\output\dotnet\*" "C:\inetpub\applications\bytefy.image" /s /i /y
xcopy ".\bytefy.webapp\dist\browser\*" "C:\inetpub\wwwroot\bytefy" /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 }}"
if ([string]::IsNullOrEmpty($appPoolName)) {
$appPoolName = "Bytefy.image"
}
Write-Host "Starting application pool: $appPoolName"
# Check if app pool exists
if (Test-Path "IIS:\AppPools\$appPoolName") {
# Start app pool
Start-WebAppPool -Name $appPoolName
Write-Host "Application pool started successfully"
} else {
Write-Host "Warning: Application pool '$appPoolName' not found. Using IISReset instead."
iisreset /restart
Write-Host "IIS restarted successfully"
}