|
| 1 | +name: Haiku |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + check: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + should-run: ${{ steps.check.outputs.should-run }} |
| 14 | + steps: |
| 15 | + - name: Random execution check |
| 16 | + id: check |
| 17 | + uses: actions/github-script@v7 |
| 18 | + with: |
| 19 | + script: | |
| 20 | + const fs = require('fs'); |
| 21 | + const outputFile = process.env.GITHUB_OUTPUT; |
| 22 | +
|
| 23 | + if (context.eventName === 'release') { |
| 24 | + fs.appendFileSync(outputFile, `should-run=true\n`); |
| 25 | + core.info('Release event detected. Will run tests.'); |
| 26 | + return; |
| 27 | + } |
| 28 | +
|
| 29 | + const probability = parseFloat(process.env.RUN_PROBABILITY || '0.2'); |
| 30 | + const timeSeed = Math.floor(Date.now() / (1000 * 60 * 60)); |
| 31 | + const seed = context.sha + context.runId + timeSeed; |
| 32 | + let hash = 0; |
| 33 | + for (let i = 0; i < seed.length; i++) { |
| 34 | + const char = seed.charCodeAt(i); |
| 35 | + hash = ((hash << 5) - hash) + char; |
| 36 | + hash = hash | 0; |
| 37 | + } |
| 38 | + const random = Math.abs(hash) / 2147483647; |
| 39 | + const shouldRun = random < probability; |
| 40 | +
|
| 41 | + fs.appendFileSync(outputFile, `should-run=${shouldRun}\n`); |
| 42 | + if (shouldRun) { |
| 43 | + core.info(`Random check passed (${(random * 100).toFixed(2)}% < ${(probability * 100).toFixed(0)}%). Will run tests.`); |
| 44 | + } else { |
| 45 | + core.info(`Random check failed (${(random * 100).toFixed(2)}% >= ${(probability * 100).toFixed(0)}%). Skipping.`); |
| 46 | + } |
| 47 | + env: |
| 48 | + RUN_PROBABILITY: ${{ vars.HAIKU_RUN_PROBABILITY || '0.2' }} |
| 49 | + |
| 50 | + build: |
| 51 | + #needs: check |
| 52 | + #if: needs.check.outputs.should-run == 'true' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + |
| 55 | + concurrency: |
| 56 | + group: Haiku-${{ github.event.repository.owner.login }}-${{ github.event.repository.name }} |
| 57 | + cancel-in-progress: false |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v2 |
| 60 | + with: |
| 61 | + submodules: true |
| 62 | + |
| 63 | + - name: Tests |
| 64 | + uses: vmactions/haiku-vm@v1 |
| 65 | + with: |
| 66 | + usesh: true |
| 67 | + mem: 4096 |
| 68 | + copyback: false |
| 69 | + prepare: | |
| 70 | + pkgman install -y git curl unzip make bash perl |
| 71 | + run: | |
| 72 | + ./configure |
| 73 | + make -j2 |
| 74 | + make install |
| 75 | + export XMAKE_ROOT=y |
| 76 | + xrepo --version |
| 77 | + xmake l os.meminfo |
| 78 | + xmake lua -v -D tests/run.lua |
0 commit comments