Skip to content

Merge pull request #41 from hexagram-solutions/expenses-grid-enhancem… #188

Merge pull request #41 from hexagram-solutions/expenses-grid-enhancem…

Merge pull request #41 from hexagram-solutions/expenses-grid-enhancem… #188

Workflow file for this run

name: continuous
on:
push:
branches:
- main
paths-ignore:
- "README.md"
pull_request:
branches:
- main
release:
types:
- released
- prereleased
workflow_dispatch:
inputs:
deployment-environment:
description: "Deployment environment"
type: environment
required: false
jobs:
build_test:
name: "🚦 Build & Test (Ubuntu 🐧)"
runs-on: ubuntu-latest
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
SA_PASSWORD: Hunter2!
ACCEPT_EULA: "Y"
ports:
- 1433:1433
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: "Build and test"
id: build-test
run: ./build.cmd test integration-test
env:
NUKE_SQL_SERVER_CONNECTION_STRING: "Server=localhost,1433;Initial Catalog=Spenses;User ID=sa;Password=Hunter2!;Encrypt=False;"
- name: "Publish test result artifact"
uses: actions/upload-artifact@v4
with:
name: test-results
path: artifacts/test-results
- name: "Publish coverage report artifact"
uses: actions/upload-artifact@v4
with:
name: coverage-report.zip
path: artifacts/reports/coverage-report.zip
setup:
name: "🗺 Setup deployment"
runs-on: ubuntu-latest
needs: build_test
# Deploy when:
# - A deployment environment was specified in the workflow dispatch, OR
# - We are building a release, OR
# - We are building the main branch AND we are NOT building a pull request
if: ${{ inputs.deployment-environment || github.event.release || (github.ref == 'refs/heads/main' && !github.event.pull_request)}}
outputs:
deployment-environment: ${{ steps.set-deployment-targets.outputs.target-environment-name }}
deployment-url-api: ${{ steps.set-deployment-targets.outputs.target-environment-url-api }}
deployment-url-app: ${{ steps.set-deployment-targets.outputs.target-environment-url-app }}
steps:
- name: Determine target deployment environment
id: set-deployment-targets
run: |
IS_MAIN_BRANCH=${{ github.ref == 'refs/heads/main' }}
echo "Building main branch? $IS_MAIN_BRANCH"
IS_PRERELEASE=${{ github.event.release.prerelease != '' }}
echo "Building a prerelease? $IS_PRERELEASE"
IS_RELEASE=${{ github.event.release != '' }}
echo "Building a release (will be true for prerelases)? $IS_RELEASE"
if [[ -n "${{ inputs.deployment-environment }}" ]]; then
TARGET_ENV_NAME=${{ inputs.deployment-environment }}
elif $IS_PRERELEASE; then
TARGET_ENV_NAME="production"
elif $IS_RELEASE; then
TARGET_ENV_NAME="production"
else
TARGET_ENV_NAME="test"
fi
case "$TARGET_ENV_NAME" in
"test")
TARGET_ENV_URL_API="https://test-api.spenses.money"
TARGET_ENV_URL_APP="https://test-app.spenses.money"
;;
"staging")
TARGET_ENV_URL_API="https://staging-api.spenses.money"
TARGET_ENV_URL_APP="https://staging-app.spenses.money"
;;
"production")
TARGET_ENV_URL_API="https://api.spenses.money"
TARGET_ENV_URL_APP="https://app.spenses.money"
;;
esac
echo "Target deployment environment is '$TARGET_ENV_NAME'"
echo "Target deployment URL for API is '$TARGET_ENV_URL_API'"
echo "Target deployment URL for web application is '$TARGET_ENV_URL_APP'"
echo "target-environment-name=$TARGET_ENV_NAME" >> $GITHUB_OUTPUT
echo "target-environment-url-api=$TARGET_ENV_URL_API" >> $GITHUB_OUTPUT
echo "target-environment-url-app=$TARGET_ENV_URL_APP" >> $GITHUB_OUTPUT
deploy_api:
name: "🚀⚙ Deploy API"
runs-on: ubuntu-latest
needs: setup
environment:
name: ${{ needs.setup.outputs.deployment-environment }}
url: ${{ needs.setup.outputs.deployment-url-api }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: "Deploy API"
run: ./build.cmd deploy-api
env:
NUKE_AZURE_USERNAME: ${{ vars.AZURE_USERNAME }}
NUKE_AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
NUKE_AZURE_TENANT: ${{ vars.AZURE_TENANT }}
NUKE_AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
NUKE_CONTAINER_APP_ENVIRONMENT: ${{ vars.CONTAINER_APP_ENVIRONMENT }}
NUKE_CONTAINER_APP_NAME: ${{ vars.CONTAINER_APP_NAME }}
NUKE_CONTAINER_REGISTRY_NAME: ${{ vars.CONTAINER_REGISTRY_NAME }}
NUKE_CONTAINER_REGISTRY_SERVER: ${{ vars.CONTAINER_REGISTRY_SERVER }}
NUKE_CONTAINER_REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
NUKE_CONTAINER_REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- name: "Migrate database"
run: ./build.cmd migrate-database
env:
NUKE_SQL_SERVER_CONNECTION_STRING: ${{ secrets.SQL_SERVER_CONNECTION_STRING }}
deploy_web:
name: "🚀🕸 Deploy web app"
runs-on: ubuntu-latest
needs: setup
environment:
name: ${{ needs.setup.outputs.deployment-environment }}
url: ${{ needs.setup.outputs.deployment-url-app }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v4
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Install WASM tools workload
run: dotnet workload install wasm-tools
- name: "Deploy web app"
run: ./build.cmd deploy-web-app
env:
NUKE_AZURE_STATIC_WEB_APPS_DEPLOYMENT_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_DEPLOYMENT_TOKEN }}