Skip to content

Commit 47aff81

Browse files
committed
Add CI
1 parent 9db3e59 commit 47aff81

File tree

8 files changed

+176
-22
lines changed

8 files changed

+176
-22
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export REDIS_PASSWORD=redispassword
1+
export REDIS_PASSWORD=redispassword
2+
export TIMEOUT=1s

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Static Checks and Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
ci:
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
go: ['1.22']
17+
os: ['ubuntu-latest', 'windows-latest']
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- name: Check out code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Go ${{ matrix.go }}
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: ${{ matrix.go }}
28+
id: go
29+
30+
- name: Build
31+
run: scripts/cibuild

.github/workflows/codeql.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "main" ]
9+
10+
jobs:
11+
analyze:
12+
name: Analyze
13+
runs-on: ubuntu-latest
14+
permissions:
15+
actions: read
16+
contents: read
17+
security-events: write
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
language: [ 'go' ]
23+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
24+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version-file: 'go.mod'
34+
35+
# Initializes the CodeQL tools for scanning.
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
with:
39+
languages: ${{ matrix.language }}
40+
# If you wish to specify custom queries, you can do so here or in a config file.
41+
# By default, queries listed here will override any specified in a config file.
42+
# Prefix the list here with "+" to use these queries and those in the config file.
43+
44+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
45+
# queries: security-extended,security-and-quality
46+
47+
48+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
49+
# If this step fails, then you should remove it and run the build manually (see below)
50+
#- name: Autobuild
51+
# uses: github/codeql-action/autobuild@v2
52+
53+
# ℹ️ Command-line programs to run using the OS shell.
54+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
55+
56+
# If the Autobuild fails above, remove it and uncomment the following three lines.
57+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
58+
59+
- name: Perform CodeQL Analysis
60+
uses: github/codeql-action/analyze@v3
61+
with:
62+
category: "/language:${{matrix.language}}"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
4+
#
5+
# Source repository: https://github.com/actions/dependency-review-action
6+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
7+
name: 'Dependency Review'
8+
on: [pull_request]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
dependency-review:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout Repository'
18+
uses: actions/checkout@v4
19+
- name: 'Dependency Review'
20+
uses: actions/dependency-review-action@v4

examples/pool/scheduler/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func main() {
2828
}
2929

3030
// Create node for pool "example".
31-
node, err := pool.AddNode(ctx, "example", rdb, pool.WithLogger(logger))
31+
node, err := pool.AddNode(ctx, "example", rdb,
32+
pool.WithJobSinkBlockDuration(100*time.Millisecond), // Shutdown faster
33+
pool.WithLogger(logger),
34+
)
3235
if err != nil {
3336
panic(err)
3437
}

examples/pool/worker/main.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ func main() {
5151
}
5252

5353
// Create node for pool "example".
54-
node, err := pool.AddNode(ctx, "example", rdb, pool.WithLogger(logger))
54+
node, err := pool.AddNode(ctx, "example", rdb,
55+
pool.WithJobSinkBlockDuration(100*time.Millisecond), // Shutdown faster
56+
pool.WithLogger(logger),
57+
)
5558
if err != nil {
5659
panic(err)
5760
}
@@ -62,15 +65,31 @@ func main() {
6265
panic(err)
6366
}
6467

65-
// Wait for jobs to complete.
66-
log.Infof(ctx, "Waiting for jobs... CTRL+C to stop.")
68+
// Check if a timeout is set
69+
var timeout time.Duration
70+
if t := os.Getenv("TIMEOUT"); t != "" {
71+
timeout, err = time.ParseDuration(t)
72+
if err != nil {
73+
panic(err)
74+
}
75+
} else {
76+
timeout = 10 * time.Minute
77+
}
78+
log.Infof(ctx, "timeout set to %s", timeout)
6779

68-
// Close done channel on CTRL-C.
80+
// Wait for CTRL-C or timeout.
81+
log.Infof(ctx, "Waiting for jobs... CTRL+C to stop.")
6982
sigc := make(chan os.Signal, 1)
83+
defer close(sigc)
7084
signal.Notify(sigc, os.Interrupt)
71-
<-sigc
72-
close(sigc)
85+
select {
86+
case <-sigc:
87+
log.Infof(ctx, "interrupted")
88+
case <-time.After(timeout):
89+
log.Infof(ctx, "timeout")
90+
}
7391

92+
// Shutdown node.
7493
if err := node.Shutdown(ctx); err != nil {
7594
panic(err)
7695
}

examples/streaming/multi-readers/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ func main() {
2828
}
2929

3030
// Don't forget to destroy the stream when done
31-
defer stream.Destroy(ctx)
31+
defer func() {
32+
if err := stream.Destroy(ctx); err != nil {
33+
panic(err)
34+
}
35+
}()
3236

3337
// Write 2 events to the stream
3438
id1, err := stream.Add(ctx, "event 1", []byte("payload 1"))

scripts/run-examples

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
#!/bin/bash
22

3+
# Find the Git root directory
4+
git_root=$(git rev-parse --show-toplevel 2>/dev/null)
5+
6+
if [ -z "$git_root" ]; then
7+
echo "Error: Not in a Git repository" >&2
8+
exit 1
9+
fi
10+
11+
# Load environment variables from .env file in the Git root
12+
if [ -f "$git_root/.env" ]; then
13+
export $(grep -v '^#' "$git_root/.env" | xargs)
14+
fi
15+
16+
# Update file paths to use absolute paths from Git root
317
files=(
4-
"examples/pool/worker/main.go"
5-
"examples/pool/producer/main.go"
6-
"examples/rmap/basics/main.go"
7-
"examples/rmap/multi-nodes/main.go"
8-
"examples/rmap/multi-nodes/main.go"
9-
"examples/streaming/single-reader/main.go"
10-
"examples/streaming/single-sink/main.go"
11-
"examples/streaming/multi-readers/main.go"
12-
"examples/streaming/multi-sinks/main.go"
13-
"examples/streaming/multi-streams/main.go"
14-
"examples/streaming/pub-sub/main.go"
18+
"$git_root/examples/pool/worker/main.go"
19+
"$git_root/examples/pool/producer/main.go"
20+
"$git_root/examples/rmap/basics/main.go"
21+
"$git_root/examples/rmap/multi-nodes/main.go"
22+
"$git_root/examples/rmap/multi-nodes/main.go"
23+
"$git_root/examples/streaming/single-reader/main.go"
24+
"$git_root/examples/streaming/single-sink/main.go"
25+
"$git_root/examples/streaming/multi-readers/main.go"
26+
"$git_root/examples/streaming/multi-sinks/main.go"
27+
"$git_root/examples/streaming/multi-streams/main.go"
28+
"$git_root/examples/streaming/pub-sub/main.go"
1529
)
1630

1731
args=(
@@ -30,7 +44,7 @@ run_example() {
3044
shift
3145
local args=("$@")
3246
echo "Running: $file ${args[*]}"
33-
output=$(timeout "$timeout_sec" go run -v "$file" "${args[@]}" 2>&1)
47+
output=$(cd "$git_root" && timeout "$timeout_sec" go run -v "$file" "${args[@]}" 2>&1)
3448
local exit_status=$?
3549
if [[ $exit_status -ne 0 ]]; then
3650
echo "Example '${file}' exited with an error or exceeded the timeout:"
@@ -55,4 +69,4 @@ for pid in "${pids[@]}"; do
5569
fi
5670
done
5771

58-
exit "$status"
72+
exit "$status"

0 commit comments

Comments
 (0)