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 }}
0 commit comments