|  | 
|  | 1 | +name: WebAssembly System | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  pull_request_target: | 
|  | 5 | +    branches: | 
|  | 6 | +      - master | 
|  | 7 | +    types: | 
|  | 8 | +      - closed | 
|  | 9 | +  workflow_dispatch: | 
|  | 10 | +    branches: | 
|  | 11 | +      - master | 
|  | 12 | +  repository_dispatch:   # listening to rv32emu-prebuilt events | 
|  | 13 | +    types: [deploy_wasm] | 
|  | 14 | + | 
|  | 15 | +jobs: | 
|  | 16 | +  wasm-system-deploy: | 
|  | 17 | +    if: github.event.pull_request.merged == true || | 
|  | 18 | +        github.event_name == 'workflow_dispatch' || | 
|  | 19 | +        github.event_name == 'repository_dispatch' | 
|  | 20 | +    runs-on: ubuntu-latest | 
|  | 21 | +    steps: | 
|  | 22 | +      - name: Check out the repo | 
|  | 23 | +        uses: actions/checkout@v4 | 
|  | 24 | +      - name: install-dependencies | 
|  | 25 | +        run: | | 
|  | 26 | +              sudo apt-get update -q=2 | 
|  | 27 | +              sudo apt-get install -q=2 libsdl2-dev libsdl2-mixer-dev device-tree-compiler | 
|  | 28 | +      - name: Verify if the JS or HTML files has been modified | 
|  | 29 | +        id: changed-files | 
|  | 30 | +        uses: tj-actions/changed-files@v46 | 
|  | 31 | +        with: | 
|  | 32 | +          files: | | 
|  | 33 | +              assets/wasm/html/system.html | 
|  | 34 | +              assets/wasm/js/system-pre.js | 
|  | 35 | +              # Files below may have a potential performance impact (reference from benchmark.yml) | 
|  | 36 | +              src/devices/*.c | 
|  | 37 | +              src/system.c | 
|  | 38 | +              src/riscv.c | 
|  | 39 | +              src/decode.c | 
|  | 40 | +              src/emulate.c | 
|  | 41 | +              src/rv32_template.c | 
|  | 42 | +              src/rv32_constopt.c | 
|  | 43 | +      - name: install emcc | 
|  | 44 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 45 | +            github.event_name == 'workflow_dispatch' || | 
|  | 46 | +            github.event_name == 'repository_dispatch' }} | 
|  | 47 | +        run: | | 
|  | 48 | +            git clone https://github.com/emscripten-core/emsdk.git | 
|  | 49 | +            cd emsdk | 
|  | 50 | +            git pull | 
|  | 51 | +            git checkout 3.1.51 | 
|  | 52 | +            ./emsdk install latest | 
|  | 53 | +            ./emsdk activate latest | 
|  | 54 | +            source ./emsdk_env.sh | 
|  | 55 | +            echo "$PATH" >> $GITHUB_PATH | 
|  | 56 | +        shell: bash | 
|  | 57 | +      - name: fetch artifact | 
|  | 58 | +        run: | | 
|  | 59 | +              make artifact | 
|  | 60 | +              # Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download | 
|  | 61 | +              wget --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" \ | 
|  | 62 | +                   --header="Referer: https://www.doomworld.com/" \ | 
|  | 63 | +                   --header="Accept-Language: en-US,en;q=0.9" \ | 
|  | 64 | +                   -O build/shareware_doom_iwad.zip \ | 
|  | 65 | +                   "https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip" | 
|  | 66 | +              unzip -d build/ build/shareware_doom_iwad.zip | 
|  | 67 | +      - name: build with emcc and move application files to /tmp | 
|  | 68 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 69 | +            github.event_name == 'workflow_dispatch' || | 
|  | 70 | +            github.event_name == 'repository_dispatch' }} | 
|  | 71 | +        run: | | 
|  | 72 | +            make CC=emcc ENABLE_SYSTEM=1 ENABLE_SDL=1 INITRD_SIZE=32 -j | 
|  | 73 | +            mkdir /tmp/rv32emu-demo-system | 
|  | 74 | +            mv assets/wasm/html/system.html /tmp/rv32emu-demo-system/index.html | 
|  | 75 | +            mv assets/wasm/js/coi-serviceworker.min.js /tmp/rv32emu-demo-system | 
|  | 76 | +            mv build/rv32emu.js /tmp/rv32emu-demo-system | 
|  | 77 | +            mv build/rv32emu.wasm /tmp/rv32emu-demo-system | 
|  | 78 | +            mv build/rv32emu.worker.js /tmp/rv32emu-demo-system | 
|  | 79 | +            ls -al /tmp/rv32emu-demo-system | 
|  | 80 | +      - name: Check out the rv32emu-demo-system repo | 
|  | 81 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 82 | +            github.event_name == 'workflow_dispatch' || | 
|  | 83 | +            github.event_name == 'repository_dispatch' }} | 
|  | 84 | +        uses: actions/checkout@v4 | 
|  | 85 | +        with: | 
|  | 86 | +          persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. | 
|  | 87 | +          repository: ChinYikMing/rv32emu-demo-system | 
|  | 88 | +      - name: Create local changes | 
|  | 89 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 90 | +            github.event_name == 'workflow_dispatch' || | 
|  | 91 | +            github.event_name == 'repository_dispatch' }} | 
|  | 92 | +        run: | | 
|  | 93 | +            mv /tmp/rv32emu-demo-system/index.html . | 
|  | 94 | +            mv /tmp/rv32emu-demo-system/coi-serviceworker.min.js . | 
|  | 95 | +            mv /tmp/rv32emu-demo-system/rv32emu.js . | 
|  | 96 | +            mv /tmp/rv32emu-demo-system/rv32emu.wasm . | 
|  | 97 | +            mv /tmp/rv32emu-demo-system/rv32emu.worker.js . | 
|  | 98 | +      - name: Commit files | 
|  | 99 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 100 | +            github.event_name == 'workflow_dispatch' || | 
|  | 101 | +            github.event_name == 'repository_dispatch' }} | 
|  | 102 | +        run: | | 
|  | 103 | +            git config --local user.email "github-actions[bot]@users.noreply.github.com" | 
|  | 104 | +            git config --local user.name "github-actions[bot]" | 
|  | 105 | +            git add --all | 
|  | 106 | +            git commit -m "Add changes" | 
|  | 107 | +      - name: Push changes | 
|  | 108 | +        if: ${{ steps.changed-files.outputs.any_modified == 'true' || | 
|  | 109 | +            github.event_name == 'workflow_dispatch' || | 
|  | 110 | +            github.event_name == 'repository_dispatch' }} | 
|  | 111 | +        uses: ad-m/github-push-action@master | 
|  | 112 | +        with: | 
|  | 113 | +          repository: ChinYikMing/rv32emu-demo-system | 
|  | 114 | +          github_token: ${{ secrets.RV32EMU_DEMO_SYSTEM_TOKEN }} | 
|  | 115 | +          branch: main | 
0 commit comments