Proper exception catching #112
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 MafiaHub Services | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| check_submodule: | |
| name: Check for services-adapter changes | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| outputs: | |
| should_build: ${{ steps.check_changes.outputs.changed }} | |
| steps: | |
| - name: Checkout services-adapter repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: MafiaHub/services-adapter | |
| path: services-adapter-repo | |
| token: ${{ secrets.FW_SERVICES_PAT }} | |
| fetch-depth: 0 | |
| - name: Get latest commits and check for changes | |
| id: check_changes | |
| run: | | |
| cd services-adapter-repo | |
| # Get the timestamp of the last successful build from build.txt | |
| LAST_BUILD_TIMESTAMP=$(curl -s -f -L https://github.com/MafiaHub/Framework/releases/download/MafiaHub-Services/build.txt || echo "0") | |
| echo "Raw timestamp response: '$LAST_BUILD_TIMESTAMP'" | |
| # Trim whitespace and make sure we have a valid number | |
| LAST_BUILD_TIMESTAMP=$(echo "$LAST_BUILD_TIMESTAMP" | tr -d '[:space:]') | |
| if ! [[ "$LAST_BUILD_TIMESTAMP" =~ ^[0-9]+$ ]]; then | |
| echo "Invalid timestamp format, defaulting to 0" | |
| LAST_BUILD_TIMESTAMP=0 | |
| fi | |
| # Convert UNIX timestamp to date format for git log (Linux format) | |
| if [ "$LAST_BUILD_TIMESTAMP" -gt 0 ]; then | |
| LAST_BUILD_TIME=$(date -d "@$LAST_BUILD_TIMESTAMP" "+%Y-%m-%d %H:%M:%S") | |
| else | |
| # Default to a very old date if build.txt doesn't exist or can't be retrieved | |
| LAST_BUILD_TIME="2000-01-01 00:00:00" | |
| fi | |
| echo "Last successful build timestamp: $LAST_BUILD_TIMESTAMP" | |
| echo "Last successful build time: $LAST_BUILD_TIME" | |
| # Check if there are any commits after the last build time | |
| RECENT_COMMITS=$(git log --since="$LAST_BUILD_TIME" --pretty=format:"%h %s" --no-merges) | |
| if [ -n "$RECENT_COMMITS" ]; then | |
| echo "Recent commits found in services-adapter:" | |
| echo "$RECENT_COMMITS" | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Services adapter has changed since last build. Triggering build." | |
| else | |
| echo "No new commits in services-adapter since last build." | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| notify_start: | |
| name: Send Start Notification | |
| needs: check_submodule | |
| if: github.event_name == 'workflow_dispatch' || needs.check_submodule.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Send Discord Notification | |
| uses: sarisia/actions-status-discord@v1 | |
| with: | |
| webhook: ${{ secrets.RELEASES_WEBHOOK }} | |
| title: "MafiaHub Services updating..." | |
| nodetail: true | |
| description: | | |
| Do not sync your Framework repository until this process is finished. | |
| color: 0x440000 | |
| username: MafiaHub Services | |
| build: | |
| name: Build MafiaHubServices on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| needs: notify_start | |
| if: github.event_name == 'workflow_dispatch' || needs.check_submodule.outputs.should_build == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, ubuntu-latest, macos-latest] | |
| include: | |
| - os: windows-latest | |
| cmake_generator: "Visual Studio 17 2022" | |
| build_type: "Release" | |
| - os: ubuntu-latest | |
| cmake_generator: "Unix Makefiles" | |
| build_type: "Release" | |
| - os: macos-latest | |
| cmake_generator: "Unix Makefiles" | |
| build_type: "Release" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| token: ${{ secrets.FW_SERVICES_PAT }} | |
| - uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: '16.2.0' | |
| if: runner.os == 'macOS' | |
| - name: Install tools on Ubuntu | |
| run: sudo apt-get install -y ninja-build build-essential libcurl4-openssl-dev | |
| if: runner.os == 'Linux' | |
| - name: Set up CMake | |
| uses: lukka/get-cmake@latest | |
| with: | |
| cmakeVersion: "~3.31.0" | |
| - name: Set up Visual Studio shell | |
| if: runner.os == 'Windows' | |
| uses: egor-tensin/vs-shell@v2 | |
| - name: Configure CMake (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
| - name: Configure CMake (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| cmake -G "${{ matrix.cmake_generator }}" -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
| - name: Build MafiaHubServices | |
| run: | | |
| cmake --build build --target MafiaHubServices --config ${{ matrix.build_type }} | |
| - name: Upload MafiaHub Services | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mafiahub-services-${{ matrix.os }} | |
| path: | | |
| ${{ github.workspace }}/code/framework/src/services/lib | |
| ${{ github.workspace }}/code/framework/src/services/services | |
| if-no-files-found: error | |
| release: | |
| name: Create or Update Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: temp-artifacts | |
| - name: Create build.txt with timestamp | |
| run: | | |
| mkdir -p release-artifacts | |
| # Create a clean timestamp without newlines or whitespace | |
| echo -n "$(date +%s)" > release-artifacts/build.txt | |
| cat release-artifacts/build.txt | |
| echo "Created build.txt with timestamp: $(cat release-artifacts/build.txt)" | |
| - name: Zip artifacts by platform | |
| run: | | |
| # Zip each platform's artifacts separately | |
| for platform in temp-artifacts/*; do | |
| platform_name=$(basename "$platform") | |
| cd "$platform" | |
| zip -r "../../release-artifacts/$platform_name.zip" . | |
| cd "../.." | |
| done | |
| - name: Check for existing release | |
| id: check_release | |
| run: | | |
| RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/tags/MafiaHub-Services" | \ | |
| jq -r '.id // "null"') | |
| echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV | |
| if [ "$RELEASE_ID" != "null" ]; then | |
| echo "release_exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "release_exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Delete existing release assets | |
| if: steps.check_release.outputs.release_exists == 'true' | |
| run: | | |
| # Get all assets for the release | |
| assets=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets") | |
| # Delete each asset | |
| for asset_id in $(echo $assets | jq -r '.[].id'); do | |
| curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/releases/assets/$asset_id" | |
| done | |
| - name: Create or update release | |
| id: create_release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: MafiaHub-Services | |
| name: MafiaHub Services | |
| draft: false | |
| prerelease: false | |
| body: "MafiaHub Services automated build from ${{ github.sha }}" | |
| files: release-artifacts/*.* | |
| fail_on_unmatched_files: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Send Discord Notification | |
| uses: sarisia/actions-status-discord@v1 | |
| with: | |
| webhook: ${{ secrets.RELEASES_WEBHOOK }} | |
| title: "MafiaHub Services updated! 🎉" | |
| nodetail: true | |
| description: | | |
| Make sure your Framework repository is up-to-date to avoid any conflicts. | |
| color: 0x440000 | |
| username: MafiaHub Services |