Deploy to blazor.radzen.com #131
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 blazor.radzen.com | |
| on: | |
| workflow_dispatch: | |
| concurrency: | |
| group: blazor-radzen-prod | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Generate static assets | |
| run: | | |
| dotnet run --project RadzenBlazorDemos.Tools -- \ | |
| RadzenBlazorDemos.Host/wwwroot \ | |
| RadzenBlazorDemos/Pages \ | |
| RadzenBlazorDemos/Services/ExampleService.cs | |
| # Kept out of the sources so forks, clones and local runs of the demos never report to | |
| # our analytics - only the image this workflow builds carries the snippet. | |
| - name: Inject analytics script | |
| run: | | |
| FILE=RadzenBlazorDemos.Host/App.razor | |
| ANCHOR='<script src="js/demos.js"></script>' | |
| SNIPPET=' <script defer data-domain="blazor.radzen.com" src="https://analytics.radzen.com/js/plausible.js"></script>' | |
| # Fail loudly: if App.razor is refactored, we want a red build, not a silent | |
| # deploy with analytics missing. | |
| grep -qF "$ANCHOR" "$FILE" || { echo "::error::anchor '$ANCHOR' not found in $FILE"; exit 1; } | |
| awk -v snip="$SNIPPET" -v anchor="$ANCHOR" \ | |
| 'index($0, anchor) && !done { print snip; done = 1 } { print }' "$FILE" > "$FILE.tmp" | |
| mv "$FILE.tmp" "$FILE" | |
| grep -qF 'analytics.radzen.com' "$FILE" || { echo "::error::injection produced no snippet"; exit 1; } | |
| echo "Injected analytics snippet into $FILE" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Compute image tag (timestamp) | |
| id: meta | |
| run: | | |
| TAG=$(date -u +"%Y%m%d%H%M%S") | |
| IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}" | |
| echo "image=$IMAGE" >> "$GITHUB_OUTPUT" | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.meta.outputs.image }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Set Dokku config | |
| run: | | |
| eval "$(ssh-agent -s)" | |
| echo "${{ secrets.DOKKU_SSH_PRIVATE_KEY }}" | ssh-add - | |
| REMOTE="${{ secrets.DOKKU_REPO }}" | |
| # Extract app name (last path segment) and host, handling both | |
| # ssh://dokku@host:port/app and dokku@host:app formats | |
| APP_NAME=$(echo "$REMOTE" | sed 's|.*/||') | |
| HOST=$(echo "$REMOTE" | sed 's|.*@||;s|[:/].*||') | |
| ssh -o StrictHostKeyChecking=no "dokku@${HOST}" config:set --no-restart "$APP_NAME" "GoogleMaps__ApiKey=${{ secrets.GOOGLE_MAPS_API_KEY }}" | |
| - name: Push to dokku | |
| uses: dokku/github-action@master | |
| with: | |
| git_remote_url: ${{ secrets.DOKKU_REPO }} | |
| ssh_private_key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }} | |
| deploy_docker_image: ${{ steps.meta.outputs.image }} | |
| - name: Prune GHCR versions (keep 1) | |
| uses: actions/delete-package-versions@v5 | |
| with: | |
| package-name: radzen-blazor | |
| package-type: container | |
| min-versions-to-keep: 1 | |
| delete-only-pre-release-versions: false |