tools for exporting godot projects via Github Actions
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
name: Setup
description: Setup godot and repo

runs:
  using: "composite"
  steps:
    - name: Check if setup needed
      id: setup
      run: |
        if [[ ! -d ~/.config/godot ]];
          then echo "needed=true" >> "$GITHUB_OUTPUT"; echo "::debug::need get deps";
        else
          echo "needed=false" >> "$GITHUB_OUTPUT"; echo "::debug::no need get deps";
        fi
      shell: bash

    - name: Checkout
      if: steps.setup.outputs.needed == 'true'
      uses: actions/checkout@v3
      with:
        fetch-depth: 0
        lfs: true
        submodules: recursive
        path: repo

    - name: Setup python
      if: steps.setup.outputs.needed == 'true'
      uses: actions/setup-python@v4
      with:
        python-version: "3.9"

    - name: Setup godot
      if: steps.setup.outputs.needed == 'true'
      run: |
        echo "::group::Setup godot"

        # config
        mkdir -p ~/.config/godot/
        mv /root/.config/godot/editor_settings-3.tres ~/.config/godot/editor_settings-3.tres
        PROJECT_PATH="$(wget -q 'https://raw.githubusercontent.com/bend-n/godot-actions/main/.github/actions/setup-godot/project_path.py' -O - | python - "$PROJECT_PATH")"
        echo "PROJECT_PATH=$PROJECT_PATH" >>$GITHUB_ENV
        cd "$PROJECT_PATH" || true

        # create version label thing
        git config --global --add safe.directory "$(pwd)" && printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" >version

        # templates
        TEMPS_DIRNAME="templates"
        [[ ${GODOT_VERSION:0:1} -gt 3 ]] && TEMPS_DIRNAME="export_templates"
        VERSION="$(wget -q 'https://raw.githubusercontent.com/bend-n/godot-actions/main/.github/actions/setup-godot/parse.py' -O - | python - "$GODOT_VERSION")"
        TEMPLATES_PATH=".local/share/godot/$TEMPS_DIRNAME/$VERSION"
        echo "Putting export templates in $TEMPLATES_PATH."
        mkdir -p "$HOME/$TEMPLATES_PATH"
        if [[ -f /root/templates.tpz ]]; then # brand new container
          mkdir -p ~/.cache
          unzip -q /root/templates.tpz -d "$HOME/$TEMPLATES_PATH"
        else # fallback to the old container method
          mv "/root/$TEMPLATES_PATH/"* "$HOME/$TEMPLATES_PATH"
        fi
        echo -e "Installed templates: $(ls "$HOME/$TEMPLATES_PATH" | tr '\n' ' ')\n"

        # gpm
        if [[ -f godot.package ]]; then
          echo "Installing addons via the GPM"
          wget -q "https://github.com/godot-package-manager/cli/releases/latest/download/godot-package-manager.x86_64" -O gpm
          chmod +x gpm
          ./gpm update --cfg-file godot.package --lock-file /dev/null
          rm gpm
        fi
        echo "::endgroup::"
      shell: bash