You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/CICD.md
+58-6Lines changed: 58 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The project uses **3 separate workflows** to handle different aspects of the CI/
8
8
9
9
| Workflow | File | Purpose | Triggers |
10
10
|----------|------|---------|----------|
11
-
|**Flutter App CI/CD**|`build-deploy.yml`| Build, test, and deploy Flutter app | Push to `main`, PRs, copilot branches|
11
+
|**Flutter App CI/CD**|`build-deploy.yml`| Build, test, and deploy Flutter app | Push to `main`, PRs to `main`|
12
12
|**Cloudflare Worker**|`cloudflare-worker.yml`| Deploy API proxy worker and festivals data | Push to `main`, PRs (when worker/festivals.json changes) |
13
13
|**Release Web**|`release-web.yml`| Production web releases to Cloudflare Pages | Version tags (`v*`) |
14
14
@@ -28,17 +28,18 @@ Handles all Flutter app building, testing, and deployment workflows for staging,
28
28
```yaml
29
29
on:
30
30
push:
31
-
branches: [main, copilot/**]
31
+
branches: [main]
32
32
pull_request:
33
33
branches: [main]
34
34
workflow_dispatch:
35
35
```
36
36
37
37
- **Push to `main`**: Full build, test, deploy to Cloudflare Pages staging
38
-
- **Pull Requests**: Build, test, deploy preview to Cloudflare Pages
39
-
- **Push to `copilot/**`**: CI builds for Copilot branches
38
+
- **Pull Requests to `main`**: Build, test, deploy preview to Cloudflare Pages (runs once per push)
40
39
- **Manual**: Via workflow_dispatch in GitHub Actions UI
41
40
41
+
**Note**: The workflow triggers only on `pull_request` events for PR branches, not on `push` events, which prevents duplicate workflow runs when pushing commits to a PR branch.
42
+
42
43
### Jobs
43
44
44
45
#### A. `changes`
@@ -149,7 +150,6 @@ on:
149
150
- 'data/festivals.json'
150
151
- '.github/workflows/cloudflare-worker.yml'
151
152
pull_request:
152
-
branches: [main]
153
153
paths:
154
154
- 'cloudflare-worker/**'
155
155
- 'data/festivals.json'
@@ -158,9 +158,11 @@ on:
158
158
```
159
159
160
160
- **Push to `main`**: Deploy worker if worker or festivals.json changed
161
-
- **Pull Requests**: Validate worker (dry-run) if worker or festivals.json changed
161
+
- **Pull Requests**: Validate worker (dry-run) if worker or festivals.json changed (runs once per push)
162
162
- **Manual**: Via workflow_dispatch in GitHub Actions UI
163
163
164
+
**Note**: The `pull_request` trigger doesn't specify branches, allowing PRs from any branch while still running only once per push.
165
+
164
166
### Jobs
165
167
166
168
#### A. `changes`
@@ -677,6 +679,55 @@ gh run rerun <run-id>
677
679
678
680
---
679
681
682
+
## Avoiding Duplicate CI Runs
683
+
684
+
### Problem
685
+
686
+
When a workflow is configured with both `push` and `pull_request` triggers for the same branches, it can run twice for the same commit:
687
+
688
+
```yaml
689
+
# ❌ BAD: Causes duplicate runs on PR pushes
690
+
on:
691
+
push:
692
+
branches: [main, feature/**]
693
+
pull_request:
694
+
branches: [main]
695
+
```
696
+
697
+
**Result**: Push to a PR branch → workflow runs on `push` event **AND** on `pull_request` event = **2 runs** 💰💸
698
+
699
+
### Solution
700
+
701
+
Our workflows are configured to run **only once** per commit:
702
+
703
+
```yaml
704
+
# ✅ GOOD: Runs only once per PR push
705
+
on:
706
+
push:
707
+
branches: [main] # Only run on direct pushes to main
708
+
pull_request:
709
+
branches: [main] # Run on all PRs targeting main
710
+
```
711
+
712
+
**Result**:
713
+
- Push to a PR branch → workflow runs **only** on `pull_request` event = **1 run** ✅
714
+
- Push directly to main → workflow runs **only** on `push` event = **1 run** ✅
2. **Faster feedback** - No waiting for duplicate runs to complete
720
+
3. **Cleaner UI** - Fewer runs to monitor in the Actions tab
721
+
4. **Resource efficiency** - Less CI queue contention
722
+
723
+
### Additional Notes
724
+
725
+
- The `pull_request` trigger in some workflows (e.g., `cloudflare-worker.yml`) doesn't specify `branches`, which allows PRs from any branch while still maintaining single-run behavior
726
+
- The `workflow_dispatch` trigger allows manual runs when needed
727
+
- Concurrency groups ensure that new pushes to the same branch cancel in-progress runs (except on `main`)
728
+
729
+
---
730
+
680
731
## Summary
681
732
682
733
The Cambridge Beer Festival app uses **3 specialized workflows**:
@@ -690,3 +741,4 @@ This separation provides:
690
741
- **Independent triggers** - Worker can deploy without rebuilding app
691
742
- **Optimized execution** - Only relevant jobs run for each change
692
743
- **Better monitoring** - Easier to track specific deployment types
744
+
- **Single run per commit** - Avoids duplicate CI runs on PR pushes
0 commit comments