Skip to content

Commit 9b67a4d

Browse files
Merge branch 'main' into add-solution-30-task-scheduler
2 parents 8583ba5 + 23993a6 commit 9b67a4d

48 files changed

Lines changed: 939 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,35 @@ jobs:
7373
echo "next=$next" >> $GITHUB_OUTPUT
7474
7575
- name: Create tag and release
76+
id: create_release
7677
env:
7778
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
7879
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
7980
run: |
8081
next="${{ steps.next.outputs.next }}"
8182
echo "Creating release: $next"
8283
83-
# Create and push tag
84-
git tag "$next"
85-
git push origin "$next"
84+
# Check if tag already exists
85+
if git rev-parse "$next" >/dev/null 2>&1; then
86+
echo "Tag $next already exists, skipping tag creation"
87+
else
88+
# Create and push tag
89+
git tag "$next"
90+
git push origin "$next"
91+
fi
8692
8793
# Create release with proper error handling
88-
if gh release create "$next" --generate-notes; then
94+
if gh release view "$next" >/dev/null 2>&1; then
95+
echo "Release $next already exists, will update it"
96+
elif gh release create "$next" --generate-notes; then
8997
echo "Release $next created successfully"
9098
else
91-
echo "Failed to create release $next, but continuing..."
99+
echo "Failed to create release $next"
92100
exit 1
93101
fi
94102
95103
- name: Attach binaries (Linux/macOS)
96-
if: success()
104+
if: steps.create_release.outcome == 'success'
97105
env:
98106
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
99107
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
@@ -103,16 +111,31 @@ jobs:
103111
104112
# Build static binaries for common platforms
105113
mkdir -p dist
114+
echo "Building binaries..."
106115
GOOS=linux GOARCH=amd64 go build -o dist/golearn-linux-amd64 ./cmd/golearn
107116
GOOS=darwin GOARCH=arm64 go build -o dist/golearn-darwin-arm64 ./cmd/golearn
108117
GOOS=darwin GOARCH=amd64 go build -o dist/golearn-darwin-amd64 ./cmd/golearn
109118
GOOS=windows GOARCH=amd64 go build -o dist/golearn-windows-amd64.exe ./cmd/golearn
110119
111-
# Upload binaries to the release
112-
if gh release upload "$next" dist/* --clobber; then
113-
echo "Binaries uploaded successfully"
114-
else
115-
echo "Failed to upload binaries"
116-
exit 1
117-
fi
120+
echo "Binaries built successfully:"
121+
ls -lh dist/
122+
123+
# Upload binaries to the release with retry logic
124+
max_attempts=3
125+
attempt=1
126+
while [ $attempt -le $max_attempts ]; do
127+
echo "Attempt $attempt of $max_attempts to upload binaries..."
128+
if gh release upload "$next" dist/* --clobber; then
129+
echo "Binaries uploaded successfully"
130+
exit 0
131+
else
132+
echo "Upload attempt $attempt failed"
133+
if [ $attempt -eq $max_attempts ]; then
134+
echo "Failed to upload binaries after $max_attempts attempts"
135+
exit 1
136+
fi
137+
attempt=$((attempt+1))
138+
sleep 2
139+
fi
140+
done
118141

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dll
88
*.so
99
*.dylib
10+
golearn
1011

1112
# Test binary, built with `go test -c`
1213
*.test

internal/exercises/catalog.yaml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,55 @@ concepts:
134134
test_regex: ".*"
135135
hints:
136136
- Define a custom error type and return it from a function.
137+
- slug: 28_defer
138+
title: Defer
139+
test_regex: ".*"
140+
hints:
141+
- Use `f.Close()` with `defer` keyword.
142+
- slug: 29_go_routines
143+
title: Go Routines
144+
test_regex: ".*"
145+
hints:
146+
- Use `go` keyword to execute functions concurrently using go routines.
147+
- slug: 30_channels
148+
title: Channels
149+
test_regex: ".*"
150+
hints:
151+
- Use `make(chan T)` to create a channel and `<-` to send and receive on it.
152+
- slug: 31_mutexes
153+
title: Mutexes
154+
test_regex: ".*"
155+
hints:
156+
- Use `sync.Mutex` to synchronize access to a shared resource.
157+
- slug: 32_sorting
158+
title: Sorting
159+
test_regex: ".*"
160+
hints:
161+
- Use `slice.Sort` for sorting slices.
162+
- slug: 33_string_formatting
163+
title: String Formatting
164+
test_regex: ".*"
165+
hints:
166+
- Use `fmt.Sprintf` and `%s`, `%d`, `%f` formatting directives to format strings, integers, and floats.
167+
- slug: 34_channel_buffering
168+
title: Channel Buffering
169+
test_regex: ".*"
170+
hints:
171+
- Use `make(chan T, N)` to create a buffered channel and `<-` to send and receive on it.
172+
- slug: 39_channel_directions
173+
title: Channel Directions
174+
test_regex: ".*"
175+
hints:
176+
- Create two channels, one for sending jobs and one for receiving results.
177+
- Start 5 workers using go routines.
178+
- Send 50 jobs to the worker pool.
179+
- Receive results from the worker pool and store them in a `rs` slice.
180+
- Enforce type safety by specifying the channel directions in worker function.
181+
- slug: 35_channel_sync
182+
title: Channel Synchronization
183+
test_regex: ".*"
184+
hints:
185+
- Use a buffered boolean channel and wait till go routine completes.
137186
- slug: 37_xml
138187
title: XML Encoding and Decoding
139188
test_regex: ".*"
@@ -142,7 +191,12 @@ concepts:
142191
- Add XML struct tags using `xml:"fieldname"` to map struct fields to XML elements.
143192
- Use xml.Marshal to convert structs to XML bytes.
144193
- Use xml.Unmarshal to parse XML bytes into structs.
145-
194+
- slug: 40_channel_select
195+
title: Channel Select
196+
test_regex: ".*"
197+
hints:
198+
- Use `select` to handle multiple channel operations concurrently.
199+
- Use `time.After` to simulate a 5 microsecond timeout.
146200
projects:
147201
- slug: 101_text_analyzer
148202
title: Text Analyzer (Easy)

internal/exercises/solutions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// Embed the canonical solutions alongside templates. We do not expose these via CLI directly.
1313
//
14-
//go:embed solutions/**
14+
//go:embed all:solutions/**
1515
var solutionsFS embed.FS
1616

1717
// SolutionExists reports whether we have an embedded solution for the given slug.

internal/exercises/solutions/02_values/.gitkeep

Whitespace-only changes.

internal/exercises/solutions/03_variables/.gitkeep

Whitespace-only changes.

internal/exercises/solutions/04_constants/.gitkeep

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package forloop
2+
3+
// SumTo returns the sum of all integers from 1 to n.
4+
func SumTo(n int) int {
5+
sum := 0
6+
for i := 1; i <= n; i++ {
7+
sum += i
8+
}
9+
return sum
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ifelse
2+
3+
// Sign returns "negative", "zero", or "positive" based on n
4+
func Sign(n int) string {
5+
if n < 0 {
6+
return "negative"
7+
} else if n == 0 {
8+
return "zero"
9+
} else {
10+
return "positive"
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package sw
2+
3+
// IsWeekend returns true if day is weekend ("sat" or "sun"), false otherwise
4+
func IsWeekend(day string) bool {
5+
switch day {
6+
case "sat", "sun":
7+
return true
8+
}
9+
return false
10+
}

0 commit comments

Comments
 (0)