Build and Release #23
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 | |
| executable: dsu_server_psmove | |
| - os: macos-13 | |
| asset: psmoveapi-4.0.12-macos.tar.gz | |
| executable: dsu_server_psmove | |
| - os: windows-latest | |
| asset: psmoveapi-4.0.12-windows-msvc2017-x64.zip | |
| executable: dsu_server_psmove.exe | |
| 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: Find and rename executable | |
| id: artifact | |
| run: | | |
| mkdir -p artifacts | |
| if [ "${{ runner.os }}" = "Windows" ]; then | |
| # Try multiple possible locations for Windows executable | |
| if [ -f "build/Release/${{ matrix.executable }}" ]; then | |
| EXEC_PATH="build/Release/${{ matrix.executable }}" | |
| elif [ -f "build/Debug/${{ matrix.executable }}" ]; then | |
| EXEC_PATH="build/Debug/${{ matrix.executable }}" | |
| elif [ -f "build/${{ matrix.executable }}" ]; then | |
| EXEC_PATH="build/${{ matrix.executable }}" | |
| else | |
| echo "ERROR: Could not find Windows executable" | |
| exit 1 | |
| fi | |
| ARTIFACT_NAME="dsu_server_psmove-windows-x64.exe" | |
| elif [ "${{ runner.os }}" = "macOS" ]; then | |
| EXEC_PATH="build/${{ matrix.executable }}" | |
| ARTIFACT_NAME="dsu_server_psmove-macos" | |
| else | |
| EXEC_PATH="build/${{ matrix.executable }}" | |
| ARTIFACT_NAME="dsu_server_psmove-linux" | |
| 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 }} |