abarichello / godot-ci

Docker image to export Godot Engine games. Templates for Gitlab CI and GitHub Actions to deploy to GitLab Pages/GitHub Pages/Itch.io.
https://hub.docker.com/r/barichello/godot-ci
MIT License
654 stars 125 forks source link

Cross origin requirements for godot 4 in the browser #116

Open matheusfillipe opened 1 year ago

matheusfillipe commented 1 year ago

Godot 4 now requires cross origin isolation and SharedArrayBuffer for web build servers, which can be tricky to setup on popular static website hosting platforms like netlify and itch.io, which you can still deal with, but specially github pages Trying to deploy with the current example actions will cause:

image

I have a workaround for that but still waits way too long to load for a very simple game (Not sure if it is related to that):

    name: "godot-ci export"
on: push

env:
  GODOT_VERSION: 4.0.3

jobs:
  export-web:
    name: Web Export
    runs-on: ubuntu-20.04
    container:
      image: barichello/godot-ci:4.0.3
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          lfs: true

      - name: Setup
        run: |
          mkdir -v -p ~/.local/share/godot/export_templates
          mv /root/.local/share/godot/templates/${GODOT_VERSION}.stable ~/.local/share/godot/export_templates/${GODOT_VERSION}.stable
      - name: Web Build
        run: |
          mkdir -v -p build/web
          godot -v --headless --export-release "Web" build/web/index.html
      - name: Install rsync 📚
        run: |
          apt-get update && apt-get install -y rsync curl
      - name: Patch for Cross Origin Isolation and SharedArrayBuffer
        run: |
          cd build/web/
          curl https://raw.githubusercontent.com/josephrocca/clip-image-sorter/92b108dc670d0b56bd6b72963b0e86c4c862412e/enable-threads.js --output enable-threads.js
          sed -i 's|headers.set("Cross-Origin-Embedder-Policy", "credentialless")|headers.set("Cross-Origin-Embedder-Policy", "require-corp")|g'  enable-threads.js
          sed -i 's|<script src="index.js"></script>|<script src="enable-threads.js"></script><script src="index.js"></script>|g' index.html
      - name: Upload Artifact
        uses: actions/upload-artifact@v1
        with:
          name: web
          path: build/web
      - name: Deploy to GitHub Pages 🚀
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: build/web # The folder the action should deploy.

https://github.com/orgs/community/discussions/13309 https://github.com/godotengine/godot/issues/70691

Calinou commented 6 months ago

I have a workaround for that but still waits way too long to load for a very simple game (Not sure if it is related to that):

On macOS, this is due to an upstream issue: https://github.com/godotengine/godot/issues/70691

On other platforms, this can occur on slower devices in general since the shader can take a very long time to compile.