From c5d38093913dede825371210d5078e8bec513ccd Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Thu, 15 Oct 2026 13:45:23 -0700 Subject: [PATCH 1/4] Add guarded GitHub Actions deployment for Payments test --- .github/workflows/ci.yml | 57 +++++++++ .github/workflows/deploy-test.yml | 86 +++++++++++++ .gitignore | 4 +- README.md | 4 + docs/test-deployment.md | 120 ++++++++++++++++++ scripts/deployment/package.sh | 30 +++++ scripts/deployment/verify-test.sh | 22 ++++ .../Controllers/HealthController.cs | 44 +++++++ src/Payments.Mvc/Payments.Mvc.csproj | 2 +- .../ControllerTests/HealthControllerTests.cs | 49 +++++++ tests/Payments.Tests/payments.Tests.csproj | 1 + tests/deployment/test_verify_test.py | 48 +++++++ 12 files changed, 465 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy-test.yml create mode 100644 docs/test-deployment.md create mode 100755 scripts/deployment/package.sh create mode 100755 scripts/deployment/verify-test.sh create mode 100644 src/Payments.Mvc/Controllers/HealthController.cs create mode 100644 tests/Payments.Tests/ControllerTests/HealthControllerTests.cs create mode 100644 tests/deployment/test_verify_test.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..55bc6b4e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + pull_request: + branches: [master] + push: + branches: [master] + workflow_call: + +permissions: + contents: read + +jobs: + validate: + name: Validate and package + runs-on: ubuntu-22.04 + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 + with: + dotnet-version: 6.0.x + - 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: Test deployment readiness checks + run: python3 -m unittest discover -s tests/deployment -v + - name: Restore frontend + working-directory: src/Payments.Mvc/ClientApp + run: npm ci --legacy-peer-deps + - name: Test frontend + working-directory: src/Payments.Mvc/ClientApp + run: npm run test:run + - name: Test server + run: dotnet test Payments.sln --configuration Release --logger trx --results-directory artifacts/test-results + - name: Publish website and WebJobs + run: bash scripts/deployment/package.sh + - name: Retain deployment package + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: payments-${{ github.sha }} + path: | + artifacts/payments.zip + artifacts/payments.zip.sha256 + if-no-files-found: error + retention-days: 90 + - name: Retain server test results + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: server-test-results-${{ github.sha }} + path: artifacts/test-results + if-no-files-found: ignore diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml new file mode 100644 index 00000000..74a70b5b --- /dev/null +++ b/.github/workflows/deploy-test.yml @@ -0,0 +1,86 @@ +name: Deploy test + +# The pilot is manual. Production remains in Azure Pipelines. +on: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: payments-test-deployment + cancel-in-progress: false + +jobs: + build: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/ci.yml + permissions: + contents: read + deploy: + name: Deploy payments-test + needs: build + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-22.04 + timeout-minutes: 20 + environment: test + permissions: + contents: read + id-token: write + env: + AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} + RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }} + WEB_APP_NAME: ${{ vars.WEB_APP_NAME }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Verify pilot configuration + env: + TEST_DEPLOYMENT_READY: ${{ vars.TEST_DEPLOYMENT_READY }} + run: | + set -euo pipefail + test "$TEST_DEPLOYMENT_READY" = true + test "$AZURE_SUBSCRIPTION_ID" = 105dede4-4731-492e-8c28-5121226319b0 + test "$AZURE_TENANT_ID" = a8046f64-66c0-4f00-9046-c8daf92ff62b + test "$RESOURCE_GROUP" = payments-test + test "$WEB_APP_NAME" = payments-test + test -n "$AZURE_CLIENT_ID" + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: payments-${{ github.sha }} + path: artifacts + - name: Verify package checksum and revision + run: | + set -euo pipefail + (cd artifacts && sha256sum --check payments.zip.sha256) + test "$(unzip -p artifacts/payments.zip wwwroot/release.json | jq -r .commit)" = "$GITHUB_SHA" + - 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 Windows App Service + run: | + set -euo pipefail + az webapp show --resource-group "$RESOURCE_GROUP" --name "$WEB_APP_NAME" > artifacts/target.json + jq -e '.name == "payments-test" and .reserved == false' artifacts/target.json + - name: Check SCM readiness + run: | + set -euo pipefail + for attempt in {1..12}; do + echo "SCM readiness attempt $attempt" + status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 10 https://payments-test.scm.azurewebsites.net/api/settings || true)" + if [[ "$status" == 200 || "$status" == 401 ]]; then exit 0; fi + sleep 5 + done + exit 1 + - name: Deploy website and WebJobs + uses: azure/webapps-deploy@02a81bead70021f5284939794bcec79c271ab383 # v3 + with: + app-name: payments-test + package: artifacts/payments.zip + - name: Verify application readiness and deployed revision + run: bash scripts/deployment/verify-test.sh "$GITHUB_SHA" diff --git a/.gitignore b/.gitignore index d84220c9..531222d3 100644 --- a/.gitignore +++ b/.gitignore @@ -223,4 +223,6 @@ src/\.vscode/ *.jfm # Ignore test coverage output -coverage/ \ No newline at end of file +coverage/ +# Python deployment checks +__pycache__/ diff --git a/README.md b/README.md index c7932a05..5eec330f 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,7 @@ [![forthebadge](https://forthebadge.com/images/badges/uses-html.svg)](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. diff --git a/docs/test-deployment.md b/docs/test-deployment.md new file mode 100644 index 00000000..a73092f0 --- /dev/null +++ b/docs/test-deployment.md @@ -0,0 +1,120 @@ +# GitHub Actions test deployment pilot + +GitHub Actions validates and packages Payments. `Deploy test` is manually dispatched +from `master` and targets only the existing Windows `payments-test` App Service. +Production remains in Azure Pipelines, including its build artifacts and manual release. + +## Package and validation + +`CI` runs .NET 6 / Node 22, restores the frontend from its lockfile, runs frontend +and backend tests, and publishes one ZIP with the website and both triggered WebJobs: + +- `app_data/jobs/triggered/Payments.Jobs.MoneyMovement`, hourly. +- `app_data/jobs/triggered/Payments.Jobs.AutoApprove`, daily at 06:00 UTC. + +The package includes each job's `run.cmd`, `settings.job`, dependencies and settings. +`wwwroot/release.json` identifies the source commit. The retained artifact includes +its SHA-256 checksum. The deploy workflow builds and tests its exact revision through +the same reusable CI workflow, then deploys that artifact without rebuilding it. + +`/health` is anonymous, uncached, and returns only `Healthy` / HTTP 200 or +`Unhealthy` / HTTP 503 after a read-only database connection check with a five-second +cancellation deadline. It does not inspect or mutate invoices. A successful deployment +requires two successful health checks and a matching deployed commit. + +For local validation, install .NET 6 and Node 22, run `npm ci --legacy-peer-deps` +in `src/Payments.Mvc/ClientApp`, run `npm run test:run` there, then run +`dotnet test Payments.sln --configuration Release` and +`bash scripts/deployment/package.sh` from the repository root. Packaging requires +`zip`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. + +## One-time test access + +Create a user-assigned managed identity `id-payments-test-deploy` in resource group +`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. +Trust issuer `https://token.actions.githubusercontent.com`, audience +`api://AzureADTokenExchange`, and subject `repo:ucdavis/payments:environment:test`. +The repository currently uses that default, non-immutable OIDC subject format; +recheck it before provisioning. Grant Website Contributor only on this App Service. +Do not grant production, SQL, shared-plan or subscription-wide access. + +Create a GitHub environment named `test`, restricted to the `master` branch, with: + +| Variable | Value | +| --- | --- | +| `AZURE_CLIENT_ID` | Client ID of the test deployment identity | +| `AZURE_TENANT_ID` | `a8046f64-66c0-4f00-9046-c8daf92ff62b` | +| `AZURE_SUBSCRIPTION_ID` | `105dede4-4731-492e-8c28-5121226319b0` | +| `RESOURCE_GROUP` | `payments-test` | +| `WEB_APP_NAME` | `payments-test` | +| `TEST_DEPLOYMENT_READY` | `false` until the handover checklist is complete | + +Application secrets and connection strings stay in Azure. Preserve Windows hosting, +32-bit worker configuration, Always On, schedules, domains, certificates and +`ASPNETCORE_ENVIRONMENT=Production`. The GitHub environment name does not replace +the ASP.NET environment setting. Do not enable run-from-package or change database +migration behavior during this pilot. + +## Handover and first deployment + +1. Merge the reviewed PR after CI succeeds. Coordinate other application merges so + the first pilot does not also introduce financial logic or schema changes. +2. Recheck the live baseline. At planning time test used Release-218 / build 15073 / + `e09c70b5d33f15f1cc3840757b3c263c2cb5ba6f`; production used Release-217. + Retain/download the last successful test artifact and capture the release definition, + deployed file inventory, settings metadata and both job histories. Protect any + configuration backups containing secrets; never commit them or upload them to CI. +3. Compare the Actions package with that baseline, allowing the health endpoint and + revision file. Investigate dependency, frontend and package layout differences. + Check both job directories and the generated Windows `web.config`. +4. In classic release definition 1, change only Test's trigger from automatic to manual. + Preserve the build pipeline, release artifact trigger and Production environment. + Confirm no test release is running or queued. Existing releases can retain older + trigger settings, so check them too. +5. Check neither scheduled job is running. Deploy between hourly MoneyMovement runs, + outside AutoApprove's daily window. Set `TEST_DEPLOYMENT_READY=true` only after + this handover. Dispatch `Deploy test` on `master`. +6. Verify Kudu deployment completion, application readiness and revision. Compare + deployed files with the artifact. The old MSDeploy task removed extra files and + renamed locked files; ZIP deployment's first run must be checked for obsolete + files and locking differences. Do not blindly erase `wwwroot` or runtime data. + +## Functional acceptance, step 5 + +Record evidence for each item; a green workflow alone does not satisfy this list. + +- CAS sign-in, existing invoice display, frontend assets and PDF generation. +- Relevant authenticated/API-key API calls, preserving authorization boundaries. +- Controlled CyberSource sandbox checkout and callback handling, with expected invoice + state and no duplicate payment processing. +- Controlled recharge and notification/webhook behavior, using agreed test records and + recipients. Confirm every external destination before allowing side effects. +- Both jobs present with unchanged names, schedules and entry points; observe the next + hourly MoneyMovement run and next daily AutoApprove run. Check job records and + expected downstream results, not just Kudu exit status. Do not manually rerun + financial jobs to accelerate observation. +- No new application errors, connection failures, duplicate processing or failed jobs. + +Live inspection found test SQL, CyberSource, SLOTH, CAS and reporting targets. +Aggie Enterprise uses a production-named gateway with `ScopeEnv=Test`; verify the +actual effective scope before financial tests. The AutoApprove executable does not +check `Finance:RechargeAutoApprove`, so that setting is not a job-disable switch. +Email and webhook delivery require approved test recipients. Never send real +notifications merely to validate deployment. + +Stop after step 5. Automatic GitHub deployment, branch-protection changes and production +migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled +run are unavailable, report the missing evidence instead of declaring acceptance. + +## Recovery + +If the pilot fails, block further GitHub deploys with `TEST_DEPLOYMENT_READY=false` +and wait for any active deployment to finish. Redeploy the retained known-good test +artifact through the existing Azure release's Test stage only. Do not select Production. +Check health using the endpoint appropriate to that artifact, login behavior, files, +and both jobs. The older artifact will not contain `/health` or `release.json`. + +Restore Test's previous automatic trigger only if abandoning the handover, after +confirming GitHub deployment is disabled and no deployment is queued. A package +rollback does not undo database changes, payments, messages or job side effects. +The pilot deliberately excludes schema and financial logic changes. diff --git a/scripts/deployment/package.sh b/scripts/deployment/package.sh new file mode 100755 index 00000000..de72b409 --- /dev/null +++ b/scripts/deployment/package.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(git rev-parse --show-toplevel)" +# Use a fresh directory so old publish output cannot enter a new package. +mkdir -p artifacts +archive="$PWD/artifacts/payments.zip" +test ! -e "$archive" || { echo "Package already exists; use a fresh checkout." >&2; exit 1; } +output="$(mktemp -d "$PWD/artifacts/package.XXXXXX")" +web="$output/web" +dotnet publish src/Payments.Mvc/Payments.Mvc.csproj --configuration Release \ + -p:FrontendDependenciesRestored=true --output "$web" +for job in Payments.Jobs.MoneyMovement Payments.Jobs.AutoApprove; do + dotnet publish "src/$job/$job.csproj" --configuration Release \ + --output "$web/app_data/jobs/triggered/$job" +done +for file in web.config Payments.Mvc.dll ClientApp/build/index.html; do + test -s "$web/$file" || { echo "Missing package file: $file" >&2; exit 1; } +done +shopt -s nullglob +frontend_assets=("$web"/ClientApp/build/assets/*.js) +((${#frontend_assets[@]} > 0)) || { echo "Missing built frontend JavaScript." >&2; exit 1; } +for job in Payments.Jobs.MoneyMovement Payments.Jobs.AutoApprove; do + for file in "$job.dll" "$job.runtimeconfig.json" run.cmd settings.job appsettings.json; do + test -s "$web/app_data/jobs/triggered/$job/$file" || { echo "Missing $job/$file" >&2; exit 1; } + done +done +revision="$(git rev-parse HEAD)" +printf '{"commit":"%s"}\n' "$revision" > "$web/wwwroot/release.json" +(cd "$web" && zip -qr "$archive" .) +(cd artifacts && shasum -a 256 payments.zip > payments.zip.sha256) diff --git a/scripts/deployment/verify-test.sh b/scripts/deployment/verify-test.sh new file mode 100755 index 00000000..2ef9b1ba --- /dev/null +++ b/scripts/deployment/verify-test.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail +revision="${1:?Expected commit is required}" +base=https://payments-test.azurewebsites.net +ready=0 +for attempt in {1..36}; do + echo "Readiness attempt $attempt" + health="$(curl --silent --show-error --fail --max-time 10 "$base/health" || true)" + deployed="$(curl --silent --show-error --fail --max-time 10 -H 'Cache-Control: no-cache' "$base/release.json" | jq -r .commit || true)" + if [[ "$health" == Healthy && "$deployed" == "$revision" ]]; then + ready=$((ready + 1)) + if ((ready >= 2)); then + echo "Test is healthy and serves commit $revision." + exit 0 + fi + else + ready=0 + fi + sleep 5 +done +echo "Test did not become healthy at the expected revision." >&2 +exit 1 diff --git a/src/Payments.Mvc/Controllers/HealthController.cs b/src/Payments.Mvc/Controllers/HealthController.cs new file mode 100644 index 00000000..9f77bc88 --- /dev/null +++ b/src/Payments.Mvc/Controllers/HealthController.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Payments.Core.Data; + +namespace Payments.Mvc.Controllers +{ + [AllowAnonymous] + [ApiExplorerSettings(IgnoreApi = true)] + public class HealthController : ControllerBase + { + private readonly ApplicationDbContext _context; + + public HealthController(ApplicationDbContext context) => _context = context; + + [HttpGet("/health")] + [ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)] + public async Task Get(CancellationToken cancellationToken) + { + using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + timeout.CancelAfter(TimeSpan.FromSeconds(5)); + var healthy = false; + try + { + healthy = await _context.Database.CanConnectAsync(timeout.Token); + } + catch (OperationCanceledException) + { + // A timed-out dependency is unavailable; never expose connection details. + } + + return new ContentResult + { + StatusCode = healthy ? StatusCodes.Status200OK : StatusCodes.Status503ServiceUnavailable, + ContentType = "text/plain", + Content = healthy ? "Healthy" : "Unhealthy", + }; + } + } +} diff --git a/src/Payments.Mvc/Payments.Mvc.csproj b/src/Payments.Mvc/Payments.Mvc.csproj index da866740..96ee990b 100644 --- a/src/Payments.Mvc/Payments.Mvc.csproj +++ b/src/Payments.Mvc/Payments.Mvc.csproj @@ -93,7 +93,7 @@ - + diff --git a/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs b/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs new file mode 100644 index 00000000..a15a48bb --- /dev/null +++ b/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs @@ -0,0 +1,49 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.TestHost; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Payments.Core.Data; +using Payments.Mvc.Controllers; +using Xunit; + +namespace payments.Tests.ControllerTests +{ + public class HealthControllerTests + { + [Theory] + [InlineData("Data Source=:memory:", HttpStatusCode.OK, "Healthy")] + [InlineData("Data Source=/missing-payments-health-test/database.db;Mode=ReadOnly", HttpStatusCode.ServiceUnavailable, "Unhealthy")] + public async Task AnonymousRequestReportsDatabaseAvailabilityWithoutDetails( + string connectionString, HttpStatusCode expectedStatus, string expectedBody) + { + using var server = new TestServer(new WebHostBuilder() + .ConfigureServices(services => + { + services.AddDbContext(options => options.UseSqlite(connectionString)); + services.AddControllers().AddApplicationPart(typeof(HealthController).Assembly); + services.AddAuthentication("test").AddCookie("test"); + services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder() + .RequireAuthenticatedUser().Build()); + }) + .Configure(app => + { + app.UseStatusCodePagesWithReExecute("/Error/{0}"); + app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseEndpoints(endpoints => endpoints.MapControllers()); + })); + using var client = server.CreateClient(); + using var response = await client.GetAsync("/health"); + Assert.Equal(expectedStatus, response.StatusCode); + Assert.Equal(expectedBody, await response.Content.ReadAsStringAsync()); + Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType); + Assert.True(response.Headers.CacheControl.NoStore); + } + } +} diff --git a/tests/Payments.Tests/payments.Tests.csproj b/tests/Payments.Tests/payments.Tests.csproj index 9f8ac95b..2313f582 100644 --- a/tests/Payments.Tests/payments.Tests.csproj +++ b/tests/Payments.Tests/payments.Tests.csproj @@ -6,6 +6,7 @@ + diff --git a/tests/deployment/test_verify_test.py b/tests/deployment/test_verify_test.py new file mode 100644 index 00000000..b8fe6ccd --- /dev/null +++ b/tests/deployment/test_verify_test.py @@ -0,0 +1,48 @@ +"""Exercise the deployment readiness command against simulated HTTP responses.""" +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().parents[2] / 'scripts/deployment/verify-test.sh' + + +class ReadinessTests(unittest.TestCase): + def run_check(self, health='Healthy', revision='expected', http_failure=False): + with tempfile.TemporaryDirectory() as directory: + curl = Path(directory) / 'curl' + curl.write_text('''#!/usr/bin/env python3 +import json, os, sys +if os.environ['HTTP_FAILURE'] == 'true': + sys.exit(22) +if sys.argv[-1].endswith('/health'): + print(os.environ['HEALTH_BODY']) +else: + print(json.dumps({'commit': os.environ['RELEASE_SHA']})) +''') + curl.chmod(0o755) + sleep = Path(directory) / 'sleep' + sleep.write_text('#!/bin/sh\nexit 0\n') + sleep.chmod(0o755) + env = dict(os.environ, PATH=directory + os.pathsep + os.environ['PATH'], + HEALTH_BODY=health, RELEASE_SHA=revision, + HTTP_FAILURE=str(http_failure).lower()) + return subprocess.run(['bash', str(SCRIPT), 'expected'], env=env, + text=True, capture_output=True, timeout=30) + + def test_accepts_healthy_expected_revision(self): + self.assertEqual(0, self.run_check().returncode) + + def test_rejects_previous_revision(self): + self.assertNotEqual(0, self.run_check(revision='previous').returncode) + + def test_rejects_login_response(self): + self.assertNotEqual(0, self.run_check(health='Sign in').returncode) + + def test_rejects_http_failure(self): + self.assertNotEqual(0, self.run_check(http_failure=True).returncode) + + +if __name__ == '__main__': + unittest.main() From f9f6d63fa61ea83f69bb935c6951502c0f8e6407 Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Thu, 15 Oct 2026 14:06:31 -0700 Subject: [PATCH 2/4] no-mistakes(document): Correct test deployment guidance and controller formatting --- docs/test-deployment.md | 29 +++--- .../Controllers/HealthController.cs | 88 +++++++++---------- 2 files changed, 62 insertions(+), 55 deletions(-) diff --git a/docs/test-deployment.md b/docs/test-deployment.md index a73092f0..f9d24aa2 100644 --- a/docs/test-deployment.md +++ b/docs/test-deployment.md @@ -20,25 +20,32 @@ the same reusable CI workflow, then deploys that artifact without rebuilding it. `/health` is anonymous, uncached, and returns only `Healthy` / HTTP 200 or `Unhealthy` / HTTP 503 after a read-only database connection check with a five-second cancellation deadline. It does not inspect or mutate invoices. A successful deployment -requires two successful health checks and a matching deployed commit. +requires two consecutive checks that each report healthy and match the expected commit. For local validation, install .NET 6 and Node 22, run `npm ci --legacy-peer-deps` in `src/Payments.Mvc/ClientApp`, run `npm run test:run` there, then run +`python3 -m unittest discover -s tests/deployment -v`, `dotnet test Payments.sln --configuration Release` and `bash scripts/deployment/package.sh` from the repository root. Packaging requires -`zip`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. +`zip`, `shasum`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. +The deployment readiness tests require Python 3, Bash and `jq`. -## One-time test access +## Test access -Create a user-assigned managed identity `id-payments-test-deploy` in resource group -`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. -Trust issuer `https://token.actions.githubusercontent.com`, audience +The test identity and GitHub environment already exist. Keep cloud configuration +unchanged and `TEST_DEPLOYMENT_READY=false` through code validation and PR review. +Recheck the existing configuration below during the post-merge handover. + +Use the user-assigned managed identity `id-payments-test-deploy` in resource group +`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. Its OIDC trust +must use issuer `https://token.actions.githubusercontent.com`, audience `api://AzureADTokenExchange`, and subject `repo:ucdavis/payments:environment:test`. The repository currently uses that default, non-immutable OIDC subject format; -recheck it before provisioning. Grant Website Contributor only on this App Service. +recheck it at handover. Keep Website Contributor scoped only to this App Service. Do not grant production, SQL, shared-plan or subscription-wide access. -Create a GitHub environment named `test`, restricted to the `master` branch, with: +Verify that the existing GitHub environment named `test` is restricted to the +`master` branch, with: | Variable | Value | | --- | --- | @@ -47,7 +54,7 @@ Create a GitHub environment named `test`, restricted to the `master` branch, wit | `AZURE_SUBSCRIPTION_ID` | `105dede4-4731-492e-8c28-5121226319b0` | | `RESOURCE_GROUP` | `payments-test` | | `WEB_APP_NAME` | `payments-test` | -| `TEST_DEPLOYMENT_READY` | `false` until the handover checklist is complete | +| `TEST_DEPLOYMENT_READY` | `false`; enable only at handover step 5 | Application secrets and connection strings stay in Azure. Preserve Windows hosting, 32-bit worker configuration, Always On, schedules, domains, certificates and @@ -102,8 +109,8 @@ check `Finance:RechargeAutoApprove`, so that setting is not a job-disable switch Email and webhook delivery require approved test recipients. Never send real notifications merely to validate deployment. -Stop after step 5. Automatic GitHub deployment, branch-protection changes and production -migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled +Stop after functional acceptance. Automatic GitHub deployment, branch-protection changes +and production migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled run are unavailable, report the missing evidence instead of declaring acceptance. ## Recovery diff --git a/src/Payments.Mvc/Controllers/HealthController.cs b/src/Payments.Mvc/Controllers/HealthController.cs index 9f77bc88..56a833c6 100644 --- a/src/Payments.Mvc/Controllers/HealthController.cs +++ b/src/Payments.Mvc/Controllers/HealthController.cs @@ -1,44 +1,44 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Payments.Core.Data; - -namespace Payments.Mvc.Controllers -{ - [AllowAnonymous] - [ApiExplorerSettings(IgnoreApi = true)] - public class HealthController : ControllerBase - { - private readonly ApplicationDbContext _context; - - public HealthController(ApplicationDbContext context) => _context = context; - - [HttpGet("/health")] - [ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)] - public async Task Get(CancellationToken cancellationToken) - { - using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); - timeout.CancelAfter(TimeSpan.FromSeconds(5)); - var healthy = false; - try - { - healthy = await _context.Database.CanConnectAsync(timeout.Token); - } - catch (OperationCanceledException) - { - // A timed-out dependency is unavailable; never expose connection details. - } - - return new ContentResult - { - StatusCode = healthy ? StatusCodes.Status200OK : StatusCodes.Status503ServiceUnavailable, - ContentType = "text/plain", - Content = healthy ? "Healthy" : "Unhealthy", - }; - } - } -} +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Payments.Core.Data; + +namespace Payments.Mvc.Controllers +{ + [AllowAnonymous] + [ApiExplorerSettings(IgnoreApi = true)] + public class HealthController : ControllerBase + { + private readonly ApplicationDbContext _context; + + public HealthController(ApplicationDbContext context) => _context = context; + + [HttpGet("/health")] + [ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)] + public async Task Get(CancellationToken cancellationToken) + { + using var timeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + timeout.CancelAfter(TimeSpan.FromSeconds(5)); + var healthy = false; + try + { + healthy = await _context.Database.CanConnectAsync(timeout.Token); + } + catch (OperationCanceledException) + { + // A timed-out dependency is unavailable; never expose connection details. + } + + return new ContentResult + { + StatusCode = healthy ? StatusCodes.Status200OK : StatusCodes.Status503ServiceUnavailable, + ContentType = "text/plain", + Content = healthy ? "Healthy" : "Unhealthy", + }; + } + } +} From aed364e00f8b5a7c5cf1a060631a699de17253c8 Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Thu, 15 Oct 2026 14:09:28 -0700 Subject: [PATCH 3/4] no-mistakes(lint): Format deployment files and normalize health test line endings --- .github/workflows/ci.yml | 114 ++++---- .github/workflows/deploy-test.yml | 172 ++++++------ README.md | 25 +- docs/test-deployment.md | 254 +++++++++--------- .../ControllerTests/HealthControllerTests.cs | 98 +++---- 5 files changed, 332 insertions(+), 331 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55bc6b4e..e6ae35d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,57 +1,57 @@ -name: CI - -on: - pull_request: - branches: [master] - push: - branches: [master] - workflow_call: - -permissions: - contents: read - -jobs: - validate: - name: Validate and package - runs-on: ubuntu-22.04 - timeout-minutes: 25 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 - with: - dotnet-version: 6.0.x - - 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: Test deployment readiness checks - run: python3 -m unittest discover -s tests/deployment -v - - name: Restore frontend - working-directory: src/Payments.Mvc/ClientApp - run: npm ci --legacy-peer-deps - - name: Test frontend - working-directory: src/Payments.Mvc/ClientApp - run: npm run test:run - - name: Test server - run: dotnet test Payments.sln --configuration Release --logger trx --results-directory artifacts/test-results - - name: Publish website and WebJobs - run: bash scripts/deployment/package.sh - - name: Retain deployment package - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: payments-${{ github.sha }} - path: | - artifacts/payments.zip - artifacts/payments.zip.sha256 - if-no-files-found: error - retention-days: 90 - - name: Retain server test results - if: always() - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: server-test-results-${{ github.sha }} - path: artifacts/test-results - if-no-files-found: ignore +name: CI + +on: + pull_request: + branches: [master] + push: + branches: [master] + workflow_call: + +permissions: + contents: read + +jobs: + validate: + name: Validate and package + runs-on: ubuntu-22.04 + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 + with: + dotnet-version: 6.0.x + - 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: Test deployment readiness checks + run: python3 -m unittest discover -s tests/deployment -v + - name: Restore frontend + working-directory: src/Payments.Mvc/ClientApp + run: npm ci --legacy-peer-deps + - name: Test frontend + working-directory: src/Payments.Mvc/ClientApp + run: npm run test:run + - name: Test server + run: dotnet test Payments.sln --configuration Release --logger trx --results-directory artifacts/test-results + - name: Publish website and WebJobs + run: bash scripts/deployment/package.sh + - name: Retain deployment package + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: payments-${{ github.sha }} + path: | + artifacts/payments.zip + artifacts/payments.zip.sha256 + if-no-files-found: error + retention-days: 90 + - name: Retain server test results + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: server-test-results-${{ github.sha }} + path: artifacts/test-results + if-no-files-found: ignore diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 74a70b5b..422b5165 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -1,86 +1,86 @@ -name: Deploy test - -# The pilot is manual. Production remains in Azure Pipelines. -on: - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: payments-test-deployment - cancel-in-progress: false - -jobs: - build: - if: github.ref == 'refs/heads/master' - uses: ./.github/workflows/ci.yml - permissions: - contents: read - deploy: - name: Deploy payments-test - needs: build - if: github.ref == 'refs/heads/master' - runs-on: ubuntu-22.04 - timeout-minutes: 20 - environment: test - permissions: - contents: read - id-token: write - env: - AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} - RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }} - WEB_APP_NAME: ${{ vars.WEB_APP_NAME }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Verify pilot configuration - env: - TEST_DEPLOYMENT_READY: ${{ vars.TEST_DEPLOYMENT_READY }} - run: | - set -euo pipefail - test "$TEST_DEPLOYMENT_READY" = true - test "$AZURE_SUBSCRIPTION_ID" = 105dede4-4731-492e-8c28-5121226319b0 - test "$AZURE_TENANT_ID" = a8046f64-66c0-4f00-9046-c8daf92ff62b - test "$RESOURCE_GROUP" = payments-test - test "$WEB_APP_NAME" = payments-test - test -n "$AZURE_CLIENT_ID" - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: payments-${{ github.sha }} - path: artifacts - - name: Verify package checksum and revision - run: | - set -euo pipefail - (cd artifacts && sha256sum --check payments.zip.sha256) - test "$(unzip -p artifacts/payments.zip wwwroot/release.json | jq -r .commit)" = "$GITHUB_SHA" - - 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 Windows App Service - run: | - set -euo pipefail - az webapp show --resource-group "$RESOURCE_GROUP" --name "$WEB_APP_NAME" > artifacts/target.json - jq -e '.name == "payments-test" and .reserved == false' artifacts/target.json - - name: Check SCM readiness - run: | - set -euo pipefail - for attempt in {1..12}; do - echo "SCM readiness attempt $attempt" - status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 10 https://payments-test.scm.azurewebsites.net/api/settings || true)" - if [[ "$status" == 200 || "$status" == 401 ]]; then exit 0; fi - sleep 5 - done - exit 1 - - name: Deploy website and WebJobs - uses: azure/webapps-deploy@02a81bead70021f5284939794bcec79c271ab383 # v3 - with: - app-name: payments-test - package: artifacts/payments.zip - - name: Verify application readiness and deployed revision - run: bash scripts/deployment/verify-test.sh "$GITHUB_SHA" +name: Deploy test + +# The pilot is manual. Production remains in Azure Pipelines. +on: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: payments-test-deployment + cancel-in-progress: false + +jobs: + build: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/ci.yml + permissions: + contents: read + deploy: + name: Deploy payments-test + needs: build + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-22.04 + timeout-minutes: 20 + environment: test + permissions: + contents: read + id-token: write + env: + AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} + RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }} + WEB_APP_NAME: ${{ vars.WEB_APP_NAME }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Verify pilot configuration + env: + TEST_DEPLOYMENT_READY: ${{ vars.TEST_DEPLOYMENT_READY }} + run: | + set -euo pipefail + test "$TEST_DEPLOYMENT_READY" = true + test "$AZURE_SUBSCRIPTION_ID" = 105dede4-4731-492e-8c28-5121226319b0 + test "$AZURE_TENANT_ID" = a8046f64-66c0-4f00-9046-c8daf92ff62b + test "$RESOURCE_GROUP" = payments-test + test "$WEB_APP_NAME" = payments-test + test -n "$AZURE_CLIENT_ID" + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: payments-${{ github.sha }} + path: artifacts + - name: Verify package checksum and revision + run: | + set -euo pipefail + (cd artifacts && sha256sum --check payments.zip.sha256) + test "$(unzip -p artifacts/payments.zip wwwroot/release.json | jq -r .commit)" = "$GITHUB_SHA" + - 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 Windows App Service + run: | + set -euo pipefail + az webapp show --resource-group "$RESOURCE_GROUP" --name "$WEB_APP_NAME" > artifacts/target.json + jq -e '.name == "payments-test" and .reserved == false' artifacts/target.json + - name: Check SCM readiness + run: | + set -euo pipefail + for attempt in {1..12}; do + echo "SCM readiness attempt $attempt" + status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 10 https://payments-test.scm.azurewebsites.net/api/settings || true)" + if [[ "$status" == 200 || "$status" == 401 ]]; then exit 0; fi + sleep 5 + done + exit 1 + - name: Deploy website and WebJobs + uses: azure/webapps-deploy@02a81bead70021f5284939794bcec79c271ab383 # v3 + with: + app-name: payments-test + package: artifacts/payments.zip + - name: Verify application readiness and deployed revision + run: bash scripts/deployment/verify-test.sh "$GITHUB_SHA" diff --git a/README.md b/README.md index 5eec330f..b018190a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ -# Payments -[![Node Version](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://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) -[![Build Status](https://dev.azure.com/ucdavis/payments/_apis/build/status%2Fucdavis.payments?branchName=master)](https://dev.azure.com/ucdavis/payments/_build/latest?definitionId=7&branchName=master) -[![CodeQL](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml) - -[![forthebadge](https://forthebadge.com/images/badges/uses-html.svg)](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. +# Payments + +[![Node Version](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://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) +[![Build Status](https://dev.azure.com/ucdavis/payments/_apis/build/status%2Fucdavis.payments?branchName=master)](https://dev.azure.com/ucdavis/payments/_build/latest?definitionId=7&branchName=master) +[![CodeQL](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ucdavis/payments/actions/workflows/codeql-analysis.yml) + +[![forthebadge](https://forthebadge.com/images/badges/uses-html.svg)](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. diff --git a/docs/test-deployment.md b/docs/test-deployment.md index f9d24aa2..05f8246a 100644 --- a/docs/test-deployment.md +++ b/docs/test-deployment.md @@ -1,127 +1,127 @@ -# GitHub Actions test deployment pilot - -GitHub Actions validates and packages Payments. `Deploy test` is manually dispatched -from `master` and targets only the existing Windows `payments-test` App Service. -Production remains in Azure Pipelines, including its build artifacts and manual release. - -## Package and validation - -`CI` runs .NET 6 / Node 22, restores the frontend from its lockfile, runs frontend -and backend tests, and publishes one ZIP with the website and both triggered WebJobs: - -- `app_data/jobs/triggered/Payments.Jobs.MoneyMovement`, hourly. -- `app_data/jobs/triggered/Payments.Jobs.AutoApprove`, daily at 06:00 UTC. - -The package includes each job's `run.cmd`, `settings.job`, dependencies and settings. -`wwwroot/release.json` identifies the source commit. The retained artifact includes -its SHA-256 checksum. The deploy workflow builds and tests its exact revision through -the same reusable CI workflow, then deploys that artifact without rebuilding it. - -`/health` is anonymous, uncached, and returns only `Healthy` / HTTP 200 or -`Unhealthy` / HTTP 503 after a read-only database connection check with a five-second -cancellation deadline. It does not inspect or mutate invoices. A successful deployment -requires two consecutive checks that each report healthy and match the expected commit. - -For local validation, install .NET 6 and Node 22, run `npm ci --legacy-peer-deps` -in `src/Payments.Mvc/ClientApp`, run `npm run test:run` there, then run -`python3 -m unittest discover -s tests/deployment -v`, -`dotnet test Payments.sln --configuration Release` and -`bash scripts/deployment/package.sh` from the repository root. Packaging requires -`zip`, `shasum`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. -The deployment readiness tests require Python 3, Bash and `jq`. - -## Test access - -The test identity and GitHub environment already exist. Keep cloud configuration -unchanged and `TEST_DEPLOYMENT_READY=false` through code validation and PR review. -Recheck the existing configuration below during the post-merge handover. - -Use the user-assigned managed identity `id-payments-test-deploy` in resource group -`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. Its OIDC trust -must use issuer `https://token.actions.githubusercontent.com`, audience -`api://AzureADTokenExchange`, and subject `repo:ucdavis/payments:environment:test`. -The repository currently uses that default, non-immutable OIDC subject format; -recheck it at handover. Keep Website Contributor scoped only to this App Service. -Do not grant production, SQL, shared-plan or subscription-wide access. - -Verify that the existing GitHub environment named `test` is restricted to the -`master` branch, with: - -| Variable | Value | -| --- | --- | -| `AZURE_CLIENT_ID` | Client ID of the test deployment identity | -| `AZURE_TENANT_ID` | `a8046f64-66c0-4f00-9046-c8daf92ff62b` | -| `AZURE_SUBSCRIPTION_ID` | `105dede4-4731-492e-8c28-5121226319b0` | -| `RESOURCE_GROUP` | `payments-test` | -| `WEB_APP_NAME` | `payments-test` | -| `TEST_DEPLOYMENT_READY` | `false`; enable only at handover step 5 | - -Application secrets and connection strings stay in Azure. Preserve Windows hosting, -32-bit worker configuration, Always On, schedules, domains, certificates and -`ASPNETCORE_ENVIRONMENT=Production`. The GitHub environment name does not replace -the ASP.NET environment setting. Do not enable run-from-package or change database -migration behavior during this pilot. - -## Handover and first deployment - -1. Merge the reviewed PR after CI succeeds. Coordinate other application merges so - the first pilot does not also introduce financial logic or schema changes. -2. Recheck the live baseline. At planning time test used Release-218 / build 15073 / - `e09c70b5d33f15f1cc3840757b3c263c2cb5ba6f`; production used Release-217. - Retain/download the last successful test artifact and capture the release definition, - deployed file inventory, settings metadata and both job histories. Protect any - configuration backups containing secrets; never commit them or upload them to CI. -3. Compare the Actions package with that baseline, allowing the health endpoint and - revision file. Investigate dependency, frontend and package layout differences. - Check both job directories and the generated Windows `web.config`. -4. In classic release definition 1, change only Test's trigger from automatic to manual. - Preserve the build pipeline, release artifact trigger and Production environment. - Confirm no test release is running or queued. Existing releases can retain older - trigger settings, so check them too. -5. Check neither scheduled job is running. Deploy between hourly MoneyMovement runs, - outside AutoApprove's daily window. Set `TEST_DEPLOYMENT_READY=true` only after - this handover. Dispatch `Deploy test` on `master`. -6. Verify Kudu deployment completion, application readiness and revision. Compare - deployed files with the artifact. The old MSDeploy task removed extra files and - renamed locked files; ZIP deployment's first run must be checked for obsolete - files and locking differences. Do not blindly erase `wwwroot` or runtime data. - -## Functional acceptance, step 5 - -Record evidence for each item; a green workflow alone does not satisfy this list. - -- CAS sign-in, existing invoice display, frontend assets and PDF generation. -- Relevant authenticated/API-key API calls, preserving authorization boundaries. -- Controlled CyberSource sandbox checkout and callback handling, with expected invoice - state and no duplicate payment processing. -- Controlled recharge and notification/webhook behavior, using agreed test records and - recipients. Confirm every external destination before allowing side effects. -- Both jobs present with unchanged names, schedules and entry points; observe the next - hourly MoneyMovement run and next daily AutoApprove run. Check job records and - expected downstream results, not just Kudu exit status. Do not manually rerun - financial jobs to accelerate observation. -- No new application errors, connection failures, duplicate processing or failed jobs. - -Live inspection found test SQL, CyberSource, SLOTH, CAS and reporting targets. -Aggie Enterprise uses a production-named gateway with `ScopeEnv=Test`; verify the -actual effective scope before financial tests. The AutoApprove executable does not -check `Finance:RechargeAutoApprove`, so that setting is not a job-disable switch. -Email and webhook delivery require approved test recipients. Never send real -notifications merely to validate deployment. - -Stop after functional acceptance. Automatic GitHub deployment, branch-protection changes -and production migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled -run are unavailable, report the missing evidence instead of declaring acceptance. - -## Recovery - -If the pilot fails, block further GitHub deploys with `TEST_DEPLOYMENT_READY=false` -and wait for any active deployment to finish. Redeploy the retained known-good test -artifact through the existing Azure release's Test stage only. Do not select Production. -Check health using the endpoint appropriate to that artifact, login behavior, files, -and both jobs. The older artifact will not contain `/health` or `release.json`. - -Restore Test's previous automatic trigger only if abandoning the handover, after -confirming GitHub deployment is disabled and no deployment is queued. A package -rollback does not undo database changes, payments, messages or job side effects. -The pilot deliberately excludes schema and financial logic changes. +# GitHub Actions test deployment pilot + +GitHub Actions validates and packages Payments. `Deploy test` is manually dispatched +from `master` and targets only the existing Windows `payments-test` App Service. +Production remains in Azure Pipelines, including its build artifacts and manual release. + +## Package and validation + +`CI` runs .NET 6 / Node 22, restores the frontend from its lockfile, runs frontend +and backend tests, and publishes one ZIP with the website and both triggered WebJobs: + +- `app_data/jobs/triggered/Payments.Jobs.MoneyMovement`, hourly. +- `app_data/jobs/triggered/Payments.Jobs.AutoApprove`, daily at 06:00 UTC. + +The package includes each job's `run.cmd`, `settings.job`, dependencies and settings. +`wwwroot/release.json` identifies the source commit. The retained artifact includes +its SHA-256 checksum. The deploy workflow builds and tests its exact revision through +the same reusable CI workflow, then deploys that artifact without rebuilding it. + +`/health` is anonymous, uncached, and returns only `Healthy` / HTTP 200 or +`Unhealthy` / HTTP 503 after a read-only database connection check with a five-second +cancellation deadline. It does not inspect or mutate invoices. A successful deployment +requires two consecutive checks that each report healthy and match the expected commit. + +For local validation, install .NET 6 and Node 22, run `npm ci --legacy-peer-deps` +in `src/Payments.Mvc/ClientApp`, run `npm run test:run` there, then run +`python3 -m unittest discover -s tests/deployment -v`, +`dotnet test Payments.sln --configuration Release` and +`bash scripts/deployment/package.sh` from the repository root. Packaging requires +`zip`, `shasum`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. +The deployment readiness tests require Python 3, Bash and `jq`. + +## Test access + +The test identity and GitHub environment already exist. Keep cloud configuration +unchanged and `TEST_DEPLOYMENT_READY=false` through code validation and PR review. +Recheck the existing configuration below during the post-merge handover. + +Use the user-assigned managed identity `id-payments-test-deploy` in resource group +`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. Its OIDC trust +must use issuer `https://token.actions.githubusercontent.com`, audience +`api://AzureADTokenExchange`, and subject `repo:ucdavis/payments:environment:test`. +The repository currently uses that default, non-immutable OIDC subject format; +recheck it at handover. Keep Website Contributor scoped only to this App Service. +Do not grant production, SQL, shared-plan or subscription-wide access. + +Verify that the existing GitHub environment named `test` is restricted to the +`master` branch, with: + +| Variable | Value | +| ----------------------- | ----------------------------------------- | +| `AZURE_CLIENT_ID` | Client ID of the test deployment identity | +| `AZURE_TENANT_ID` | `a8046f64-66c0-4f00-9046-c8daf92ff62b` | +| `AZURE_SUBSCRIPTION_ID` | `105dede4-4731-492e-8c28-5121226319b0` | +| `RESOURCE_GROUP` | `payments-test` | +| `WEB_APP_NAME` | `payments-test` | +| `TEST_DEPLOYMENT_READY` | `false`; enable only at handover step 5 | + +Application secrets and connection strings stay in Azure. Preserve Windows hosting, +32-bit worker configuration, Always On, schedules, domains, certificates and +`ASPNETCORE_ENVIRONMENT=Production`. The GitHub environment name does not replace +the ASP.NET environment setting. Do not enable run-from-package or change database +migration behavior during this pilot. + +## Handover and first deployment + +1. Merge the reviewed PR after CI succeeds. Coordinate other application merges so + the first pilot does not also introduce financial logic or schema changes. +2. Recheck the live baseline. At planning time test used Release-218 / build 15073 / + `e09c70b5d33f15f1cc3840757b3c263c2cb5ba6f`; production used Release-217. + Retain/download the last successful test artifact and capture the release definition, + deployed file inventory, settings metadata and both job histories. Protect any + configuration backups containing secrets; never commit them or upload them to CI. +3. Compare the Actions package with that baseline, allowing the health endpoint and + revision file. Investigate dependency, frontend and package layout differences. + Check both job directories and the generated Windows `web.config`. +4. In classic release definition 1, change only Test's trigger from automatic to manual. + Preserve the build pipeline, release artifact trigger and Production environment. + Confirm no test release is running or queued. Existing releases can retain older + trigger settings, so check them too. +5. Check neither scheduled job is running. Deploy between hourly MoneyMovement runs, + outside AutoApprove's daily window. Set `TEST_DEPLOYMENT_READY=true` only after + this handover. Dispatch `Deploy test` on `master`. +6. Verify Kudu deployment completion, application readiness and revision. Compare + deployed files with the artifact. The old MSDeploy task removed extra files and + renamed locked files; ZIP deployment's first run must be checked for obsolete + files and locking differences. Do not blindly erase `wwwroot` or runtime data. + +## Functional acceptance, step 5 + +Record evidence for each item; a green workflow alone does not satisfy this list. + +- CAS sign-in, existing invoice display, frontend assets and PDF generation. +- Relevant authenticated/API-key API calls, preserving authorization boundaries. +- Controlled CyberSource sandbox checkout and callback handling, with expected invoice + state and no duplicate payment processing. +- Controlled recharge and notification/webhook behavior, using agreed test records and + recipients. Confirm every external destination before allowing side effects. +- Both jobs present with unchanged names, schedules and entry points; observe the next + hourly MoneyMovement run and next daily AutoApprove run. Check job records and + expected downstream results, not just Kudu exit status. Do not manually rerun + financial jobs to accelerate observation. +- No new application errors, connection failures, duplicate processing or failed jobs. + +Live inspection found test SQL, CyberSource, SLOTH, CAS and reporting targets. +Aggie Enterprise uses a production-named gateway with `ScopeEnv=Test`; verify the +actual effective scope before financial tests. The AutoApprove executable does not +check `Finance:RechargeAutoApprove`, so that setting is not a job-disable switch. +Email and webhook delivery require approved test recipients. Never send real +notifications merely to validate deployment. + +Stop after functional acceptance. Automatic GitHub deployment, branch-protection changes +and production migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled +run are unavailable, report the missing evidence instead of declaring acceptance. + +## Recovery + +If the pilot fails, block further GitHub deploys with `TEST_DEPLOYMENT_READY=false` +and wait for any active deployment to finish. Redeploy the retained known-good test +artifact through the existing Azure release's Test stage only. Do not select Production. +Check health using the endpoint appropriate to that artifact, login behavior, files, +and both jobs. The older artifact will not contain `/health` or `release.json`. + +Restore Test's previous automatic trigger only if abandoning the handover, after +confirming GitHub deployment is disabled and no deployment is queued. A package +rollback does not undo database changes, payments, messages or job side effects. +The pilot deliberately excludes schema and financial logic changes. diff --git a/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs b/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs index a15a48bb..aa65853a 100644 --- a/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs +++ b/tests/Payments.Tests/ControllerTests/HealthControllerTests.cs @@ -1,49 +1,49 @@ -using System; -using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.TestHost; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Payments.Core.Data; -using Payments.Mvc.Controllers; -using Xunit; - -namespace payments.Tests.ControllerTests -{ - public class HealthControllerTests - { - [Theory] - [InlineData("Data Source=:memory:", HttpStatusCode.OK, "Healthy")] - [InlineData("Data Source=/missing-payments-health-test/database.db;Mode=ReadOnly", HttpStatusCode.ServiceUnavailable, "Unhealthy")] - public async Task AnonymousRequestReportsDatabaseAvailabilityWithoutDetails( - string connectionString, HttpStatusCode expectedStatus, string expectedBody) - { - using var server = new TestServer(new WebHostBuilder() - .ConfigureServices(services => - { - services.AddDbContext(options => options.UseSqlite(connectionString)); - services.AddControllers().AddApplicationPart(typeof(HealthController).Assembly); - services.AddAuthentication("test").AddCookie("test"); - services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder() - .RequireAuthenticatedUser().Build()); - }) - .Configure(app => - { - app.UseStatusCodePagesWithReExecute("/Error/{0}"); - app.UseRouting(); - app.UseAuthentication(); - app.UseAuthorization(); - app.UseEndpoints(endpoints => endpoints.MapControllers()); - })); - using var client = server.CreateClient(); - using var response = await client.GetAsync("/health"); - Assert.Equal(expectedStatus, response.StatusCode); - Assert.Equal(expectedBody, await response.Content.ReadAsStringAsync()); - Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType); - Assert.True(response.Headers.CacheControl.NoStore); - } - } -} +using System; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.TestHost; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Payments.Core.Data; +using Payments.Mvc.Controllers; +using Xunit; + +namespace payments.Tests.ControllerTests +{ + public class HealthControllerTests + { + [Theory] + [InlineData("Data Source=:memory:", HttpStatusCode.OK, "Healthy")] + [InlineData("Data Source=/missing-payments-health-test/database.db;Mode=ReadOnly", HttpStatusCode.ServiceUnavailable, "Unhealthy")] + public async Task AnonymousRequestReportsDatabaseAvailabilityWithoutDetails( + string connectionString, HttpStatusCode expectedStatus, string expectedBody) + { + using var server = new TestServer(new WebHostBuilder() + .ConfigureServices(services => + { + services.AddDbContext(options => options.UseSqlite(connectionString)); + services.AddControllers().AddApplicationPart(typeof(HealthController).Assembly); + services.AddAuthentication("test").AddCookie("test"); + services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder() + .RequireAuthenticatedUser().Build()); + }) + .Configure(app => + { + app.UseStatusCodePagesWithReExecute("/Error/{0}"); + app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseEndpoints(endpoints => endpoints.MapControllers()); + })); + using var client = server.CreateClient(); + using var response = await client.GetAsync("/health"); + Assert.Equal(expectedStatus, response.StatusCode); + Assert.Equal(expectedBody, await response.Content.ReadAsStringAsync()); + Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType); + Assert.True(response.Headers.CacheControl.NoStore); + } + } +} From 72d88628ec10e75e9a83c15af7476c7006eafced Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Thu, 15 Oct 2026 14:23:32 -0700 Subject: [PATCH 4/4] Align deployment with the web app template --- .github/workflows/ci.yml | 53 ++++--- .github/workflows/deploy-test.yml | 86 ------------ .github/workflows/deploy.yml | 192 ++++++++++++++++++++++++++ .gitignore | 4 +- docs/test-deployment.md | 197 +++++++++++---------------- scripts/deployment/package.sh | 30 ---- scripts/deployment/verify-test.sh | 22 --- tests/deployment/test_verify_test.py | 48 ------- 8 files changed, 299 insertions(+), 333 deletions(-) delete mode 100644 .github/workflows/deploy-test.yml create mode 100644 .github/workflows/deploy.yml delete mode 100755 scripts/deployment/package.sh delete mode 100755 scripts/deployment/verify-test.sh delete mode 100644 tests/deployment/test_verify_test.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ae35d8..41fc2cb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,53 +5,50 @@ on: branches: [master] push: branches: [master] - workflow_call: permissions: contents: read jobs: validate: - name: Validate and package + name: Validate runs-on: ubuntu-22.04 timeout-minutes: 25 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 + + - name: Setup .NET + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 with: dotnet-version: 6.0.x - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + + - 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: Test deployment readiness checks - run: python3 -m unittest discover -s tests/deployment -v - - name: Restore frontend + + - 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: Test server - run: dotnet test Payments.sln --configuration Release --logger trx --results-directory artifacts/test-results - - name: Publish website and WebJobs - run: bash scripts/deployment/package.sh - - name: Retain deployment package - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: payments-${{ github.sha }} - path: | - artifacts/payments.zip - artifacts/payments.zip.sha256 - if-no-files-found: error - retention-days: 90 - - name: Retain server test results - if: always() - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: server-test-results-${{ github.sha }} - path: artifacts/test-results - if-no-files-found: ignore + + - 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 diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml deleted file mode 100644 index 422b5165..00000000 --- a/.github/workflows/deploy-test.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Deploy test - -# The pilot is manual. Production remains in Azure Pipelines. -on: - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: payments-test-deployment - cancel-in-progress: false - -jobs: - build: - if: github.ref == 'refs/heads/master' - uses: ./.github/workflows/ci.yml - permissions: - contents: read - deploy: - name: Deploy payments-test - needs: build - if: github.ref == 'refs/heads/master' - runs-on: ubuntu-22.04 - timeout-minutes: 20 - environment: test - permissions: - contents: read - id-token: write - env: - AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} - RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }} - WEB_APP_NAME: ${{ vars.WEB_APP_NAME }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: Verify pilot configuration - env: - TEST_DEPLOYMENT_READY: ${{ vars.TEST_DEPLOYMENT_READY }} - run: | - set -euo pipefail - test "$TEST_DEPLOYMENT_READY" = true - test "$AZURE_SUBSCRIPTION_ID" = 105dede4-4731-492e-8c28-5121226319b0 - test "$AZURE_TENANT_ID" = a8046f64-66c0-4f00-9046-c8daf92ff62b - test "$RESOURCE_GROUP" = payments-test - test "$WEB_APP_NAME" = payments-test - test -n "$AZURE_CLIENT_ID" - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 - with: - name: payments-${{ github.sha }} - path: artifacts - - name: Verify package checksum and revision - run: | - set -euo pipefail - (cd artifacts && sha256sum --check payments.zip.sha256) - test "$(unzip -p artifacts/payments.zip wwwroot/release.json | jq -r .commit)" = "$GITHUB_SHA" - - 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 Windows App Service - run: | - set -euo pipefail - az webapp show --resource-group "$RESOURCE_GROUP" --name "$WEB_APP_NAME" > artifacts/target.json - jq -e '.name == "payments-test" and .reserved == false' artifacts/target.json - - name: Check SCM readiness - run: | - set -euo pipefail - for attempt in {1..12}; do - echo "SCM readiness attempt $attempt" - status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 10 https://payments-test.scm.azurewebsites.net/api/settings || true)" - if [[ "$status" == 200 || "$status" == 401 ]]; then exit 0; fi - sleep 5 - done - exit 1 - - name: Deploy website and WebJobs - uses: azure/webapps-deploy@02a81bead70021f5284939794bcec79c271ab383 # v3 - with: - app-name: payments-test - package: artifacts/payments.zip - - name: Verify application readiness and deployed revision - run: bash scripts/deployment/verify-test.sh "$GITHUB_SHA" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..1db3c7db --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.gitignore b/.gitignore index 531222d3..d84220c9 100644 --- a/.gitignore +++ b/.gitignore @@ -223,6 +223,4 @@ src/\.vscode/ *.jfm # Ignore test coverage output -coverage/ -# Python deployment checks -__pycache__/ +coverage/ \ No newline at end of file diff --git a/docs/test-deployment.md b/docs/test-deployment.md index 05f8246a..2fb27eee 100644 --- a/docs/test-deployment.md +++ b/docs/test-deployment.md @@ -1,127 +1,92 @@ -# GitHub Actions test deployment pilot +# GitHub Actions deployment -GitHub Actions validates and packages Payments. `Deploy test` is manually dispatched -from `master` and targets only the existing Windows `payments-test` App Service. -Production remains in Azure Pipelines, including its build artifacts and manual release. +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. -## Package and validation +## Build and publish -`CI` runs .NET 6 / Node 22, restores the frontend from its lockfile, runs frontend -and backend tests, and publishes one ZIP with the website and both triggered WebJobs: +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. -The package includes each job's `run.cmd`, `settings.job`, dependencies and settings. -`wwwroot/release.json` identifies the source commit. The retained artifact includes -its SHA-256 checksum. The deploy workflow builds and tests its exact revision through -the same reusable CI workflow, then deploys that artifact without rebuilding it. - -`/health` is anonymous, uncached, and returns only `Healthy` / HTTP 200 or -`Unhealthy` / HTTP 503 after a read-only database connection check with a five-second -cancellation deadline. It does not inspect or mutate invoices. A successful deployment -requires two consecutive checks that each report healthy and match the expected commit. - -For local validation, install .NET 6 and Node 22, run `npm ci --legacy-peer-deps` -in `src/Payments.Mvc/ClientApp`, run `npm run test:run` there, then run -`python3 -m unittest discover -s tests/deployment -v`, -`dotnet test Payments.sln --configuration Release` and -`bash scripts/deployment/package.sh` from the repository root. Packaging requires -`zip`, `shasum`, a fresh `artifacts/payments.zip` path, and restored frontend dependencies. -The deployment readiness tests require Python 3, Bash and `jq`. - -## Test access - -The test identity and GitHub environment already exist. Keep cloud configuration -unchanged and `TEST_DEPLOYMENT_READY=false` through code validation and PR review. -Recheck the existing configuration below during the post-merge handover. - -Use the user-assigned managed identity `id-payments-test-deploy` in resource group -`payments-test`, subscription `105dede4-4731-492e-8c28-5121226319b0`. Its OIDC trust -must use issuer `https://token.actions.githubusercontent.com`, audience -`api://AzureADTokenExchange`, and subject `repo:ucdavis/payments:environment:test`. -The repository currently uses that default, non-immutable OIDC subject format; -recheck it at handover. Keep Website Contributor scoped only to this App Service. -Do not grant production, SQL, shared-plan or subscription-wide access. - -Verify that the existing GitHub environment named `test` is restricted to the -`master` branch, with: - -| Variable | Value | -| ----------------------- | ----------------------------------------- | -| `AZURE_CLIENT_ID` | Client ID of the test deployment identity | -| `AZURE_TENANT_ID` | `a8046f64-66c0-4f00-9046-c8daf92ff62b` | -| `AZURE_SUBSCRIPTION_ID` | `105dede4-4731-492e-8c28-5121226319b0` | -| `RESOURCE_GROUP` | `payments-test` | -| `WEB_APP_NAME` | `payments-test` | -| `TEST_DEPLOYMENT_READY` | `false`; enable only at handover step 5 | - -Application secrets and connection strings stay in Azure. Preserve Windows hosting, -32-bit worker configuration, Always On, schedules, domains, certificates and -`ASPNETCORE_ENVIRONMENT=Production`. The GitHub environment name does not replace -the ASP.NET environment setting. Do not enable run-from-package or change database -migration behavior during this pilot. - -## Handover and first deployment - -1. Merge the reviewed PR after CI succeeds. Coordinate other application merges so - the first pilot does not also introduce financial logic or schema changes. -2. Recheck the live baseline. At planning time test used Release-218 / build 15073 / - `e09c70b5d33f15f1cc3840757b3c263c2cb5ba6f`; production used Release-217. - Retain/download the last successful test artifact and capture the release definition, - deployed file inventory, settings metadata and both job histories. Protect any - configuration backups containing secrets; never commit them or upload them to CI. -3. Compare the Actions package with that baseline, allowing the health endpoint and - revision file. Investigate dependency, frontend and package layout differences. - Check both job directories and the generated Windows `web.config`. -4. In classic release definition 1, change only Test's trigger from automatic to manual. - Preserve the build pipeline, release artifact trigger and Production environment. - Confirm no test release is running or queued. Existing releases can retain older - trigger settings, so check them too. -5. Check neither scheduled job is running. Deploy between hourly MoneyMovement runs, - outside AutoApprove's daily window. Set `TEST_DEPLOYMENT_READY=true` only after - this handover. Dispatch `Deploy test` on `master`. -6. Verify Kudu deployment completion, application readiness and revision. Compare - deployed files with the artifact. The old MSDeploy task removed extra files and - renamed locked files; ZIP deployment's first run must be checked for obsolete - files and locking differences. Do not blindly erase `wwwroot` or runtime data. - -## Functional acceptance, step 5 - -Record evidence for each item; a green workflow alone does not satisfy this list. - -- CAS sign-in, existing invoice display, frontend assets and PDF generation. -- Relevant authenticated/API-key API calls, preserving authorization boundaries. -- Controlled CyberSource sandbox checkout and callback handling, with expected invoice - state and no duplicate payment processing. -- Controlled recharge and notification/webhook behavior, using agreed test records and - recipients. Confirm every external destination before allowing side effects. -- Both jobs present with unchanged names, schedules and entry points; observe the next - hourly MoneyMovement run and next daily AutoApprove run. Check job records and - expected downstream results, not just Kudu exit status. Do not manually rerun - financial jobs to accelerate observation. -- No new application errors, connection failures, duplicate processing or failed jobs. - -Live inspection found test SQL, CyberSource, SLOTH, CAS and reporting targets. -Aggie Enterprise uses a production-named gateway with `ScopeEnv=Test`; verify the -actual effective scope before financial tests. The AutoApprove executable does not -check `Finance:RechargeAutoApprove`, so that setting is not a job-disable switch. -Email and webhook delivery require approved test recipients. Never send real -notifications merely to validate deployment. - -Stop after functional acceptance. Automatic GitHub deployment, branch-protection changes -and production migration are separate follow-up decisions. If sign-in, test fixtures or a scheduled -run are unavailable, report the missing evidence instead of declaring acceptance. +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 -If the pilot fails, block further GitHub deploys with `TEST_DEPLOYMENT_READY=false` -and wait for any active deployment to finish. Redeploy the retained known-good test -artifact through the existing Azure release's Test stage only. Do not select Production. -Check health using the endpoint appropriate to that artifact, login behavior, files, -and both jobs. The older artifact will not contain `/health` or `release.json`. +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. -Restore Test's previous automatic trigger only if abandoning the handover, after -confirming GitHub deployment is disabled and no deployment is queued. A package -rollback does not undo database changes, payments, messages or job side effects. -The pilot deliberately excludes schema and financial logic changes. +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. diff --git a/scripts/deployment/package.sh b/scripts/deployment/package.sh deleted file mode 100755 index de72b409..00000000 --- a/scripts/deployment/package.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -cd "$(git rev-parse --show-toplevel)" -# Use a fresh directory so old publish output cannot enter a new package. -mkdir -p artifacts -archive="$PWD/artifacts/payments.zip" -test ! -e "$archive" || { echo "Package already exists; use a fresh checkout." >&2; exit 1; } -output="$(mktemp -d "$PWD/artifacts/package.XXXXXX")" -web="$output/web" -dotnet publish src/Payments.Mvc/Payments.Mvc.csproj --configuration Release \ - -p:FrontendDependenciesRestored=true --output "$web" -for job in Payments.Jobs.MoneyMovement Payments.Jobs.AutoApprove; do - dotnet publish "src/$job/$job.csproj" --configuration Release \ - --output "$web/app_data/jobs/triggered/$job" -done -for file in web.config Payments.Mvc.dll ClientApp/build/index.html; do - test -s "$web/$file" || { echo "Missing package file: $file" >&2; exit 1; } -done -shopt -s nullglob -frontend_assets=("$web"/ClientApp/build/assets/*.js) -((${#frontend_assets[@]} > 0)) || { echo "Missing built frontend JavaScript." >&2; exit 1; } -for job in Payments.Jobs.MoneyMovement Payments.Jobs.AutoApprove; do - for file in "$job.dll" "$job.runtimeconfig.json" run.cmd settings.job appsettings.json; do - test -s "$web/app_data/jobs/triggered/$job/$file" || { echo "Missing $job/$file" >&2; exit 1; } - done -done -revision="$(git rev-parse HEAD)" -printf '{"commit":"%s"}\n' "$revision" > "$web/wwwroot/release.json" -(cd "$web" && zip -qr "$archive" .) -(cd artifacts && shasum -a 256 payments.zip > payments.zip.sha256) diff --git a/scripts/deployment/verify-test.sh b/scripts/deployment/verify-test.sh deleted file mode 100755 index 2ef9b1ba..00000000 --- a/scripts/deployment/verify-test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -revision="${1:?Expected commit is required}" -base=https://payments-test.azurewebsites.net -ready=0 -for attempt in {1..36}; do - echo "Readiness attempt $attempt" - health="$(curl --silent --show-error --fail --max-time 10 "$base/health" || true)" - deployed="$(curl --silent --show-error --fail --max-time 10 -H 'Cache-Control: no-cache' "$base/release.json" | jq -r .commit || true)" - if [[ "$health" == Healthy && "$deployed" == "$revision" ]]; then - ready=$((ready + 1)) - if ((ready >= 2)); then - echo "Test is healthy and serves commit $revision." - exit 0 - fi - else - ready=0 - fi - sleep 5 -done -echo "Test did not become healthy at the expected revision." >&2 -exit 1 diff --git a/tests/deployment/test_verify_test.py b/tests/deployment/test_verify_test.py deleted file mode 100644 index b8fe6ccd..00000000 --- a/tests/deployment/test_verify_test.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Exercise the deployment readiness command against simulated HTTP responses.""" -import os -from pathlib import Path -import subprocess -import tempfile -import unittest - -SCRIPT = Path(__file__).resolve().parents[2] / 'scripts/deployment/verify-test.sh' - - -class ReadinessTests(unittest.TestCase): - def run_check(self, health='Healthy', revision='expected', http_failure=False): - with tempfile.TemporaryDirectory() as directory: - curl = Path(directory) / 'curl' - curl.write_text('''#!/usr/bin/env python3 -import json, os, sys -if os.environ['HTTP_FAILURE'] == 'true': - sys.exit(22) -if sys.argv[-1].endswith('/health'): - print(os.environ['HEALTH_BODY']) -else: - print(json.dumps({'commit': os.environ['RELEASE_SHA']})) -''') - curl.chmod(0o755) - sleep = Path(directory) / 'sleep' - sleep.write_text('#!/bin/sh\nexit 0\n') - sleep.chmod(0o755) - env = dict(os.environ, PATH=directory + os.pathsep + os.environ['PATH'], - HEALTH_BODY=health, RELEASE_SHA=revision, - HTTP_FAILURE=str(http_failure).lower()) - return subprocess.run(['bash', str(SCRIPT), 'expected'], env=env, - text=True, capture_output=True, timeout=30) - - def test_accepts_healthy_expected_revision(self): - self.assertEqual(0, self.run_check().returncode) - - def test_rejects_previous_revision(self): - self.assertNotEqual(0, self.run_check(revision='previous').returncode) - - def test_rejects_login_response(self): - self.assertNotEqual(0, self.run_check(health='Sign in').returncode) - - def test_rejects_http_failure(self): - self.assertNotEqual(0, self.run_check(http_failure=True).returncode) - - -if __name__ == '__main__': - unittest.main()