|
| 1 | +name: Export projects to HTML5 and deploy to GitHub Pages |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + |
| 7 | +env: |
| 8 | + GODOT_VERSION: 3.2.3 |
| 9 | + |
| 10 | +jobs: |
| 11 | + export-html5: |
| 12 | + name: Export projects to HTML5 and deploy to GitHub Pages |
| 13 | + runs-on: ubuntu-20.04 |
| 14 | + container: |
| 15 | + image: barichello/godot-ci:3.2.3 |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + |
| 19 | + |
| 20 | + - name: Setup |
| 21 | + run: | |
| 22 | + mkdir -p ~/.local/share/godot/templates/ |
| 23 | + mv /root/.local/share/godot/templates/$GODOT_VERSION.stable ~/.local/share/godot/templates/$GODOT_VERSION.stable |
| 24 | +
|
| 25 | + - name: Export projects to HTML5 |
| 26 | + run: | |
| 27 | + apt-get update -qq && apt-get install -qqq imagemagick |
| 28 | +
|
| 29 | + # Don't export Mono demos (not supported yet), demos that can't be run in HTML5 |
| 30 | + # since they're platform-specific or demos that are currently broken in HTML5. |
| 31 | + # Remember to update `.github/dist/footer.html` when updating the list of excluded demos. |
| 32 | + rm -rf \ |
| 33 | + 2d/hdr/ \ |
| 34 | + 3d/voxel/ \ |
| 35 | + audio/device_changer/ \ |
| 36 | + loading/background_load/ \ |
| 37 | + loading/multiple_threads_loading/ \ |
| 38 | + loading/threads/ \ |
| 39 | + misc/matrix_transform/ \ |
| 40 | + mobile/android_iap/ \ |
| 41 | + mobile/sensors/ \ |
| 42 | + mono/ \ |
| 43 | + networking/ \ |
| 44 | + plugins/ |
| 45 | +
|
| 46 | + for panorama in 3d/material_testers/backgrounds/*.hdr; do |
| 47 | + # Decrease the resolution to get below the 20 MB per-file limit. |
| 48 | + # Otherwise, the website can't be deployed as files larger than 20 MB |
| 49 | + # can't be pushed to GitHub anymore. |
| 50 | + mogrify -resize 75% "$panorama" |
| 51 | + done |
| 52 | +
|
| 53 | + BASEDIR="$PWD" |
| 54 | +
|
| 55 | + # Use absolute paths so that we can `cd` without having to go back to the parent directory manually. |
| 56 | + for demo in */*/; do |
| 57 | + echo "" |
| 58 | + echo "================================" |
| 59 | + echo "Exporting demo $demo..." |
| 60 | + echo "================================" |
| 61 | +
|
| 62 | + mkdir -p "$BASEDIR/.github/dist/$demo" |
| 63 | + cd "$BASEDIR/$demo" |
| 64 | +
|
| 65 | + # Copy an export template preset file configured for HTML5 exporting. |
| 66 | + # This way, we don't have to commit `export_presets.cfg` for each project. |
| 67 | + cp "$BASEDIR/.github/dist/export_presets.cfg" . |
| 68 | + godot --export "HTML5" "$BASEDIR/.github/dist/$demo/index.html" |
| 69 | +
|
| 70 | + # Replace the WASM file with a symbolic link to avoid duplicating files in the pushed branch. |
| 71 | + # (WASM files are identical across projects, but not PCK or HTML files.) |
| 72 | + mv -f "$BASEDIR/.github/dist/$demo/index.wasm" "$BASEDIR/.github/dist/index.wasm" |
| 73 | + # The symlink must be relative as it needs to point to a file within the pushed repository. |
| 74 | + ln -s "../../index.wasm" "$BASEDIR/.github/dist/$demo/index.wasm" |
| 75 | +
|
| 76 | + # Append the demo to the list of demos for the website. |
| 77 | + PROJECT_NAME=$(cat project.godot | grep "config/name" | cut -d '"' -f 2 | tr -d "\n") |
| 78 | + echo "<li><a href='$demo'><img width="64" height="64" src="$demo/favicon.png" alt=""> $PROJECT_NAME</a></li>" >> "$BASEDIR/.github/dist/demos.html" |
| 79 | + done |
| 80 | +
|
| 81 | + cat "$BASEDIR/.github/dist/header.html" "$BASEDIR/.github/dist/demos.html" "$BASEDIR/.github/dist/footer.html" > "$BASEDIR/.github/dist/index.html" |
| 82 | +
|
| 83 | + # Clean up files that don't need to be deployed. |
| 84 | + rm -f "$BASEDIR/.github/dist/header.html" "$BASEDIR/.github/dist/demos.html" "$BASEDIR/.github/dist/footer.html" "$BASEDIR/.github/dist/export_presets.cfg" |
| 85 | +
|
| 86 | + # Installing rsync is needed in order to deploy to GitHub Pages. Without it, the build will fail. |
| 87 | + - name: Install rsync 📚 |
| 88 | + run: | |
| 89 | + apt-get update -qq && apt-get install -qqq rsync |
| 90 | + - name: Deploy to GitHub Pages 🚀 |
| 91 | + uses: JamesIves/github-pages-deploy-action@releases/v3 |
| 92 | + with: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + # The branch the action should deploy to. |
| 95 | + BRANCH: gh-pages |
| 96 | + # The folder the action should deploy. |
| 97 | + FOLDER: .github/dist |
| 98 | + # Artifacts are large; don't keep the branch's history. |
| 99 | + SINGLE_COMMIT: true |
0 commit comments