Skip to content

Commit 976ff26

Browse files
Merge pull request #129 from richardthe3rd/copilot/configure-ci-for-pr-push
Configure CI workflows to run once per PR push
2 parents 1d94bcf + 6ddd94e commit 976ff26

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

.github/workflows/build-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Flutter App CI/CD
22

33
on:
44
push:
5-
branches: [main, copilot/**]
5+
branches: [main]
66
pull_request:
77
branches: [main]
88
workflow_dispatch:

.github/workflows/cloudflare-worker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
- 'data/festivals.json'
99
- '.github/workflows/cloudflare-worker.yml'
1010
pull_request:
11-
branches: [main]
1211
paths:
1312
- 'cloudflare-worker/**'
1413
- 'data/festivals.json'

.github/workflows/devcontainer.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
- 'mise.dev.toml'
1010
- '.github/workflows/devcontainer.yml'
1111
pull_request:
12-
branches: [main]
1312
paths:
1413
- '.devcontainer/**'
1514
- 'mise.toml'

docs/CICD.md

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The project uses **3 separate workflows** to handle different aspects of the CI/
88

99
| Workflow | File | Purpose | Triggers |
1010
|----------|------|---------|----------|
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` |
1212
| **Cloudflare Worker** | `cloudflare-worker.yml` | Deploy API proxy worker and festivals data | Push to `main`, PRs (when worker/festivals.json changes) |
1313
| **Release Web** | `release-web.yml` | Production web releases to Cloudflare Pages | Version tags (`v*`) |
1414

@@ -28,17 +28,18 @@ Handles all Flutter app building, testing, and deployment workflows for staging,
2828
```yaml
2929
on:
3030
push:
31-
branches: [main, copilot/**]
31+
branches: [main]
3232
pull_request:
3333
branches: [main]
3434
workflow_dispatch:
3535
```
3636
3737
- **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)
4039
- **Manual**: Via workflow_dispatch in GitHub Actions UI
4140

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+
4243
### Jobs
4344

4445
#### A. `changes`
@@ -149,7 +150,6 @@ on:
149150
- 'data/festivals.json'
150151
- '.github/workflows/cloudflare-worker.yml'
151152
pull_request:
152-
branches: [main]
153153
paths:
154154
- 'cloudflare-worker/**'
155155
- 'data/festivals.json'
@@ -158,9 +158,11 @@ on:
158158
```
159159

160160
- **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)
162162
- **Manual**: Via workflow_dispatch in GitHub Actions UI
163163

164+
**Note**: The `pull_request` trigger doesn't specify branches, allowing PRs from any branch while still running only once per push.
165+
164166
### Jobs
165167

166168
#### A. `changes`
@@ -677,6 +679,55 @@ gh run rerun <run-id>
677679

678680
---
679681

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** ✅
715+
716+
### Benefits
717+
718+
1. **Cost savings** - Reduces GitHub Actions minutes usage by 50%
719+
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+
680731
## Summary
681732

682733
The Cambridge Beer Festival app uses **3 specialized workflows**:
@@ -690,3 +741,4 @@ This separation provides:
690741
- **Independent triggers** - Worker can deploy without rebuilding app
691742
- **Optimized execution** - Only relevant jobs run for each change
692743
- **Better monitoring** - Easier to track specific deployment types
744+
- **Single run per commit** - Avoids duplicate CI runs on PR pushes

0 commit comments

Comments
 (0)