Skip to content

Commit 9ca947d

Browse files
authored
chore: refactoring and cleaning up the code to adhere to standards (#105)
1 parent 0d451ad commit 9ca947d

15 files changed

Lines changed: 1242 additions & 123 deletions

File tree

.github/workflows/ci.yml

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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

.github/workflows/pages.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy Jekyll site to Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: '3.1'
28+
bundler-cache: true
29+
30+
- name: Setup Pages
31+
uses: actions/configure-pages@v4
32+
33+
- name: Build with Jekyll
34+
run: |
35+
cd docs
36+
bundle install --path vendor/bundle
37+
bundle exec jekyll build
38+
env:
39+
JEKYLL_ENV: production
40+
41+
- name: Upload artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: ./docs/_site
45+
46+
deploy:
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
runs-on: ubuntu-latest
51+
needs: build
52+
steps:
53+
- name: Deploy to GitHub Pages
54+
id: deployment
55+
uses: actions/deploy-pages@v4

docs/Gemfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
source "https://rubygems.org"
2+
3+
gem "jekyll", "~> 4.3"
4+
gem "minima", "~> 2.5"
5+
6+
group :jekyll_plugins do
7+
gem "jekyll-feed", "~> 0.12"
8+
gem "jekyll-sitemap"
9+
gem "jekyll-seo-tag"
10+
end
11+
12+
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
13+
# and associated library.
14+
platforms :mingw, :x64_mingw, :mswin, :jruby do
15+
gem "tzinfo", ">= 1", "< 3"
16+
gem "tzinfo-data"
17+
end
18+
19+
# Performance-booster for watching directories on Windows
20+
gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
21+
22+
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
23+
# do not have a Java counterpart.
24+
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

docs/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# GoLearn Documentation
2+
3+
This directory contains the Jekyll-based documentation website for GoLearn.
4+
5+
## Local Development
6+
7+
To run the documentation site locally:
8+
9+
1. Install Ruby and Bundler
10+
2. Install dependencies:
11+
```bash
12+
cd docs
13+
bundle install
14+
```
15+
3. Start the Jekyll server:
16+
```bash
17+
bundle exec jekyll serve
18+
```
19+
4. Open http://localhost:4000 in your browser
20+
21+
## Deployment
22+
23+
The site is automatically deployed to GitHub Pages when changes are pushed to the main branch.
24+
25+
## Structure
26+
27+
- `_config.yml` - Jekyll configuration
28+
- `_layouts/` - HTML templates
29+
- `_includes/` - Reusable components
30+
- `assets/` - CSS, JS, and other assets
31+
- `*.md` - Markdown pages
32+
33+
## Theme
34+
35+
The site uses a custom gopher-themed design with:
36+
- Playful gopher animations
37+
- Go-inspired color scheme
38+
- Responsive design
39+
- Clean, readable typography

docs/_config.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# GoLearn Documentation Site
2+
# A fun, gopher-themed Jekyll site for Go learning
3+
4+
title: GoLearn
5+
description: "Learn Go the fun way! A Rustlings-style interactive Go tutorial with gopher-powered exercises."
6+
author: "GoLearn Team"
7+
email: "golearn@example.com"
8+
url: "https://golearn.dev"
9+
baseurl: ""
10+
11+
# Jekyll configuration
12+
markdown: kramdown
13+
highlighter: rouge
14+
theme: minima
15+
plugins:
16+
- jekyll-feed
17+
- jekyll-sitemap
18+
- jekyll-seo-tag
19+
20+
# Site settings
21+
exclude:
22+
- Gemfile
23+
- Gemfile.lock
24+
- README.md
25+
- vendor/
26+
27+
# Collections
28+
collections:
29+
exercises:
30+
output: true
31+
permalink: /:name/
32+
33+
# Default layouts
34+
defaults:
35+
- scope:
36+
path: ""
37+
type: "pages"
38+
values:
39+
layout: "default"
40+
- scope:
41+
path: ""
42+
type: "exercises"
43+
values:
44+
layout: "exercise"
45+
46+
# Navigation
47+
header_pages:
48+
- index.md
49+
- getting-started.md
50+
- exercises.md
51+
- contributing.md
52+
- about.md
53+
54+
# Gopher theme settings
55+
gopher_theme:
56+
primary_color: "#00ADD8" # Go blue
57+
secondary_color: "#5DC9E2" # Light blue
58+
accent_color: "#FF6B6B" # Fun red
59+
text_color: "#2D3748" # Dark gray
60+
background_color: "#F7FAFC" # Light gray
61+
62+
# Social links (optional)
63+
social:
64+
github: "your-username/golearn"
65+
twitter: "golearn_dev"

0 commit comments

Comments
 (0)