diff options
| author | ruki <[email protected]> | 2025-11-27 23:26:11 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-27 23:26:11 +0800 |
| commit | d0fb4b9571c0a104cfba6fd1d824423c68f2c792 (patch) | |
| tree | 077bf09cba475e464c188feef34638cbabcbdef6 | |
| parent | 69f46e715f83742b35fb1337a695c96fe10c456b (diff) | |
update ci
| -rw-r--r-- | .github/workflows/cosmocc.yml | 49 | ||||
| -rw-r--r-- | .github/workflows/freebsd.yml | 50 | ||||
| -rw-r--r-- | .github/workflows/solaris.yml | 50 |
3 files changed, 147 insertions, 2 deletions
diff --git a/.github/workflows/cosmocc.yml b/.github/workflows/cosmocc.yml index 1857e546e..cfe9c3303 100644 --- a/.github/workflows/cosmocc.yml +++ b/.github/workflows/cosmocc.yml @@ -7,7 +7,56 @@ on: 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-13] diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 5cb8e0edf..92b91c84e 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -7,8 +7,56 @@ on: types: [published] jobs: - build: + 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.FREEBSD_RUN_PROBABILITY || '0.5' }} + build: + needs: check + if: needs.check.outputs.should-run == 'true' runs-on: ubuntu-latest concurrency: diff --git a/.github/workflows/solaris.yml b/.github/workflows/solaris.yml index fa500ad89..9e044b036 100644 --- a/.github/workflows/solaris.yml +++ b/.github/workflows/solaris.yml @@ -7,8 +7,56 @@ on: types: [published] jobs: - build: + 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.SOLARIS_RUN_PROBABILITY || '0.5' }} + build: + needs: check + if: needs.check.outputs.should-run == 'true' runs-on: ubuntu-latest concurrency: |
