Skip to content

Commit 0d0145e

Browse files
Add comprehensive GitHub Actions CI/CD pipeline for multi-platform testing
- Add CI workflow for Ubuntu, macOS, and Windows testing - Add release workflow for automated binary builds - Configure Dependabot for GitHub Actions updates - Include platform-specific testing and CLI functionality validation - Add comprehensive documentation for CI/CD setup - Include word transformer improvements and architecture updates
1 parent 547ac40 commit 0d0145e

9 files changed

Lines changed: 1143 additions & 65 deletions

File tree

.github/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# GitHub Actions CI/CD Setup
2+
3+
This directory contains the GitHub Actions workflows for the Amber CLI project, providing comprehensive continuous integration and deployment across all major operating systems.
4+
5+
## Workflows
6+
7+
### 1. CI Workflow (`.github/workflows/ci.yml`)
8+
9+
**Triggers:** Push to main/master branches, Pull Requests
10+
11+
**Purpose:** Ensures code quality and compatibility across platforms
12+
13+
**Jobs:**
14+
- **test**: Runs on Ubuntu, macOS, and Windows
15+
- Installs Crystal using platform-specific methods
16+
- Caches shard dependencies for faster builds
17+
- Checks code formatting with `crystal tool format`
18+
- Runs Ameba linter (with soft failure)
19+
- Compiles the project to ensure no build errors
20+
- Runs the full test suite with `crystal spec`
21+
- Builds a release binary (Linux only)
22+
23+
- **platform-specific**: Additional platform-specific testing
24+
- Tests CLI functionality by running `--help` and `--version`
25+
- Ensures the compiled binary works on each platform
26+
27+
- **integration**: Runs integration tests if they exist
28+
- Currently checks for and runs tests in `spec/integration/`
29+
30+
### 2. Release Workflow (`.github/workflows/release.yml`)
31+
32+
**Triggers:** Push to version tags (`v*`), Manual dispatch
33+
34+
**Purpose:** Builds and publishes release binaries for all platforms
35+
36+
**Features:**
37+
- Builds static binaries for Linux (fully portable)
38+
- Builds optimized binaries for macOS and Windows
39+
- Automatically creates GitHub releases with binaries attached
40+
- Generates release notes automatically
41+
42+
### 3. Dependabot Configuration (`.github/dependabot.yml`)
43+
44+
**Purpose:** Keeps GitHub Actions dependencies up to date
45+
46+
**Features:**
47+
- Weekly updates for GitHub Actions
48+
- Ready for Crystal shards support when available
49+
50+
## Platform-Specific Notes
51+
52+
### Linux (Ubuntu Latest)
53+
- Uses the official Crystal installer script
54+
- Builds static binaries for maximum portability
55+
- Includes build-essential for static compilation
56+
57+
### macOS (macOS Latest)
58+
- Installs Crystal via Homebrew
59+
- Builds standard dynamic binaries
60+
61+
### Windows (Windows Latest)
62+
- Installs Crystal via Chocolatey
63+
- Uses PowerShell for Windows-specific commands
64+
- Some CLI tests use `continue-on-error` due to potential Windows-specific issues
65+
66+
## Caching Strategy
67+
68+
The workflows use GitHub Actions caching to speed up builds:
69+
- **Shard cache**: Caches `~/.cache/shards` and `./lib` based on `shard.lock` hash
70+
- **OS-specific**: Separate caches for each operating system
71+
72+
## Usage
73+
74+
### For Contributors
75+
1. The CI workflow runs automatically on every push and pull request
76+
2. All tests must pass on all platforms before merging
77+
3. Code formatting and linting issues are reported but don't fail the build
78+
79+
### For Releases
80+
1. Create a git tag with version format: `git tag v1.0.0`
81+
2. Push the tag: `git push origin v1.0.0`
82+
3. The release workflow automatically builds binaries for all platforms
83+
4. A GitHub release is created with the binaries attached
84+
85+
### Manual Testing
86+
You can trigger the release workflow manually from the GitHub Actions tab for testing purposes.
87+
88+
## Troubleshooting
89+
90+
### Common Issues
91+
1. **Crystal installation fails**: Usually due to temporary network issues or package manager problems
92+
2. **Shard installation fails**: Often due to missing system dependencies
93+
3. **Windows-specific failures**: Crystal on Windows can be less stable; some tests use `continue-on-error`
94+
95+
### Debugging
96+
- Check the Actions tab in your GitHub repository for detailed logs
97+
- Each step shows its output and any error messages
98+
- Failed workflows will show which specific step failed
99+
100+
## Adding New Tests
101+
102+
To add new tests that run in CI:
103+
1. Add test files to the `spec/` directory
104+
2. Integration tests go in `spec/integration/`
105+
3. The workflows will automatically pick up and run new tests
106+
107+
## Future Improvements
108+
109+
1. **Code coverage reporting**: Add a code coverage tool
110+
2. **Performance benchmarks**: Track performance across releases
111+
3. **Docker builds**: Add containerized builds for additional consistency
112+
4. **Cross-compilation**: Explore Crystal's cross-compilation features
113+
5. **Shard dependency updates**: When Dependabot supports Crystal, enable automatic dependency updates

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
# Enable version updates for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
open-pull-requests-limit: 10
9+
10+
# Enable version updates for Crystal dependencies (shards)
11+
# Note: Dependabot doesn't natively support Crystal shards yet,
12+
# but this configuration is ready for when support is added
13+
# - package-ecosystem: "bundler"
14+
# directory: "/"
15+
# schedule:
16+
# interval: "weekly"
17+
# open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
crystal: [latest]
17+
include:
18+
- os: ubuntu-latest
19+
crystal-install: |
20+
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
21+
- os: macos-latest
22+
crystal-install: |
23+
brew install crystal
24+
- os: windows-latest
25+
crystal-install: |
26+
choco install crystal
27+
28+
name: Test on ${{ matrix.os }} with Crystal ${{ matrix.crystal }}
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Install Crystal (Ubuntu)
35+
if: matrix.os == 'ubuntu-latest'
36+
run: |
37+
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
38+
crystal version
39+
40+
- name: Install Crystal (macOS)
41+
if: matrix.os == 'macos-latest'
42+
run: |
43+
brew install crystal
44+
crystal version
45+
46+
- name: Install Crystal (Windows)
47+
if: matrix.os == 'windows-latest'
48+
run: |
49+
choco install crystal -y
50+
crystal version
51+
shell: powershell
52+
53+
- name: Cache shards
54+
uses: actions/cache@v3
55+
with:
56+
path: |
57+
~/.cache/shards
58+
./lib
59+
key: ${{ runner.os }}-shards-${{ hashFiles('shard.lock') }}
60+
restore-keys: |
61+
${{ runner.os }}-shards-
62+
63+
- name: Install dependencies
64+
run: shards install
65+
66+
- name: Check code formatting
67+
run: crystal tool format --check
68+
continue-on-error: true
69+
70+
- name: Run ameba linter
71+
run: ./bin/ameba
72+
continue-on-error: true
73+
74+
- name: Compile project
75+
run: crystal build src/amber_cli.cr --no-debug
76+
77+
- name: Run tests
78+
run: crystal spec
79+
80+
- name: Build release binary
81+
run: crystal build src/amber_cli.cr --release --no-debug -o amber_cli
82+
if: matrix.os == 'ubuntu-latest'
83+
84+
- name: Upload binary artifact (Linux)
85+
uses: actions/upload-artifact@v3
86+
if: matrix.os == 'ubuntu-latest'
87+
with:
88+
name: amber_cli-linux
89+
path: amber_cli
90+
91+
# Separate job for additional platform-specific tests
92+
platform-specific:
93+
runs-on: ${{ matrix.os }}
94+
strategy:
95+
matrix:
96+
os: [ubuntu-latest, macos-latest, windows-latest]
97+
98+
name: Platform-specific tests on ${{ matrix.os }}
99+
needs: test
100+
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v4
104+
105+
- name: Install Crystal (Ubuntu)
106+
if: matrix.os == 'ubuntu-latest'
107+
run: |
108+
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
109+
110+
- name: Install Crystal (macOS)
111+
if: matrix.os == 'macos-latest'
112+
run: |
113+
brew install crystal
114+
115+
- name: Install Crystal (Windows)
116+
if: matrix.os == 'windows-latest'
117+
run: |
118+
choco install crystal -y
119+
shell: powershell
120+
121+
- name: Install dependencies
122+
run: shards install
123+
124+
- name: Test CLI functionality (Unix)
125+
if: matrix.os != 'windows-latest'
126+
run: |
127+
crystal build src/amber_cli.cr -o amber_cli
128+
./amber_cli --help || true
129+
./amber_cli --version || true
130+
131+
- name: Test CLI functionality (Windows)
132+
if: matrix.os == 'windows-latest'
133+
run: |
134+
crystal build src/amber_cli.cr -o amber_cli.exe
135+
.\amber_cli.exe --help
136+
.\amber_cli.exe --version
137+
shell: powershell
138+
continue-on-error: true
139+
140+
# Job to run integration tests
141+
integration:
142+
runs-on: ubuntu-latest
143+
name: Integration tests
144+
needs: test
145+
146+
steps:
147+
- name: Checkout code
148+
uses: actions/checkout@v4
149+
150+
- name: Install Crystal
151+
run: |
152+
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
153+
154+
- name: Install dependencies
155+
run: shards install
156+
157+
- name: Run integration tests
158+
run: |
159+
if [ -d "spec/integration" ]; then
160+
crystal spec spec/integration/
161+
else
162+
echo "No integration tests found, skipping..."
163+
fi

0 commit comments

Comments
 (0)