|
| 1 | +# Testing GitHub Actions Workflows Before Merging |
| 2 | + |
| 3 | +When modifying reusable or scheduled workflows (e.g., `nightly.yaml`, `schemaspy.yaml`), you often can't test changes directly because: |
| 4 | + |
| 5 | +- **Scheduled workflows** (`on: schedule`) always run from the default branch. |
| 6 | +- **`workflow_dispatch`** only works for workflows that already exist on the default branch. |
| 7 | +- **Reusable workflows** (`on: workflow_call`) can't be triggered directly. |
| 8 | + |
| 9 | +## Recommended Approach: Temporary Push-Triggered Workflow |
| 10 | + |
| 11 | +Create a temporary workflow file on your feature branch that triggers on `push` and calls the reusable workflow you're testing. |
| 12 | + |
| 13 | +### 1. Create the temporary workflow |
| 14 | + |
| 15 | +Add a file like `.github/workflows/test-my-fix.yaml`: |
| 16 | + |
| 17 | +```yaml |
| 18 | +# Temporary workflow - delete before merging. |
| 19 | +name: Test My Fix |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + branches: |
| 24 | + - my-feature-branch |
| 25 | + |
| 26 | +jobs: |
| 27 | + test-job: |
| 28 | + uses: ./.github/workflows/the-reusable-workflow.yaml |
| 29 | + secrets: inherit |
| 30 | +``` |
| 31 | +
|
| 32 | +### 2. Commit and push |
| 33 | +
|
| 34 | +Push the temporary workflow along with your fixes. The workflow runs automatically on push, using the reusable workflow files **from your branch** (not from `develop`). |
| 35 | + |
| 36 | +### 3. Check results |
| 37 | + |
| 38 | +**Using the GitHub UI:** |
| 39 | + |
| 40 | +1. Go to the repository on GitHub. |
| 41 | +2. Click the **Actions** tab. |
| 42 | +3. Find your workflow name (e.g., "Test My Fix") in the left sidebar. |
| 43 | +4. Click into the run to see step-by-step logs and status. |
| 44 | +5. If a run was canceled by a concurrent push, click **Re-run all jobs** to retry. |
| 45 | + |
| 46 | +**Using the GitHub CLI (optional):** |
| 47 | + |
| 48 | +```bash |
| 49 | +gh run list --workflow=test-my-fix.yaml |
| 50 | +gh run watch |
| 51 | +``` |
| 52 | + |
| 53 | +### 4. Clean up |
| 54 | + |
| 55 | +Delete the temporary workflow file before merging your PR. |
| 56 | + |
| 57 | +## Limitations |
| 58 | + |
| 59 | +- **`github.event_name`** will be `push`, not `schedule`. Conditionals that check for `schedule` (e.g., disabling Happo) won't activate. For those, verify the logic by reading the code; the conditional behavior itself is deterministic. |
| 60 | +- **Concurrency settings** in the reusable workflow may cancel runs if you push multiple times quickly. Wait for a run to finish or re-run from the Actions tab. |
| 61 | +- **Timeouts** from the reusable workflow still apply. If a full checkout replaces a sparse checkout, you may need to increase the timeout. |
0 commit comments