Repository navigation
Add environment-based GitHub Actions deployment #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c5d3809
Add guarded GitHub Actions deployment for Payments test
srkirkland f9f6d63
no-mistakes(document): Correct test deployment guidance and controlle…
srkirkland aed364e
no-mistakes(lint): Format deployment files and normalize health test …
srkirkland 72d8862
Align deployment with the web app template
srkirkland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [master] | ||
| push: | ||
| branches: [master] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| validate: | ||
| name: Validate | ||
| runs-on: ubuntu-22.04 | ||
| timeout-minutes: 25 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 | ||
| with: | ||
| dotnet-version: 6.0.x | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: 22.x | ||
| cache: npm | ||
| cache-dependency-path: src/Payments.Mvc/ClientApp/package-lock.json | ||
|
|
||
| - name: Restore frontend dependencies | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm ci --legacy-peer-deps | ||
|
|
||
| - name: Build frontend | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm run build | ||
|
|
||
| - name: Test frontend | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm run test:run | ||
|
|
||
| - name: Restore .NET projects | ||
| run: dotnet restore Payments.sln | ||
|
|
||
| - name: Build .NET projects | ||
| run: dotnet build Payments.sln --configuration Release --no-restore | ||
|
|
||
| - name: Test .NET projects | ||
| run: dotnet test Payments.sln --configuration Release --no-build |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| name: Deploy | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| environment: | ||
| description: GitHub Environment to deploy. | ||
| required: true | ||
| type: environment | ||
| default: test | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy ${{ inputs.environment }} | ||
| # Only test is enabled during this migration. Production stays in Azure Pipelines. | ||
| if: github.ref == 'refs/heads/master' && inputs.environment == 'test' | ||
| runs-on: ubuntu-22.04 | ||
| timeout-minutes: 30 | ||
| environment: ${{ inputs.environment }} | ||
| concurrency: | ||
| group: azure-${{ inputs.environment }} | ||
| cancel-in-progress: false | ||
| env: | ||
| APP_HEALTH_TIMEOUT_SECONDS: ${{ vars.APP_HEALTH_TIMEOUT_SECONDS || '60' }} | ||
| AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} | ||
| AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} | ||
| AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} | ||
| RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }} | ||
| WEB_APP_NAME: ${{ vars.WEB_APP_NAME }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Validate deployment configuration | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| for name in AZURE_CLIENT_ID AZURE_TENANT_ID AZURE_SUBSCRIPTION_ID RESOURCE_GROUP WEB_APP_NAME; do | ||
| if [[ -z "${!name}" ]]; then | ||
| echo "Missing required GitHub Environment variable: $name" | ||
| exit 1 | ||
| fi | ||
| done | ||
| if [[ ! "$APP_HEALTH_TIMEOUT_SECONDS" =~ ^[1-9][0-9]*$ ]]; then | ||
| echo "APP_HEALTH_TIMEOUT_SECONDS must be a positive integer." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 | ||
| with: | ||
| dotnet-version: 6.0.x | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: 22.x | ||
| cache: npm | ||
| cache-dependency-path: src/Payments.Mvc/ClientApp/package-lock.json | ||
|
|
||
| - name: Restore frontend dependencies | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm ci --legacy-peer-deps | ||
|
|
||
| - name: Build frontend | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm run build | ||
|
|
||
| - name: Test frontend | ||
| working-directory: src/Payments.Mvc/ClientApp | ||
| run: npm run test:run | ||
|
|
||
| - name: Restore .NET projects | ||
| run: dotnet restore Payments.sln | ||
|
|
||
| - name: Build .NET projects | ||
| run: dotnet build Payments.sln --configuration Release --no-restore | ||
|
|
||
| - name: Test .NET projects | ||
| run: dotnet test Payments.sln --configuration Release --no-build | ||
|
|
||
| - name: Publish app | ||
| run: dotnet publish src/Payments.Mvc/Payments.Mvc.csproj --configuration Release -p:FrontendDependenciesRestored=true --output "$PWD/publish/web" | ||
|
|
||
| - name: Publish WebJobs | ||
| run: | | ||
| dotnet publish src/Payments.Jobs.MoneyMovement/Payments.Jobs.MoneyMovement.csproj --configuration Release --output "$PWD/publish/web/app_data/jobs/triggered/Payments.Jobs.MoneyMovement" | ||
| dotnet publish src/Payments.Jobs.AutoApprove/Payments.Jobs.AutoApprove.csproj --configuration Release --output "$PWD/publish/web/app_data/jobs/triggered/Payments.Jobs.AutoApprove" | ||
|
|
||
| - name: Package app | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p publish | ||
| cd publish/web | ||
| zip -qr ../webapp.zip . | ||
|
|
||
| - name: Azure login | ||
| uses: azure/login@7ddb5af1ef8758cf1353cf3b42f940aee27ba21c # v3.0.2 | ||
| with: | ||
| client-id: ${{ env.AZURE_CLIENT_ID }} | ||
| tenant-id: ${{ env.AZURE_TENANT_ID }} | ||
| subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }} | ||
|
|
||
| - name: Verify existing App Service | ||
| run: az webapp show --resource-group "$RESOURCE_GROUP" --name "$WEB_APP_NAME" --output none | ||
|
|
||
| - name: Check SCM readiness | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| scm_url="https://${WEB_APP_NAME}.scm.azurewebsites.net/api/settings" | ||
| ready_count=0 | ||
|
|
||
| for attempt in {1..12}; do | ||
| scm_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 10 "$scm_url" || true)" | ||
|
|
||
| if [[ "$scm_status" == "200" || "$scm_status" == "401" ]]; then | ||
| ((ready_count += 1)) | ||
| if (( ready_count == 2 )); then | ||
| echo "SCM is ready for package deployment." | ||
| exit 0 | ||
| fi | ||
| else | ||
| ready_count=0 | ||
| fi | ||
|
|
||
| if (( attempt < 12 )); then | ||
| sleep 5 | ||
| fi | ||
| done | ||
|
|
||
| echo "SCM is not ready for package deployment." | ||
| exit 1 | ||
|
|
||
| - name: Deploy app package | ||
| uses: azure/webapps-deploy@02a81bead70021f5284939794bcec79c271ab383 # v3 | ||
| with: | ||
| app-name: ${{ env.WEB_APP_NAME }} | ||
| package: publish/webapp.zip | ||
|
|
||
| - name: Verify application health | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| app_url="https://${WEB_APP_NAME}.azurewebsites.net/health" | ||
| start_time=$SECONDS | ||
| deadline=$((start_time + APP_HEALTH_TIMEOUT_SECONDS)) | ||
| ready_count=0 | ||
| attempt=0 | ||
|
|
||
| while (( SECONDS < deadline )); do | ||
| ((attempt += 1)) | ||
| remaining=$((deadline - SECONDS)) | ||
| if (( remaining <= 0 )); then | ||
| break | ||
| fi | ||
|
|
||
| request_timeout=$((remaining < 10 ? remaining : 10)) | ||
| app_status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time "$request_timeout" "$app_url" || true)" | ||
| elapsed=$((SECONDS - start_time)) | ||
|
|
||
| if [[ "$app_status" == "200" ]]; then | ||
| ((ready_count += 1)) | ||
| if (( ready_count == 2 )); then | ||
| echo "The deployed application is healthy after ${elapsed} seconds." | ||
| exit 0 | ||
| fi | ||
| else | ||
| ready_count=0 | ||
| echo "Health check attempt $attempt returned HTTP ${app_status:-000} after ${elapsed} seconds." | ||
| fi | ||
|
|
||
| remaining=$((deadline - SECONDS)) | ||
| if (( remaining <= 0 )); then | ||
| break | ||
| fi | ||
|
|
||
| sleep_seconds=$((remaining < 5 ? remaining : 5)) | ||
| sleep "$sleep_seconds" | ||
| done | ||
|
|
||
| echo "The package was deployed, but the application did not become healthy within ${APP_HEALTH_TIMEOUT_SECONDS} seconds." | ||
| exit 1 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| # Payments | ||
| [](https://img.shields.io/badge/dynamic/json?label=Node%20Version&query=%24.engines.node&url=https%3A%2F%2Fraw.githubusercontent.com%2Fucdavis%2Fpayments%2Fmaster%2Fsrc%2FPayments.Mvc%2FClientApp%2Fpackage.json) | ||
| [](https://dev.azure.com/ucdavis/payments/_build/latest?definitionId=7&branchName=master) | ||
| [](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml) | ||
|
|
||
| [](https://forthebadge.com) | ||
|
|
||
| Accept and process credit card payments for CA&ES | ||
| # Payments | ||
|
|
||
| [](https://img.shields.io/badge/dynamic/json?label=Node%20Version&query=%24.engines.node&url=https%3A%2F%2Fraw.githubusercontent.com%2Fucdavis%2Fpayments%2Fmaster%2Fsrc%2FPayments.Mvc%2FClientApp%2Fpackage.json) | ||
| [](https://dev.azure.com/ucdavis/payments/_build/latest?definitionId=7&branchName=master) | ||
| [](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml) | ||
|
|
||
| [](https://forthebadge.com) | ||
|
|
||
| Accept and process credit card payments for CA&ES | ||
|
|
||
| ## Deployment | ||
|
|
||
| See [the test deployment runbook](docs/test-deployment.md) for the GitHub Actions pilot, handover checks, and rollback. Production continues through Azure Pipelines. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # GitHub Actions deployment | ||
|
|
||
| The manual `Deploy` workflow follows the [web-app-template deployment workflow](https://github.com/ucdavis/web-app-template/blob/main/.github/workflows/deploy-azure-appservice.yml). | ||
| Choose a GitHub environment when running it from `master`. Only `test` is enabled | ||
| for this migration. Production continues through the existing Azure pipeline. | ||
|
|
||
| ## Build and publish | ||
|
|
||
| CI builds the frontend and .NET projects and runs their tests using .NET 6 and | ||
| Node 22. Deployment repeats those steps, then publishes directly to `publish/web`. | ||
| Payments' existing publish target includes the frontend in the web output. | ||
|
|
||
| The deploy workflow also publishes both WebJobs into the web directory before | ||
| zipping it to `publish/webapp.zip`: | ||
|
|
||
| - `app_data/jobs/triggered/Payments.Jobs.MoneyMovement`, hourly. | ||
| - `app_data/jobs/triggered/Payments.Jobs.AutoApprove`, daily at 06:00 UTC. | ||
|
|
||
| Their existing `run.cmd`, `settings.job`, dependencies and settings are preserved. | ||
| The same job logs into Azure with OIDC, checks SCM readiness, deploys the ZIP using | ||
| `azure/webapps-deploy`, and checks `/health` for two consecutive HTTP 200 responses. | ||
| The health endpoint performs a read-only database connection check and returns | ||
| `Healthy` or `Unhealthy`, without connection details. | ||
|
|
||
| ## GitHub environment | ||
|
|
||
| The `test` environment and deployment identity already exist. The environment | ||
| restricts deployment to `master` and supplies these variables: | ||
|
|
||
| | Variable | Purpose | | ||
| | ---------------------------- | --------------------------------------------- | | ||
| | `AZURE_CLIENT_ID` | Deployment managed identity client ID | | ||
| | `AZURE_TENANT_ID` | Azure tenant ID | | ||
| | `AZURE_SUBSCRIPTION_ID` | Azure subscription ID | | ||
| | `RESOURCE_GROUP` | Existing App Service resource group | | ||
| | `WEB_APP_NAME` | Existing App Service name | | ||
| | `APP_HEALTH_TIMEOUT_SECONDS` | Optional health-check timeout, defaults to 60 | | ||
|
|
||
| The test identity is `id-payments-test-deploy`, with Website Contributor scoped to | ||
| `payments-test` only. Its federated subject is | ||
| `repo:ucdavis/payments:environment:test`. No production identity or permissions are | ||
| part of this change. | ||
|
|
||
| Application secrets and connection strings remain in Azure. Preserve Windows | ||
| hosting, 32-bit workers, Always On, schedules, domains, certificates, and | ||
| `ASPNETCORE_ENVIRONMENT=Production`. Do not change database migration behavior or | ||
| enable run-from-package during this migration. | ||
|
|
||
| The earlier draft's `TEST_DEPLOYMENT_READY` variable is no longer used. Deployment | ||
| requires an explicit manual run; do not dispatch it until the handover below. | ||
|
|
||
| ## Test handover | ||
|
|
||
| 1. Review and merge the PR after CI passes. Coordinate other application changes so | ||
| the first deployment does not also introduce schema or financial logic changes. | ||
| 2. Recheck the live test release and retain its artifact for rollback. The initial | ||
| baseline was Release-218 / build 15073 / commit | ||
| `e09c70b5d33f15f1cc3840757b3c263c2cb5ba6f`. Inspect both WebJobs and their histories. | ||
| 3. In Azure classic release definition 1, change only Test's automatic trigger to | ||
| manual. Preserve the build pipeline, release artifact trigger, and Production | ||
| stage. Confirm no test release is running or queued, including older releases. | ||
| 4. Check neither scheduled job is running. Between hourly runs and outside the | ||
| daily AutoApprove window, run `Deploy` on `master` with environment `test`. | ||
| 5. Confirm deployment and health checks pass. Inspect deployed files and both | ||
| WebJobs, especially their schedules and Windows entry points. The old MSDeploy | ||
| task removed extra files and renamed locked files; inspect the first ZIP deploy | ||
| for obsolete files or locking issues without deleting runtime data. | ||
|
|
||
| ## Read-only acceptance | ||
|
|
||
| For this first pass, inspect login, existing invoice pages, frontend assets, and | ||
| safe authenticated reads where access is available. Observe the next scheduled | ||
| MoneyMovement and AutoApprove runs and inspect application errors and job results. | ||
| Do not manually run jobs or initiate payments, recharge, email, or webhooks. | ||
|
|
||
| A green build or deployment does not prove authenticated workflows or scheduled | ||
| job success. Record any checks that still need credentials or the next scheduled | ||
| run. The AutoApprove executable does not check `Finance:RechargeAutoApprove`, so | ||
| that setting is not a job-disable switch. | ||
|
|
||
| Automatic GitHub deployment and production migration need a separate decision. | ||
|
|
||
| ## Recovery | ||
|
|
||
| Stop further manual GitHub runs and let any active deployment finish. Redeploy | ||
| the retained known-good artifact through the existing Azure release's Test stage | ||
| only. Check login, deployed files, and both jobs. The older artifact does not have | ||
| `/health`, so use its existing application routes for verification. | ||
|
|
||
| If abandoning the handover, restore Test's previous automatic trigger after | ||
| confirming no GitHub deployment is running or queued. Package rollback does not | ||
| undo database changes or job side effects. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ucdavis/payments
Length of output: 154
🏁 Script executed:
Repository: ucdavis/payments
Length of output: 13412
Verify the deployed revision, not only health status.
The health step discards the response body and accepts two consecutive HTTP 200 responses.
HealthControllerreturns onlyHealthyorUnhealthy, so an older healthy instance can satisfy the check without proving thatpublish/webapp.zipis running.Add a revision check. For example, expose the build SHA from
/healthand compare it withGITHUB_SHA, or compare the deployed package checksum withpublish/webapp.zip.🤖 Prompt for AI Agents