192 lines
6.6 KiB
YAML
192 lines
6.6 KiB
YAML
name: BuildApp
|
||
|
||
on:
|
||
# push:
|
||
# branches: [ main ]
|
||
# pull_request:
|
||
#branches: [ main ]
|
||
workflow_dispatch: {}
|
||
|
||
# (opcjonalnie) ogranicz równoległe runy
|
||
concurrency:
|
||
group: build-${{ github.ref }}
|
||
cancel-in-progress: false
|
||
|
||
jobs:
|
||
build-frontend:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: https://github.com/actions/checkout@v4
|
||
|
||
- name: Use Node.js 20
|
||
uses: https://github.com/actions/setup-node@v4
|
||
with:
|
||
node-version: 20
|
||
|
||
# Zostawiamy jak u Ciebie, jeśli chcesz – można też użyć corepack (pnpm) zamiast global install
|
||
- name: Install Angular CLI
|
||
run: npm install -g @angular/cli
|
||
|
||
- name: Install PNPM
|
||
run: npm install -g pnpm
|
||
# alternatywa:
|
||
# run: corepack enable && corepack prepare pnpm@latest --activate
|
||
|
||
- name: Install dependencies
|
||
working-directory: src/Frontend
|
||
run: pnpm install
|
||
|
||
- name: Build Angular
|
||
working-directory: src/Frontend
|
||
run: ng build --configuration=production
|
||
|
||
- name: Upload artifact (frontend)
|
||
uses: https://github.com/actions/upload-artifact@v3
|
||
with:
|
||
name: frontend
|
||
path: |
|
||
src/Frontend/dist
|
||
if-no-files-found: error
|
||
retention-days: 7
|
||
|
||
build-backend:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: https://github.com/actions/checkout@v4
|
||
|
||
- name: Setup .NET 8
|
||
uses: https://github.com/actions/setup-dotnet@v4
|
||
with:
|
||
dotnet-version: 8.0.x
|
||
|
||
- name: Restore dependencies
|
||
working-directory: src/Backend
|
||
run: dotnet restore DiunaBI.sln
|
||
|
||
- name: Build solution and prepare plugins
|
||
working-directory: src/Backend
|
||
run: |
|
||
set -e
|
||
dotnet build DiunaBI.sln --configuration Release
|
||
dotnet build DiunaBI.Plugins.Morska/DiunaBI.Plugins.Morska.csproj --configuration Release
|
||
mkdir -p DiunaBI.Tests/bin/Release/net8.0/Plugins
|
||
cp DiunaBI.Plugins.Morska/bin/Release/net8.0/DiunaBI.Plugins.Morska.dll DiunaBI.Tests/bin/Release/net8.0/Plugins/
|
||
cp DiunaBI.Plugins.Morska/bin/Release/net8.0/DiunaBI.Core.dll DiunaBI.Tests/bin/Release/net8.0/Plugins/
|
||
ls -la DiunaBI.Tests/bin/Release/net8.0/Plugins/
|
||
|
||
- name: Run Tests
|
||
working-directory: src/Backend
|
||
run: |
|
||
dotnet add DiunaBI.Tests/DiunaBI.Tests.csproj package coverlet.collector
|
||
dotnet test DiunaBI.Tests/DiunaBI.Tests.csproj \
|
||
--configuration Release \
|
||
--no-restore \
|
||
--logger "trx;LogFileName=test-results.trx" \
|
||
--collect:"XPlat Code Coverage" \
|
||
--filter "Category!=LocalOnly"
|
||
|
||
- name: Publish Test Results
|
||
uses: https://github.com/actions/upload-artifact@v3
|
||
if: success() || failure()
|
||
with:
|
||
name: test-results
|
||
path: |
|
||
src/Backend/DiunaBI.Tests/TestResults/*.trx
|
||
src/Backend/DiunaBI.Tests/TestResults/**/coverage.cobertura.xml
|
||
retention-days: 7
|
||
|
||
- name: Publish WebAPI
|
||
if: success()
|
||
working-directory: src/Backend
|
||
run: |
|
||
dotnet publish DiunaBI.WebAPI/DiunaBI.WebAPI.csproj \
|
||
--configuration Release \
|
||
--framework net8.0 \
|
||
--self-contained false \
|
||
--output ../../build/webapi
|
||
mkdir -p ../../build/webapi/Plugins
|
||
cp DiunaBI.Plugins.Morska/bin/Release/net8.0/DiunaBI.Plugins.Morska.dll ../../build/webapi/Plugins/
|
||
ls -la ../../build/webapi/Plugins/
|
||
|
||
- name: Clean up sensitive files
|
||
working-directory: build/webapi
|
||
run: |
|
||
rm -f appsettings.Development.json || true
|
||
rm -f client_secrets.Development.json || true
|
||
|
||
- name: Upload artifact (webapi)
|
||
uses: https://github.com/actions/upload-artifact@v3
|
||
with:
|
||
name: webapi
|
||
path: build/webapi
|
||
if-no-files-found: error
|
||
retention-days: 7
|
||
|
||
publish-build:
|
||
needs: [ build-frontend, build-backend ]
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: https://github.com/actions/checkout@v4
|
||
|
||
- name: Tools
|
||
run: |
|
||
apt-get update -y
|
||
apt-get install -y jq unzip zip curl
|
||
|
||
- name: Download frontend
|
||
uses: https://github.com/actions/download-artifact@v3
|
||
with: { name: frontend, path: ./release/frontend }
|
||
|
||
- name: Download backend
|
||
uses: https://github.com/actions/download-artifact@v3
|
||
with: { name: webapi, path: ./release/webapi }
|
||
|
||
- name: Zip artifacts
|
||
run: |
|
||
(cd release/frontend && zip -r ../DiunaBI-Morska-Frontend.zip .)
|
||
(cd release/webapi && zip -r ../DiunaBI-Morska-WebApi.zip .)
|
||
ls -la release
|
||
|
||
- name: Create or update release (tag build-main-latest)
|
||
id: rel
|
||
env:
|
||
API: "${{ github.server_url }}/api/v1"
|
||
OWNER: "${{ github.repository_owner }}"
|
||
REPO: "${{ github.event.repository.name }}"
|
||
TOKEN: "${{ secrets.GITEATOKEN }}"
|
||
run: |
|
||
set -euo pipefail
|
||
TAG="build-main-latest"
|
||
# spróbuj pobrać release po tagu
|
||
if curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO/releases/tags/$TAG" -o rel.json; then
|
||
ID=$(jq -r '.id' rel.json)
|
||
else
|
||
# utwórz release
|
||
DATA=$(jq -n --arg tag "$TAG" --arg name "Latest build for main" \
|
||
--arg sha "${{ github.sha }}" '{tag_name:$tag,name:$name,target_commitish:$sha,prerelease:true,draft:false}')
|
||
curl -sfSL -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||
-d "$DATA" "$API/repos/$OWNER/$REPO/releases" -o rel.json
|
||
ID=$(jq -r '.id' rel.json)
|
||
fi
|
||
echo "id=$ID" >> $GITHUB_OUTPUT
|
||
|
||
- name: Upload assets to release
|
||
env:
|
||
API: "${{ github.server_url }}/api/v1"
|
||
OWNER: "${{ github.repository_owner }}"
|
||
REPO: "${{ github.event.repository.name }}"
|
||
TOKEN: "${{ secrets.GITEATOKEN }}"
|
||
RID: "${{ steps.rel.outputs.id }}"
|
||
run: |
|
||
set -euo pipefail
|
||
upload() {
|
||
local file="$1" name="$2"
|
||
curl -sfSL -H "Authorization: token $TOKEN" \
|
||
-H "Content-Type: multipart/form-data" \
|
||
-F "attachment=@${file}" \
|
||
"$API/repos/$OWNER/$REPO/releases/$RID/assets?name=${name}" >/dev/null
|
||
}
|
||
upload "release/DiunaBI-Morska-Frontend.zip" "DiunaBI-Morska-Frontend.zip"
|
||
upload "release/DiunaBI-Morska-WebApi.zip" "DiunaBI-Morska-WebApi.zip" |