|
| 1 | +# Testing cpflow GitHub Actions Changes |
| 2 | + |
| 3 | +Use this guide when changing generated `cpflow-*` GitHub Actions, updating the |
| 4 | +`cpflow` generator version, or debugging review-app automation. |
| 5 | + |
| 6 | +## What To Test |
| 7 | + |
| 8 | +Test the flow in three layers: |
| 9 | + |
| 10 | +1. Local generated-file checks catch YAML, metadata, and lint problems before a PR. |
| 11 | +2. GitHub workflow checks prove GitHub can load the workflow and run CI. |
| 12 | +3. A real review-app deploy proves the default-branch trusted actions, GitHub |
| 13 | + secrets, Docker build, and Control Plane deploy all work together. |
| 14 | + |
| 15 | +The third layer matters because the review-app workflow intentionally checks out |
| 16 | +trusted workflow sources from the repository default branch before passing |
| 17 | +Control Plane secrets to local composite actions. A PR branch can contain fixed |
| 18 | +`.github/actions/*` files, but the deploy job still loads those local actions |
| 19 | +from `master` until the fix is merged there. |
| 20 | + |
| 21 | +## Local Checks |
| 22 | + |
| 23 | +After regenerating the flow, run these checks from the repository root. If |
| 24 | +`cpflow` is installed as a gem, use `cpflow` directly: |
| 25 | + |
| 26 | +```sh |
| 27 | +bin/conductor-exec cpflow generate-github-actions --staging-branch master |
| 28 | +bin/test-cpflow-github-flow |
| 29 | +``` |
| 30 | + |
| 31 | +When testing an unreleased upstream `control-plane-flow` checkout, replace |
| 32 | +`cpflow` with that checkout's `bin/cpflow`: |
| 33 | + |
| 34 | +```sh |
| 35 | +bin/conductor-exec ruby /path/to/control-plane-flow/bin/cpflow generate-github-actions --staging-branch master |
| 36 | +bin/test-cpflow-github-flow ruby /path/to/control-plane-flow/bin/cpflow |
| 37 | +``` |
| 38 | + |
| 39 | +Why the explicit description check exists: GitHub parses expression-like snippets |
| 40 | +inside composite action metadata, including `description:` fields. Literal |
| 41 | +examples such as `${{ vars.SOME_VALUE }}` can fail action loading before any |
| 42 | +shell step starts. The wrapper runs `cpflow github-flow-readiness`, parses the |
| 43 | +generated YAML, checks action input descriptions for literal GitHub expressions, |
| 44 | +and runs `actionlint -ignore 'SC2129' .github/workflows/cpflow-*.yml`. |
| 45 | + |
| 46 | +## PR Checks |
| 47 | + |
| 48 | +Open a normal PR for the generated-file diff and wait for CI. The workflow PR |
| 49 | +itself is useful for syntax and CI validation, but it does not fully prove |
| 50 | +review-app deployment changes that live under `.github/actions/`. |
| 51 | + |
| 52 | +For top-level workflow edits, you can manually dispatch the PR branch workflow: |
| 53 | + |
| 54 | +```sh |
| 55 | +gh workflow run cpflow-deploy-review-app.yml --ref <branch> -f pr_number=<pr-number> |
| 56 | +``` |
| 57 | + |
| 58 | +This loads the workflow file from `<branch>`, but the deploy workflow's |
| 59 | +`Checkout trusted workflow sources` step still checks out `master` before using |
| 60 | +local composite actions with secrets. Treat this as a partial smoke test, not as |
| 61 | +proof that PR-branch composite action changes work. |
| 62 | + |
| 63 | +## Post-Merge Review-App Test |
| 64 | + |
| 65 | +After the workflow PR merges to `master`, test a real review-app deployment: |
| 66 | + |
| 67 | +1. Pick a same-repository PR to use as the canary. |
| 68 | +2. If the review app does not exist yet, comment exactly `+review-app-deploy` on |
| 69 | + that PR. |
| 70 | +3. If a previous deploy run failed, rerun the failed deploy run after the |
| 71 | + workflow PR is merged. |
| 72 | +4. Confirm the deploy run checks out `master` at the merge commit in |
| 73 | + `Checkout trusted workflow sources`. |
| 74 | +5. Confirm `Setup environment` succeeds and prints the expected `cpflow` version. |
| 75 | +6. Confirm `Check if review app exists`, `Build Docker image`, and |
| 76 | + `Deploy to Control Plane` all run as expected. |
| 77 | +7. Open the review-app URL from the PR comment or deployment status and verify |
| 78 | + it returns HTTP 200. |
| 79 | + |
| 80 | +Use the generated app name from the workflow log: |
| 81 | + |
| 82 | +```text |
| 83 | +APP_NAME: ${REVIEW_APP_PREFIX}-${PR_NUMBER} |
| 84 | +``` |
| 85 | + |
| 86 | +This is a template from the workflow output, not a literal command to evaluate |
| 87 | +unless those environment variables are already set. For this repo, verify the |
| 88 | +actual `REVIEW_APP_PREFIX` repository variable before assuming the final app |
| 89 | +name. |
| 90 | + |
| 91 | +## Troubleshooting Signals |
| 92 | + |
| 93 | +### Composite action metadata fails before setup |
| 94 | + |
| 95 | +Error shape: |
| 96 | + |
| 97 | +```text |
| 98 | +Unrecognized named-value: 'vars' |
| 99 | +Failed to load ./.github/actions/cpflow-setup-environment/action.yml |
| 100 | +``` |
| 101 | + |
| 102 | +Cause: GitHub parsed a literal expression inside composite action metadata, |
| 103 | +usually an input description. Because trusted local actions come from `master`, |
| 104 | +fix and merge the generated action metadata on `master`, then rerun the deploy. |
| 105 | + |
| 106 | +### Setup succeeds, then `cpflow exists` reports token format |
| 107 | + |
| 108 | +Error shape: |
| 109 | + |
| 110 | +```text |
| 111 | +ERROR: Unknown API token format. Please re-run 'cpln profile login' or set the correct CPLN_TOKEN env variable. |
| 112 | +``` |
| 113 | + |
| 114 | +Cause: the workflow can read `CPLN_TOKEN_STAGING`, but the value is not a valid |
| 115 | +Control Plane service-account token for the installed Control Plane CLI. Rotate |
| 116 | +the GitHub secret, then rerun the failed deploy job. |
| 117 | + |
| 118 | +### PR pushes do not create a new review app |
| 119 | + |
| 120 | +This is expected. Pushes redeploy only after the review app already exists. |
| 121 | +Create the first review app by commenting exactly: |
| 122 | + |
| 123 | +```text |
| 124 | ++review-app-deploy |
| 125 | +``` |
| 126 | + |
| 127 | +## Ways To Make This Easier |
| 128 | + |
| 129 | +- Add a no-secret GitHub Actions smoke workflow that loads generated local |
| 130 | + composite actions from the PR branch and fails fast on action metadata parsing. |
| 131 | +- Extend `bin/test-cpflow-github-flow` as more local cpflow GitHub Actions |
| 132 | + checks become worth standardizing. |
| 133 | +- Add an early token sanity step after `Setup environment` so invalid |
| 134 | + `CPLN_TOKEN_STAGING` and `CPLN_TOKEN_PRODUCTION` values fail with a named |
| 135 | + "validate Control Plane token" step instead of surfacing later during |
| 136 | + `cpflow exists`. |
| 137 | +- Keep a tiny canary PR open for review-app workflow testing so post-merge |
| 138 | + deploy verification does not depend on whichever feature PR happens to exist. |
| 139 | +- Upstream the metadata-description check to `cpflow github-flow-readiness` so |
| 140 | + downstream repos get the guard automatically. |
0 commit comments