Merge pull request #7 from xnodeoncode/feature/deploy-update #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Azure (on merge to main) | |
| on: | |
| push: | |
| branches: [main] | |
| env: | |
| DOTNET_VERSION: "9.0.x" | |
| jobs: | |
| build-and-deploy: | |
| name: Build, Publish and Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore | |
| run: dotnet restore Aquiis.sln | |
| - name: Publish | |
| run: dotnet publish ./Aquiis.SimpleStart/Aquiis.SimpleStart.csproj -c Release -o ${{ github.workspace }}/publish | |
| - name: Azure Login (for deployment) | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Show publish output | |
| run: | | |
| echo "Publish folder contents:" | |
| ls -la "${{ github.workspace }}/publish" || true | |
| du -sh "${{ github.workspace }}/publish" || true | |
| - name: Zip publish output | |
| run: | | |
| cd "${{ github.workspace }}" | |
| if [ -d ./publish ]; then | |
| rm -f publish.zip | |
| zip -r publish.zip publish | |
| else | |
| echo "ERROR: publish folder not found" && exit 3 | |
| fi | |
| - name: Deploy with Azure CLI | |
| run: | | |
| az webapp deploy \ | |
| --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ | |
| --name ${{ secrets.AZURE_WEBAPP_NAME }} \ | |
| --src-path "${{ github.workspace }}/publish.zip" \ | |
| --type zip | |
| - name: Extract DB settings and export to GITHUB_ENV | |
| run: | | |
| DB_FILE=$(jq -r '.ApplicationSettings.DatabaseFileName // "app_v0.0.0.db"' Aquiis.SimpleStart/appsettings.json) | |
| PREV_DB_FILE=$(jq -r '.ApplicationSettings.PreviousDatabaseFileName // ""' Aquiis.SimpleStart/appsettings.json) | |
| APP_VERSION=$(jq -r '.ApplicationSettings.Version // ""' Aquiis.SimpleStart/appsettings.json) | |
| SCHEMA_VERSION=$(jq -r '.ApplicationSettings.SchemaVersion // ""' Aquiis.SimpleStart/appsettings.json) | |
| echo "DB_FILE=$DB_FILE" >> "$GITHUB_ENV" | |
| echo "PREV_DB_FILE=$PREV_DB_FILE" >> "$GITHUB_ENV" | |
| echo "APP_VERSION=$APP_VERSION" >> "$GITHUB_ENV" | |
| echo "SCHEMA_VERSION=$SCHEMA_VERSION" >> "$GITHUB_ENV" | |
| echo "DB_PATH=/home/data/$DB_FILE" >> "$GITHUB_ENV" | |
| shell: bash | |
| - name: Backup existing DB (if any) | |
| if: env.DB_PATH != '' | |
| run: | | |
| echo "Skipping Kudu-based DB backup because publish-profile/Kudu is not used when deploy via service principal." | |
| echo "Ensure app startup handles DB migrations/backups or run an alternative remote command if necessary." | |
| - name: Azure Login (for App Settings) | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Configure App Settings (set SQLite connection string and app metadata) | |
| run: | | |
| az webapp config appsettings set \ | |
| --resource-group "${{ secrets.AZURE_RESOURCE_GROUP }}" \ | |
| --name "${{ secrets.AZURE_WEBAPP_NAME }}" \ | |
| --settings \ | |
| "ConnectionStrings__DefaultConnection=DataSource=/home/data/$DB_FILE;Cache=Shared" \ | |
| "ApplicationSettings__Version=$APP_VERSION" \ | |
| "ApplicationSettings__DatabaseFileName=$DB_FILE" \ | |
| "ApplicationSettings__PreviousDatabaseFileName=$PREV_DB_FILE" \ | |
| "ApplicationSettings__SchemaVersion=$SCHEMA_VERSION" \ | |
| ASPNETCORE_ENVIRONMENT=Production | |
| shell: bash |