name: Cosmocc on: pull_request: push: release: types: [published] jobs: check: runs-on: ubuntu-latest outputs: should-run: ${{ steps.check.outputs.should-run }} steps: - name: Random execution check id: check uses: actions/github-script@v7 with: script: | const fs = require('fs'); const outputFile = process.env.GITHUB_OUTPUT; // Always run for release events if (context.eventName === 'release') { fs.appendFileSync(outputFile, `should-run=true\n`); core.info('Release event detected. Will run tests.'); return; } // Execution probability (default 50%, can be overridden via env) const probability = parseFloat(process.env.RUN_PROBABILITY || '0.5'); // Generate deterministic "random" number based on commit SHA, run ID, and current time // Adding time ensures better randomness while keeping same commit/run consistent const timeSeed = Math.floor(Date.now() / (1000 * 60 * 60)); // Round to hour for consistency const seed = context.sha + context.runId + timeSeed; let hash = 0; for (let i = 0; i < seed.length; i++) { const char = seed.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash = hash | 0; // Convert to 32-bit integer } // Normalize to 0-1 range const random = Math.abs(hash) / 2147483647; const shouldRun = random < probability; // Use environment file instead of deprecated set-output fs.appendFileSync(outputFile, `should-run=${shouldRun}\n`); if (shouldRun) { core.info(`Random check passed (${(random * 100).toFixed(2)}% < ${(probability * 100).toFixed(0)}%). Will run tests.`); } else { core.info(`Random check failed (${(random * 100).toFixed(2)}% >= ${(probability * 100).toFixed(0)}%). Skipping.`); } env: RUN_PROBABILITY: ${{ vars.COSMOCC_RUN_PROBABILITY || '0.5' }} build: needs: check if: needs.check.outputs.should-run == 'true' strategy: matrix: os: [ubuntu-latest, macos-15-intel] arch: [x86_64] runs-on: ${{ matrix.os }} concurrency: group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Cosmocc-${{ matrix.os }}-${{ matrix.arch }} cancel-in-progress: true steps: - uses: actions/checkout@v2 with: submodules: true - uses: little-core-labs/get-git-tag@v3.0.2 id: tagName - name: Prepare local xmake run: cp -rf . ../xmake-source - uses: xmake-io/github-action-setup-xmake@v1 with: xmake-version: local#../xmake-source - uses: bjia56/setup-cosmocc@main with: version: "4.0.2" - name: Build run: | cd core xmake f -p linux --cosmocc=y --embed=y -y -cvD xmake -v cd .. - name: Prepare (Linux) if: matrix.os == 'ubuntu-latest' run: | sudo apt update sudo apt install -y ruby ruby-dev rubygems build-essential llvm libc++-dev sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev clang --version # In the tests, cmake tries to use make from the cosmopolitan toolchain and fails, so uninstall it - name: Remove cosmocc if: startsWith(matrix.os, 'macos') run: | INSTALL_DIR="${{runner.temp}}/cosmocc-4.0.2" echo "Removing cosmocc from PATH" echo "::remove-path::${INSTALL_DIR}/bin" rm -r "${INSTALL_DIR}" - name: Tests run: | ls -l core/build/ cmake --version core/build/xmake --version core/build/xmake lua -v -D tests/run.lua - name: Artifact if: matrix.os == 'ubuntu-latest' uses: actions/upload-artifact@v4 with: name: xmake-bundle.cosmocc path: core/build/xmake - name: Publish bundle binary if: github.event.action == 'published' && matrix.os == 'ubuntu-latest' uses: actions/upload-release-asset@v1.0.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} asset_path: core/build/xmake asset_name: xmake-bundle-${{ steps.tagName.outputs.tag }}.cosmocc asset_content_type: application/zip