Skip to content

Commit 89217a4

Browse files
committed
Slowly fixing up v5 API.
1 parent dd74007 commit 89217a4

33 files changed

+2012
-2236
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Build Artifacts
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version_suffix:
7+
description: 'Version suffix (empty for release, e.g., "pr123" for prerelease)'
8+
required: false
9+
type: string
10+
default: ''
11+
retention_days:
12+
description: 'Artifact retention days (7 for prerelease, 400 for release)'
13+
required: false
14+
type: number
15+
default: 400
16+
is_prerelease:
17+
description: 'Whether this is a prerelease build'
18+
required: false
19+
type: boolean
20+
default: false
21+
outputs:
22+
artifacts_created:
23+
description: "Whether all artifacts were created successfully"
24+
value: ${{ jobs.create-packages.outputs.success }}
25+
26+
jobs:
27+
build:
28+
name: Build ${{ matrix.os }} ${{ matrix.build_type }}
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
fail-fast: ${{ inputs.is_prerelease }} # Fail fast for prerelease, not for release
32+
matrix:
33+
os: [ubuntu-latest, macos-latest]
34+
build_type: [Debug, Release]
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Configure and Build
40+
run: |
41+
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPTK_BUILD_TESTS=ON
42+
cmake --build build --config ${{ matrix.build_type }}
43+
44+
- name: Run Tests
45+
working-directory: build
46+
run: |
47+
echo "Running tests - failure will block artifact creation..."
48+
ctest --output-on-failure -C ${{ matrix.build_type }}
49+
echo "✅ All tests passed!"
50+
51+
- name: Package Artifacts
52+
run: |
53+
# Get version from CMakeLists.txt
54+
VERSION=$(grep "project.*VERSION" CMakeLists.txt | sed -n 's/.*VERSION \([0-9.]*\).*/\1/p')
55+
56+
# Create platform-specific package directory
57+
PLATFORM=$(echo "${{ matrix.os }}" | sed 's/-latest//')
58+
BUILD_TYPE_LOWER=$(echo "${{ matrix.build_type }}" | tr '[:upper:]' '[:lower:]')
59+
60+
if [ -n "${{ inputs.version_suffix }}" ]; then
61+
PACKAGE_DIR="protocol-toolkit-${PLATFORM}-${BUILD_TYPE_LOWER}-${VERSION}-${{ inputs.version_suffix }}"
62+
VERSION_DISPLAY="${VERSION}-${{ inputs.version_suffix }}"
63+
else
64+
PACKAGE_DIR="protocol-toolkit-${PLATFORM}-${BUILD_TYPE_LOWER}"
65+
VERSION_DISPLAY="${VERSION}"
66+
fi
67+
68+
mkdir -p "${PACKAGE_DIR}"
69+
70+
# Copy library and header
71+
cp build/lib/libprotocol_toolkit.a "${PACKAGE_DIR}/"
72+
cp build/include/protocol_toolkit.h "${PACKAGE_DIR}/"
73+
74+
# Create appropriate README
75+
if [ "${{ inputs.is_prerelease }}" = "true" ]; then
76+
cat > "${PACKAGE_DIR}/README.md" << EOF
77+
# Protocol Toolkit ${VERSION_DISPLAY} - ${PLATFORM^} ${{ matrix.build_type }} Build
78+
79+
**⚠️ PRERELEASE ARTIFACT - NOT FOR PRODUCTION USE**
80+
81+
This is a prerelease build for testing and development purposes.
82+
83+
## Build Information
84+
- **Version**: ${VERSION_DISPLAY}
85+
- **Platform**: ${PLATFORM^}
86+
- **Build Type**: ${{ matrix.build_type }}
87+
- **Built From**: \${GITHUB_REF#refs/heads/} branch
88+
- **Commit**: ${{ github.sha }}
89+
90+
## Important Notes
91+
- ⚠️ This is a **prerelease build** - use for testing only
92+
- 🧪 All tests passed at build time
93+
- ⏱️ Artifact expires in ${{ inputs.retention_days }} days
94+
- 📋 For production use, wait for official release
95+
EOF
96+
else
97+
cat > "${PACKAGE_DIR}/README.md" << EOF
98+
# Protocol Toolkit ${VERSION_DISPLAY} - ${PLATFORM^} ${{ matrix.build_type }} Build
99+
100+
Cross-platform event-driven protocol toolkit with state machine support.
101+
102+
## Platform
103+
- **OS**: ${PLATFORM^}
104+
- **Build**: ${{ matrix.build_type }}
105+
- **API**: Event loops, state machines, TCP/UDP sockets
106+
107+
## Build Information
108+
- **Version**: ${VERSION_DISPLAY}
109+
- **Release**: Official release build
110+
- **Platform**: ${PLATFORM^}
111+
- **Build Type**: ${{ matrix.build_type }}
112+
EOF
113+
fi
114+
115+
# Add common sections to README
116+
cat >> "${PACKAGE_DIR}/README.md" << EOF
117+
118+
## Files
119+
- \`libprotocol_toolkit.a\` - Static library
120+
- \`protocol_toolkit.h\` - Unified header file
121+
122+
## Usage
123+
124+
### CMake Integration
125+
\`\`\`cmake
126+
# Copy files to your project directory, then:
127+
target_link_libraries(your_target
128+
\${CMAKE_CURRENT_SOURCE_DIR}/libprotocol_toolkit.a)
129+
target_include_directories(your_target PRIVATE
130+
\${CMAKE_CURRENT_SOURCE_DIR})
131+
\`\`\`
132+
133+
### Direct Compilation
134+
\`\`\`bash
135+
gcc your_code.c libprotocol_toolkit.a -o your_program
136+
\`\`\`
137+
138+
## Platform Support
139+
- **Linux**: epoll-based event loop
140+
- **macOS**: kqueue-based event loop
141+
142+
## API Overview
143+
- \`ptk_ev_t\` - Event loop
144+
- \`ptk_sm_t\` - State machine
145+
- \`ptk_socket_t\` - TCP/UDP sockets
146+
- \`ptk_ev_source_t\` - Event sources (timers, user events)
147+
148+
For full documentation, visit: https://github.com/\${GITHUB_REPOSITORY}
149+
EOF
150+
151+
echo "PACKAGE_DIR=${PACKAGE_DIR}" >> $GITHUB_ENV
152+
153+
- name: Upload Platform Package
154+
uses: actions/upload-artifact@v4
155+
with:
156+
name: ${{ env.PACKAGE_DIR }}
157+
path: ${{ env.PACKAGE_DIR }}/
158+
retention-days: ${{ inputs.retention_days }}
159+
160+
create-packages:
161+
name: Create ZIP Files
162+
runs-on: ubuntu-latest
163+
needs: build
164+
outputs:
165+
success: ${{ steps.create-zips.outputs.success }}
166+
167+
steps:
168+
- name: Download All Artifacts
169+
uses: actions/download-artifact@v4
170+
with:
171+
path: artifacts/
172+
173+
- name: Create ZIP Files
174+
id: create-zips
175+
run: |
176+
cd artifacts
177+
178+
# Create ZIP files for each platform/build combination
179+
for dir in protocol-toolkit-*; do
180+
if [ -d "$dir" ]; then
181+
echo "Creating ${dir}.zip..."
182+
zip -r "${dir}.zip" "$dir/"
183+
fi
184+
done
185+
186+
# List created files
187+
echo "Created ZIP files:"
188+
ls -la *.zip
189+
190+
# Verify we have all expected files
191+
EXPECTED_FILES=4 # 2 platforms × 2 build types
192+
ACTUAL_FILES=$(ls -1 *.zip | wc -l)
193+
194+
if [ "$ACTUAL_FILES" -eq "$EXPECTED_FILES" ]; then
195+
echo "✅ All $EXPECTED_FILES ZIP files created successfully"
196+
echo "success=true" >> $GITHUB_OUTPUT
197+
else
198+
echo "❌ Expected $EXPECTED_FILES ZIP files, got $ACTUAL_FILES"
199+
echo "success=false" >> $GITHUB_OUTPUT
200+
exit 1
201+
fi
202+
203+
- name: Upload ZIP Files
204+
uses: actions/upload-artifact@v4
205+
with:
206+
name: ${{ inputs.is_prerelease && 'prerelease-zip-files' || 'release-zip-files' }}
207+
path: artifacts/*.zip
208+
retention-days: ${{ inputs.retention_days }}

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
test:
11+
name: Test (${{ matrix.os }}, ${{ matrix.build_type }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, macos-latest]
17+
build_type: [Debug, Release]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Configure CMake
23+
run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DPTK_BUILD_TESTS=ON
24+
25+
- name: Build
26+
run: cmake --build build --config ${{ matrix.build_type }}
27+
28+
- name: Run Tests
29+
working-directory: build
30+
run: ctest --output-on-failure -C ${{ matrix.build_type }}
31+
32+
- name: Upload Test Results
33+
uses: actions/upload-artifact@v4
34+
if: always()
35+
with:
36+
name: test-results-${{ matrix.os }}-${{ matrix.build_type }}
37+
path: build/Testing/
38+
39+
- name: Upload Build Artifacts (for release)
40+
if: github.event_name == 'pull_request' && github.base_ref == 'release'
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: build-${{ matrix.os }}-${{ matrix.build_type }}
44+
path: |
45+
build/lib/libprotocol_toolkit.a
46+
build/include/protocol_toolkit.h
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Prerelease Artifacts
2+
3+
on:
4+
pull_request:
5+
branches: [ 'prerelease' ]
6+
push:
7+
branches: [ 'prerelease' ]
8+
9+
jobs:
10+
setup:
11+
name: Setup Build Info
12+
runs-on: ubuntu-latest
13+
outputs:
14+
version_suffix: ${{ steps.info.outputs.version_suffix }}
15+
pr_number: ${{ steps.info.outputs.pr_number }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Get Version and PR Info
21+
id: info
22+
run: |
23+
VERSION=$(grep "project.*VERSION" CMakeLists.txt | sed -n 's/.*VERSION \([0-9.]*\).*/\1/p')
24+
echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
26+
if [ "${{ github.event_name }}" = "pull_request" ]; then
27+
PR_NUMBER="${{ github.event.pull_request.number }}"
28+
SUFFIX="pr${PR_NUMBER}"
29+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
30+
else
31+
# For push events, use short commit hash
32+
COMMIT_HASH=$(echo "${{ github.sha }}" | cut -c1-7)
33+
SUFFIX="$COMMIT_HASH"
34+
echo "pr_number=" >> $GITHUB_OUTPUT
35+
fi
36+
37+
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
38+
echo "version_suffix=${VERSION}-${SUFFIX}" >> $GITHUB_OUTPUT
39+
40+
# Call the unified build workflow
41+
build-artifacts:
42+
name: Build Multi-Platform Artifacts
43+
needs: setup
44+
uses: ./.github/workflows/build-artifacts-unified.yml
45+
with:
46+
version_suffix: ${{ needs.setup.outputs.version_suffix }}
47+
retention_days: 7
48+
is_prerelease: true
49+
50+
comment-on-pr:
51+
name: Comment on PR with Artifact Links
52+
if: github.event_name == 'pull_request'
53+
needs: [setup, build-artifacts]
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- name: Comment on PR
58+
uses: actions/github-script@v7
59+
with:
60+
script: |
61+
const prNumber = ${{ github.event.pull_request.number }};
62+
const version = '${{ needs.setup.outputs.version_suffix }}';
63+
const runId = context.runId;
64+
65+
await github.rest.issues.createComment({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
issue_number: prNumber,
69+
body: `## 🏗️ Prerelease Artifacts Built Successfully
70+
71+
**Version**: \`${version}\`
72+
**Build Run**: [#${runId}](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId})
73+
74+
### 📦 Available Artifacts:
75+
- \`protocol-toolkit-linux-debug-${version}.zip\`
76+
- \`protocol-toolkit-linux-release-${version}.zip\`
77+
- \`protocol-toolkit-macos-debug-${version}.zip\`
78+
- \`protocol-toolkit-macos-release-${version}.zip\`
79+
80+
### 📥 Download Instructions:
81+
1. Go to the [Actions Run](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId})
82+
2. Scroll down to the "Artifacts" section
83+
3. Download the desired platform/build combination
84+
85+
### ⏱️ Artifact Retention:
86+
These prerelease artifacts will be available for **7 days**.
87+
88+
### 🧪 Testing:
89+
All platform tests passed before artifact creation.
90+
91+
---
92+
*This comment was automatically generated for PR #${prNumber}*`
93+
});

0 commit comments

Comments
 (0)