Skip to content

Commit c9559e3

Browse files
Copilotneilime
andcommitted
docs: document CI testing strategy for actions
Add documentation explaining how CI tests local GitHub Actions using arrange-act-assert patterns and how tests adapt to different trigger contexts (branch push, tag push, PR). Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent 6b0d5ca commit c9559e3

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.github/workflows/__test-action-docker-build-image.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ jobs:
123123
expectedTags.push(refTag);
124124
expectedImageVersion = refTag;
125125
126-
if (`${{ github.event_name }}` === "push" && refTag === "${{ github.event.repository.default_branch }}") {
126+
const isTag = `${{ github.ref }}`.startsWith('refs/tags/');
127+
const isPushOnDefaultBranch = `${{ github.event_name }}` === "push" && !isTag && refTag === "${{ github.event.repository.default_branch }}";
128+
129+
if (isPushOnDefaultBranch) {
127130
expectedTags.push("latest");
128131
}
129132
}

.github/workflows/__test-action-get-image-metadata.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ jobs:
8686
8787
expectedTags.push(prShaTag, prTag);
8888
} else {
89-
expectedTags.push("main");
90-
if (`${{ github.event_name }}` === "push" && `${{ github.ref_name }}` === "${{ github.event.repository.default_branch }}") {
89+
const refTag = `${{ github.ref_name }}`;
90+
expectedTags.push(refTag);
91+
92+
const isTag = `${{ github.ref }}`.startsWith('refs/tags/');
93+
const isPushOnDefaultBranch = `${{ github.event_name }}` === "push" && !isTag && refTag === "${{ github.event.repository.default_branch }}";
94+
95+
if (isPushOnDefaultBranch) {
9196
expectedTags.push("latest");
9297
}
9398
}

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This project contains **opinionated GitHub Actions and reusable workflows** to s
1717
- **[Reusable Workflows](README.md#reusable-workflows)** – Orchestration playbooks for common CI tasks
1818
- **[Contributing](README.md#contributing)** – Contribution guidelines, action structure patterns, and development standards
1919
- **[Development Workflow](README.md#development-workflow)** – Commands for linting, testing, and local development
20+
- **[CI Testing Strategy](README.md#ci-testing-strategy)** – How we test local actions with arrange-act-assert patterns across different trigger contexts
2021

2122
## Agent-Specific Development Patterns
2223

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ make test-build-application # Build and push the sample test application image
121121
make test-ct-install # Validate Helm charts via chart-testing
122122
```
123123

124+
#### CI Testing Strategy
125+
126+
The repository includes comprehensive end-to-end tests for all local GitHub Actions. These tests follow an **Arrange-Act-Assert** pattern:
127+
128+
1. **Arrange**: Set up test fixtures and inputs (e.g., checkout code, prepare test context)
129+
2. **Act**: Execute the action being tested with specific inputs
130+
3. **Assert**: Validate outputs match expected values using `actions/github-script`
131+
132+
Test workflows are located in `.github/workflows/__test-action-*.yml` and `.github/workflows/__test-workflow-*.yml`. They run on:
133+
134+
- Push to `main` branch
135+
- Push to tags (e.g., `v1.0.0`)
136+
- Pull request events
137+
- Scheduled runs (weekly)
138+
139+
**Tag-specific behavior**: When tests run on tag pushes, assertions dynamically adapt to expect the tag name (e.g., `v1.0.0`) instead of branch names. This ensures tests pass in all trigger contexts without hardcoding expected values.
140+
124141
## Author
125142

126143
🏢 **Hoverkraft <contact@hoverkraft.cloud>**

0 commit comments

Comments
 (0)