|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up Go |
| 18 | + uses: actions/setup-go@v4 |
| 19 | + with: |
| 20 | + go-version: '1.22' |
| 21 | + |
| 22 | + - name: Cache Go modules |
| 23 | + uses: actions/cache@v3 |
| 24 | + with: |
| 25 | + path: ~/go/pkg/mod |
| 26 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 27 | + restore-keys: | |
| 28 | + ${{ runner.os }}-go- |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: go mod download |
| 32 | + |
| 33 | + - name: Run go vet |
| 34 | + run: go vet ./... |
| 35 | + |
| 36 | + - name: Check formatting |
| 37 | + run: | |
| 38 | + if [ "$(gofmt -l .)" != "" ]; then |
| 39 | + echo "Code is not formatted. Run 'go fmt ./...' to fix." |
| 40 | + gofmt -l . |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | + - name: Build application |
| 45 | + run: | |
| 46 | + go build -o bin/golearn ./cmd/golearn |
| 47 | + chmod +x bin/golearn |
| 48 | + |
| 49 | + - name: Test build works |
| 50 | + run: | |
| 51 | + ./bin/golearn --help |
| 52 | + ./bin/golearn help |
| 53 | + |
| 54 | + - name: Test list command |
| 55 | + run: | |
| 56 | + ./bin/golearn list |
| 57 | + |
| 58 | + - name: Test progress command |
| 59 | + run: | |
| 60 | + ./bin/golearn progress |
| 61 | + |
| 62 | + - name: Test hint command (with valid exercise) |
| 63 | + run: | |
| 64 | + ./bin/golearn hint 01_hello || true |
| 65 | + |
| 66 | + - name: Test solution command (with valid exercise) |
| 67 | + run: | |
| 68 | + echo "n" | ./bin/golearn solution 01_hello |
| 69 | + |
| 70 | + - name: Test verify command (templates should fail) |
| 71 | + run: | |
| 72 | + echo "Testing that template exercises fail as expected..." |
| 73 | + if ./bin/golearn verify; then |
| 74 | + echo "FAILURE: Template exercises should fail but they passed - this indicates templates are complete when they should be incomplete for students to fill in" |
| 75 | + exit 1 |
| 76 | + else |
| 77 | + echo "SUCCESS: Template exercises failed as expected - templates are properly incomplete for student learning" |
| 78 | + fi |
| 79 | + |
| 80 | + - name: Test verify command with solutions (should pass) |
| 81 | + run: | |
| 82 | + echo "Testing that solution exercises pass..." |
| 83 | + # Test a few key exercises with their solutions |
| 84 | + ./bin/golearn verify 01_hello --solution |
| 85 | + ./bin/golearn verify 36_json --solution |
| 86 | + ./bin/golearn verify 37_xml --solution |
| 87 | + |
| 88 | + - name: Test specific template exercises (should fail) |
| 89 | + run: | |
| 90 | + echo "Testing that specific template exercises fail as expected..." |
| 91 | + failed_templates=() |
| 92 | + |
| 93 | + # Test a few key template exercises to ensure they fail |
| 94 | + for exercise in 01_hello 02_values 36_json 37_xml; do |
| 95 | + echo "Testing template exercise: $exercise" |
| 96 | + if ./bin/golearn verify "$exercise"; then |
| 97 | + echo "ERROR: Template $exercise should fail but passed - this template is complete when it should be incomplete for students to learn from" |
| 98 | + failed_templates+=("$exercise") |
| 99 | + else |
| 100 | + echo "SUCCESS: Template $exercise failed as expected - template is properly incomplete for student learning" |
| 101 | + fi |
| 102 | + done |
| 103 | + |
| 104 | + # Report results |
| 105 | + if [ ${#failed_templates[@]} -eq 0 ]; then |
| 106 | + echo "SUCCESS: All tested template exercises failed as expected - templates are properly incomplete for student learning" |
| 107 | + else |
| 108 | + echo "FAILURE: The following template exercises should have failed but passed - these templates are complete when they should be incomplete:" |
| 109 | + for exercise in "${failed_templates[@]}"; do |
| 110 | + echo " - $exercise" |
| 111 | + done |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + |
| 115 | + - name: Test reset command |
| 116 | + run: | |
| 117 | + ./bin/golearn reset 01_hello |
| 118 | + |
| 119 | + - name: Test init command (built-in templates) |
| 120 | + run: | |
| 121 | + ./bin/golearn init |
| 122 | + |
| 123 | + - name: Test error handling |
| 124 | + run: | |
| 125 | + # Test invalid commands |
| 126 | + ./bin/golearn invalid-command || true |
| 127 | + ./bin/golearn hint || true |
| 128 | + ./bin/golearn solution || true |
| 129 | + ./bin/golearn reset || true |
| 130 | + |
| 131 | + - name: Test theme options |
| 132 | + run: | |
| 133 | + ./bin/golearn --no-color list |
| 134 | + ./bin/golearn --theme=high-contrast list |
| 135 | + ./bin/golearn --theme=monochrome list |
| 136 | + |
| 137 | + - name: Test publish dry-run |
| 138 | + run: | |
| 139 | + ./bin/golearn publish --dry-run |
| 140 | + |
| 141 | + - name: Run exercise tests |
| 142 | + run: | |
| 143 | + echo "Running go tests for non-template exercise packages..." |
| 144 | + packages=$(go list ./internal/exercises/... | grep -v '/templates') |
| 145 | + if [ -n "$packages" ]; then |
| 146 | + go test $packages |
| 147 | + else |
| 148 | + echo "No non-template packages to test." |
| 149 | + fi |
| 150 | + |
| 151 | + - name: Test ALL exercise solutions (comprehensive) |
| 152 | + run: | |
| 153 | + echo "Testing ALL solution exercises to ensure they pass..." |
| 154 | + failed_exercises=() |
| 155 | + |
| 156 | + echo "Discovering exercises that actually have solution implementations..." |
| 157 | + exercises_to_test=() |
| 158 | + for dir in ./internal/exercises/solutions/*; do |
| 159 | + [ -d "$dir" ] || continue |
| 160 | + if ls "$dir"/*.go >/dev/null 2>&1; then |
| 161 | + exercises_to_test+=("$(basename "$dir")") |
| 162 | + fi |
| 163 | + done |
| 164 | +
|
| 165 | + if [ ${#exercises_to_test[@]} -eq 0 ]; then |
| 166 | + echo "No solution exercises found to test. Skipping." |
| 167 | + else |
| 168 | + for exercise in "${exercises_to_test[@]}"; do |
| 169 | + echo "Testing solution exercise: $exercise" |
| 170 | + if ./bin/golearn verify "$exercise" --solution; then |
| 171 | + echo "PASS: $exercise" |
| 172 | + else |
| 173 | + echo "FAIL: $exercise - solution implementation is broken or incomplete" |
| 174 | + failed_exercises+=("$exercise") |
| 175 | + fi |
| 176 | + done |
| 177 | +
|
| 178 | + if [ ${#failed_exercises[@]} -eq 0 ]; then |
| 179 | + echo "SUCCESS: All solution exercises passed - all solutions are working correctly" |
| 180 | + else |
| 181 | + echo "FAILURE: The following solution exercises failed - these solutions need to be fixed:" |
| 182 | + for exercise in "${failed_exercises[@]}"; do |
| 183 | + echo " - $exercise" |
| 184 | + done |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | + fi |
| 188 | + |
| 189 | + - name: Verify binary works in different directory |
| 190 | + run: | |
| 191 | + cd /tmp |
| 192 | + $GITHUB_WORKSPACE/bin/golearn --help |
| 193 | + |
| 194 | + - name: Test watch command (timeout after 5 seconds) |
| 195 | + run: | |
| 196 | + timeout 5s ./bin/golearn watch || true |
0 commit comments