Build and Release #28
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| release: | |
| types: [created] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| actions: read | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| asset: psmoveapi-4.0.12-linux.tar.gz | |
| - os: macos-13 | |
| asset: psmoveapi-4.0.12-macos.tar.gz | |
| - os: windows-latest | |
| asset: psmoveapi-4.0.12-windows-msvc2017-x64.zip | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libusb-1.0-0-dev libbluetooth-dev pkg-config | |
| - name: Install dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew update | |
| brew install libusb | |
| - name: Download psmoveapi (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| run: | | |
| curl -L -o psmoveapi.${{ matrix.asset }} \ | |
| https://github.com/thp/psmoveapi/releases/download/4.0.12/${{ matrix.asset }} | |
| - name: Download psmoveapi (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| curl -L -o psmoveapi.${{ matrix.asset }} https://github.com/thp/psmoveapi/releases/download/4.0.12/${{ matrix.asset }} | |
| - name: Extract psmoveapi (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| mkdir -p psmoveapi_install | |
| tar -xzf psmoveapi.${{ matrix.asset }} -C psmoveapi_install --strip-components=1 | |
| - name: Extract psmoveapi (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| mkdir -p psmoveapi_install | |
| tar -xzf psmoveapi.${{ matrix.asset }} -C psmoveapi_install --strip-components=1 | |
| - name: Extract psmoveapi (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| mkdir -p psmoveapi_install | |
| tar -xf psmoveapi.${{ matrix.asset }} -C psmoveapi_install --strip-components=1 | |
| - name: Configure with CMake (Windows) | |
| if: runner.os == 'Windows' | |
| run: cmake -S . -B build -DPSMOVE_ROOT=${{ github.workspace }}/psmoveapi_install | |
| - name: Configure with CMake (Linux/macOS) | |
| if: runner.os != 'Windows' | |
| run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DPSMOVE_ROOT=${{ github.workspace }}/psmoveapi_install | |
| - name: Build | |
| run: cmake --build build --config Release | |
| - name: List build directory contents (debug) | |
| run: | | |
| echo "Contents of build directory:" | |
| ls -la build/ | |
| if [ "${{ runner.os }}" = "Windows" ]; then | |
| echo "Contents of build/Release directory:" | |
| ls -la build/Release/ || echo "build/Release/ does not exist" | |
| echo "Contents of build/Debug directory:" | |
| ls -la build/Debug/ || echo "build/Debug/ does not exist" | |
| fi | |
| shell: bash | |
| - name: Get executable name from CMake | |
| id: cmake_info | |
| run: | | |
| if [ "${{ runner.os }}" = "Windows" ]; then | |
| # For Windows, we need to find the actual executable name | |
| if [ -f "build/Release/"*.exe ]; then | |
| EXEC_NAME=$(basename build/Release/*.exe) | |
| elif [ -f "build/Debug/"*.exe ]; then | |
| EXEC_NAME=$(basename build/Debug/*.exe) | |
| elif [ -f "build/"*.exe ]; then | |
| EXEC_NAME=$(basename build/*.exe) | |
| else | |
| echo "ERROR: Could not find Windows executable" | |
| exit 1 | |
| fi | |
| else | |
| # For Linux/macOS, find the executable (non-.exe files that are executable) | |
| EXEC_NAME=$(find build/ -maxdepth 1 -type f -executable ! -name "*.so" ! -name "*.dylib" -printf '%f\n' | head -n1) | |
| if [ -z "$EXEC_NAME" ]; then | |
| echo "ERROR: Could not find executable" | |
| exit 1 | |
| fi | |
| fi | |
| echo "executable_name=$EXEC_NAME" >> $GITHUB_OUTPUT | |
| echo "Found executable: $EXEC_NAME" | |
| shell: bash | |
| - name: Find and rename executable | |
| id: artifact | |
| run: | | |
| mkdir -p artifacts | |
| EXEC_NAME="${{ steps.cmake_info.outputs.executable_name }}" | |
| if [ "${{ runner.os }}" = "Windows" ]; then | |
| # Try multiple possible locations for Windows executable | |
| if [ -f "build/Release/$EXEC_NAME" ]; then | |
| EXEC_PATH="build/Release/$EXEC_NAME" | |
| elif [ -f "build/Debug/$EXEC_NAME" ]; then | |
| EXEC_PATH="build/Debug/$EXEC_NAME" | |
| elif [ -f "build/$EXEC_NAME" ]; then | |
| EXEC_PATH="build/$EXEC_NAME" | |
| else | |
| echo "ERROR: Could not find Windows executable $EXEC_NAME" | |
| exit 1 | |
| fi | |
| ARTIFACT_NAME="$EXEC_NAME" | |
| elif [ "${{ runner.os }}" = "macOS" ]; then | |
| EXEC_PATH="build/$EXEC_NAME" | |
| ARTIFACT_NAME="$EXEC_NAME" | |
| else | |
| EXEC_PATH="build/$EXEC_NAME" | |
| ARTIFACT_NAME="$EXEC_NAME" | |
| fi | |
| echo "name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT | |
| echo "path=$EXEC_PATH" >> $GITHUB_OUTPUT | |
| # Copy to artifacts directory | |
| cp "$EXEC_PATH" "artifacts/$ARTIFACT_NAME" | |
| echo "Successfully created: artifacts/$ARTIFACT_NAME" | |
| shell: bash | |
| - name: Upload to release (on release event) | |
| if: github.event_name == 'release' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: artifacts/${{ steps.artifact.outputs.name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get latest release (on workflow_dispatch) | |
| if: github.event_name == 'workflow_dispatch' | |
| id: latest_release | |
| shell: bash | |
| run: | | |
| # Try to get the latest release | |
| if LATEST_RELEASE=$(gh api repos/${{ github.repository }}/releases/latest --jq '.tag_name' 2>/dev/null); then | |
| echo "Found latest release: $LATEST_RELEASE" | |
| echo "tag_name=$LATEST_RELEASE" >> $GITHUB_OUTPUT | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No releases found - will create a new one" | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "tag_name=v1.0.0" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create release if none exists (on workflow_dispatch) | |
| if: github.event_name == 'workflow_dispatch' && steps.latest_release.outputs.exists == 'false' | |
| shell: bash | |
| run: | | |
| gh release create ${{ steps.latest_release.outputs.tag_name }} \ | |
| --title "Release ${{ steps.latest_release.outputs.tag_name }}" \ | |
| --notes "Automated release created by workflow dispatch" \ | |
| --repo ${{ github.repository }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload to release (on workflow_dispatch) | |
| if: github.event_name == 'workflow_dispatch' | |
| shell: bash | |
| run: | | |
| gh release upload ${{ steps.latest_release.outputs.tag_name }} \ | |
| "artifacts/${{ steps.artifact.outputs.name }}" \ | |
| --repo ${{ github.repository }} \ | |
| --clobber | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |