summaryrefslogtreecommitdiff
path: root/.github/workflows/haiku.yml
blob: 34e51392beb9061d8a65209ac89e6f344fffe27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Haiku

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;

            if (context.eventName === 'release') {
              fs.appendFileSync(outputFile, `should-run=true\n`);
              core.info('Release event detected. Will run tests.');
              return;
            }

            const probability = parseFloat(process.env.RUN_PROBABILITY || '0.2');
            const timeSeed = Math.floor(Date.now() / (1000 * 60 * 60));
            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;
            }
            const random = Math.abs(hash) / 2147483647;
            const shouldRun = random < probability;

            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.HAIKU_RUN_PROBABILITY || '0.2' }}

  build:
    needs: check
    if: needs.check.outputs.should-run == 'true'
    runs-on: ubuntu-latest

    concurrency:
      group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Haiku
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true

      - name: Tests
        uses: vmactions/haiku-vm@v1
        with:
          usesh: true
          mem: 4096
          copyback: false
          prepare: |
            pkgman install -y git curl unzip make bash perl
          run: |
            ./configure --prefix=`pwd`/dist
            make -j2
            make install
            export XMAKE_ROOT=y
            export PATH=`pwd`/dist/bin:$PATH
            xrepo --version
            xmake lua -v -D tests/run.lua