Skip to content

Commit bf5c87e

Browse files
authored
Merge pull request #25 from aspicas/fix/cicd
feat(workflows): introduce GitHub Actions testing scripts and configu…
2 parents 694c5d9 + 3f43c6f commit bf5c87e

15 files changed

+1336
-88
lines changed

.actrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Act configuration for flutter_policy_engine
2+
# This file is auto-generated by test_github_actions.sh
3+
4+
# Use medium-sized image for better compatibility
5+
-P ubuntu-latest=catthehacker/ubuntu:act-latest
6+
7+
# Environment variables
8+
--env-file .env
9+
10+
# Secrets (you can create a .secrets file for local testing)
11+
--secret-file .secrets
12+
13+
# Bind mounts for better performance
14+
--bind
15+
16+
# Reuse containers when possible
17+
--reuse
18+
19+
# Show timestamps
20+
--verbose

.github/workflows/check-commits.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: 🛡️ Validate Commit Messages
33
on:
44
push:
55
pull_request:
6+
branches-ignore:
7+
- main
8+
- develop
69

710
jobs:
811
check-commits:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: 🚀 Main Branch Pipeline
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
# Step 1: Validate commit messages
10+
check-commits:
11+
name: Validate Commit Messages
12+
runs-on: ubuntu-latest
13+
outputs:
14+
commits-validated: ${{ steps.validate-commits.outputs.result }}
15+
steps:
16+
- name: ⬇️ Checkout code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: ⬢ Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
26+
- name: 📦 Install Commitlint
27+
run: |
28+
npm install --save-dev @commitlint/{config-conventional,cli}
29+
30+
- name: 🔍 Validate commit messages (entire branch)
31+
id: validate-commits
32+
run: |
33+
npx commitlint --from=$(git rev-list --max-parents=0 HEAD) --to=HEAD --verbose
34+
echo "result=success" >> $GITHUB_OUTPUT
35+
36+
# Step 2: Run Flutter tests
37+
test:
38+
name: Flutter Tests & Coverage
39+
runs-on: ubuntu-latest
40+
needs: check-commits
41+
if: needs.check-commits.outputs.commits-validated == 'success'
42+
outputs:
43+
tests-passed: ${{ steps.run-tests.outputs.result }}
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Flutter
49+
uses: subosito/flutter-action@v2
50+
with:
51+
flutter-version: "3.29.3"
52+
architecture: "x64"
53+
54+
- name: Install dependencies
55+
run: flutter pub get
56+
57+
- name: Verify formatting
58+
run: dart format --set-exit-if-changed .
59+
60+
- name: Analyze project source
61+
run: flutter analyze
62+
63+
- name: Run tests with coverage
64+
id: run-tests
65+
run: |
66+
flutter test --coverage
67+
echo "result=success" >> $GITHUB_OUTPUT

.github/workflows/main-branch-pipeline.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: 🚀 Main Branch Pipeline
22

33
on:
4-
push:
5-
branches:
6-
- main
74
pull_request:
85
branches:
96
- main
@@ -89,28 +86,3 @@ jobs:
8986
run: |
9087
flutter test --coverage
9188
echo "result=success" >> $GITHUB_OUTPUT
92-
93-
# Step 4: Release
94-
release:
95-
name: Release
96-
runs-on: ubuntu-latest
97-
needs: test
98-
if: needs.test.outputs.tests-passed == 'success'
99-
steps:
100-
- name: ⬇️ Checkout code
101-
uses: actions/checkout@v3
102-
with:
103-
fetch-depth: 0
104-
105-
- name: ⬢ Setup Node
106-
uses: actions/setup-node@v4
107-
with:
108-
node-version: 20
109-
110-
- name: 📦 Install dependencies
111-
run: npm ci
112-
113-
- name: 🚀 Run semantic-release
114-
env:
115-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
116-
run: npx semantic-release

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 🚀 Release Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release-push:
10+
name: Release Push
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: ⬇️ Checkout code
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- name: ⬢ Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
23+
- name: 📦 Install dependencies
24+
run: npm ci
25+
26+
- name: 🚀 Run semantic-release
27+
env:
28+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
29+
run: npx semantic-release

.github/workflows/test.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/validate-resource.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ genhtml coverage/lcov.info -o coverage/html
165165
open coverage/html/index.html
166166
```
167167

168+
### GitHub Actions Testing
169+
170+
Test GitHub Actions workflows locally before pushing to GitHub:
171+
172+
```bash
173+
# Install dependencies (first time only)
174+
./scripts/install_dependencies.sh
175+
176+
# Test a specific workflow
177+
./scripts/test_github_actions.sh -w .github/workflows/check-commits.yml --dry-run
178+
179+
# List available workflows
180+
./scripts/test_github_actions.sh --list-workflows
181+
182+
# Test with verbose output
183+
./scripts/test_github_actions.sh -w .github/workflows/main-branch-pipeline.yml -v
184+
```
185+
186+
**Features:**
187+
188+
- 🐳 Docker-based local testing with `act`
189+
- 🔍 Workflow validation and syntax checking
190+
- 🧪 Dry-run mode for safe testing
191+
- 📋 Comprehensive workflow coverage
192+
- 🛠️ Automatic dependency management
193+
194+
For detailed usage, see [GitHub Actions Testing Guide](scripts/README.md).
195+
168196
### Example App
169197

170198
Explore the interactive example app:

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/CHANGELOG.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# GitHub Actions Testing Scripts Changelog
2+
3+
## [1.0.0] - 2025-07-24
4+
5+
### Added
6+
7+
- **GitHub Actions Testing Script** (`test_github_actions.sh`)
8+
9+
- Comprehensive script to test GitHub Actions workflows locally using `act` and Docker
10+
- Support for all project workflows: main-branch-pipeline, develop-branch-pipeline, check-commits, and release
11+
- Dry-run mode for safe testing without execution
12+
- Verbose output for debugging
13+
- Automatic workflow validation and syntax checking
14+
- Smart defaults based on workflow type
15+
- Colored output with timestamps
16+
- Automatic cleanup of Docker containers
17+
18+
- **Dependency Installation Script** (`install_dependencies.sh`)
19+
20+
- Cross-platform installation of `act` CLI tool
21+
- Docker installation and setup guidance
22+
- Python dependencies management (PyYAML for YAML validation)
23+
- Automatic environment file setup (.env and .secrets)
24+
- Installation verification and health checks
25+
- Support for macOS, Linux, and Windows
26+
27+
- **Configuration Files**
28+
29+
- `.actrc` - Optimized act configuration for the project
30+
- `env.example` - Template for environment variables
31+
- `secrets.example` - Template for secrets configuration
32+
- Comprehensive documentation in `README.md`
33+
34+
- **Documentation**
35+
- Detailed usage guide with examples
36+
- Troubleshooting section
37+
- Integration examples for CI/CD pipelines
38+
- Pre-commit hook examples
39+
- Cross-platform installation instructions
40+
41+
### Features
42+
43+
- **Workflow Testing**: Test any GitHub Actions workflow locally before pushing
44+
- **Event Simulation**: Simulate push, pull_request, and other GitHub events
45+
- **Branch Support**: Test workflows with different branch scenarios
46+
- **Validation**: YAML syntax validation and workflow correctness checking
47+
- **Performance**: Optimized Docker image usage and container reuse
48+
- **Safety**: Dry-run mode prevents accidental execution
49+
- **Debugging**: Verbose mode for detailed troubleshooting
50+
51+
### Supported Workflows
52+
53+
1. **Main Branch Pipeline** - Validates PRs to main branch
54+
2. **Develop Branch Pipeline** - Validates PRs to develop branch
55+
3. **Check Commits** - Validates commit messages on all branches
56+
4. **Release Pipeline** - Tests semantic-release automation
57+
58+
### Prerequisites
59+
60+
- Docker (running)
61+
- Git repository
62+
- act CLI (auto-installed by script)
63+
- Python 3 (optional, for enhanced YAML validation)
64+
65+
### Quick Start
66+
67+
```bash
68+
# Install dependencies
69+
./scripts/install_dependencies.sh
70+
71+
# Test a workflow
72+
./scripts/test_github_actions.sh -w .github/workflows/check-commits.yml --dry-run
73+
74+
# List available workflows
75+
./scripts/test_github_actions.sh --list-workflows
76+
```
77+
78+
### Breaking Changes
79+
80+
None - This is a new feature addition.
81+
82+
### Deprecations
83+
84+
None.
85+
86+
### Removed
87+
88+
None.
89+
90+
### Fixed
91+
92+
None.
93+
94+
### Security
95+
96+
- Secure handling of secrets through `.secrets` file
97+
- Automatic cleanup of Docker containers
98+
- Validation of workflow files before execution
99+
- Safe defaults for environment variables
100+
101+
### Performance
102+
103+
- Optimized Docker image selection (`catthehacker/ubuntu:act-latest`)
104+
- Container reuse for faster subsequent runs
105+
- Bind mounts for better performance
106+
- Efficient workflow parsing and validation
107+
108+
### Documentation
109+
110+
- Comprehensive README with examples
111+
- Inline help for all scripts
112+
- Troubleshooting guide
113+
- Integration examples
114+
- Cross-platform installation instructions

0 commit comments

Comments
 (0)