Skip to content

Commit

Permalink
Update actions, enable scons cache
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Aug 28, 2023
1 parent ab34184 commit d2c5095
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 36 deletions.
35 changes: 35 additions & 0 deletions .github/actions/build-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Setup build cache
description: Setup build cache.
inputs:
cache-name:
description: The cache base name (job name by default).
default: "${{github.job}}"
scons-cache:
description: The scons cache path.
default: "${{github.workspace}}/.scons-cache/"
runs:
using: "composite"
steps:
# Upload cache on completion and check it out now
- name: Load .scons_cache directory
uses: actions/cache@v3
with:
path: ${{inputs.scons-cache}}
key: ${{inputs.cache-name}}-main-${{github.ref}}-${{github.sha}}

# We try to match an existing cache to restore from it. Each potential key is checked against
# all existing caches as a prefix. E.g. 'linux-template-minimal' would match any cache that
# starts with "linux-template-minimal", such as "linux-template-minimal-master-refs/heads/master-6588a4a29af1621086feac0117d5d4d37af957fd".
#
# We check these prefixes in this order:
#
# 1. The exact match, including the base branch, the commit reference, and the SHA hash of the commit.
# 2. A partial match for the same base branch and the same commit reference.
# 3. A partial match for the same base branch and the base branch commit reference.
# 4. A partial match for the same base branch only (not ideal, matches any PR with the same base branch).

restore-keys: |
${{inputs.cache-name}}-main-${{github.ref}}-${{github.sha}}
${{inputs.cache-name}}-main-${{github.ref}}
${{inputs.cache-name}}-main-refs/heads/main
${{inputs.cache-name}}-main
62 changes: 62 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 🤖 Android Builds
on: [ workflow_call, workflow_dispatch ]

env:
SCONSFLAGS: verbose=yes

jobs:
build:
runs-on: ${{ matrix.runner }}
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- identifier: android-debug
name: Android Debug
runner: ubuntu-20.04
target: template_debug
platform: android
arch: arm64
- identifier: android-release
name: Android Release
runner: ubuntu-20.04
target: template_release
platform: android
arch: arm64

steps:
- name: Checkout project
uses: actions/checkout@v3
with:
submodules: recursive

- name: (Android) Set up Android dependencies
if: ${{ startsWith(matrix.identifier, 'android-') }}
uses: ./.github/actions/android-deps

- name: Setup python & scons
uses: ./.github/actions/base-deps

- name: Compile extension
shell: sh
env:
SCONS_CACHE: "${{ github.workspace }}/.scons-cache/"
SCONS_CACHE_LIMIT: 7168
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' ${{ env.SCONSFLAGS }} -j2
ls -l project/addons/terrain_3d/bin/
- name: Prepare artifact
shell: sh
run: |
strip project/addons/terrain_3d/bin/libterrain.*
ls -l project/addons/terrain_3d/bin/
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' ${{ github.workspace }}/project/addons/terrain_3d/
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: |
${{ github.workspace }}/project/
54 changes: 30 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 🛠️ Build All
on: workflow_dispatch

env:
SCONSFLAGS: verbose=yes

jobs:
build:
runs-on: ${{ matrix.runner }}
Expand Down Expand Up @@ -33,6 +36,18 @@ jobs:
target: template_release
platform: windows
arch: x86_64
- name: macOS Debug
target: template_debug
platform: macos
- name: macOS Release
target: template_release
platform: macos
- identifier: android-debug
name: Android Debug
runner: ubuntu-20.04
target: template_debug
platform: android
arch: arm64
- identifier: android-release
name: Android Release
runner: ubuntu-20.04
Expand Down Expand Up @@ -61,38 +76,29 @@ jobs:
- name: Setup python & scons
uses: ./.github/actions/base-deps

# TODO: Cache doesn't work yet. SCons rebuilds the objects even if they already exist. Could be caused by modification dates or extension_api.json.
# fetch-depth: 0 May be needed for cache. See: <https://github.com/actions/checkout/issues/468>.
# - name: Set up SCons cache
# uses: actions/cache@v3
# with:
# path: |
# ${{ github.workspace }}/.scons-cache/
# ${{ github.workspace }}/**/.sconsign.dblite
# ${{ github.workspace }}/godot-cpp/gen/
# key: ${{ matrix.identifier }}-${{ github.ref }}-${{ github.sha }}
# restore-keys: |
# ${{ matrix.identifier }}-${{ github.ref }}-${{ github.sha }}
# ${{ matrix.identifier }}-${{ github.ref }}
# ${{ matrix.identifier }}

- name: Compile extension
shell: sh
# env:
# SCONS_CACHE: '${{ github.workspace }}/.scons-cache/'
# SCONS_CACHE_LIMIT: 8192
env:
SCONS_CACHE: "${{ github.workspace }}/.scons-cache/"
SCONS_CACHE_LIMIT: 7168
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' -j2
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' ${{ env.SCONSFLAGS }} -j2
ls -l project/addons/terrain_3d/bin/
- name: Prepare artifact
- name: Strip libraries
shell: sh
run: |
strip project/addons/terrain_3d/bin/libterrain.*
if [ -x "project/addons/terrain_3d/bin/libterrain.macos.debug.framework" ]; then
strip project/addons/terrain_3d/bin/libterrain.macos.{debug,release}.framework/*
else
strip project/addons/terrain_3d/bin/libterrain.*
fi
ls -l project/addons/terrain_3d/bin/
for addon in ${{ github.workspace }}/project/addons/terrain_3d/; do
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' "$addon"
done
- name: Prepare artifact
shell: sh
run: |
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' ${{ github.workspace }}/project/addons/terrain_3d/
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ jobs:
- name: Setup python & scons
uses: ./.github/actions/base-deps

- name: Setup build cache
uses: ./.github/actions/build-cache
with:
cache-name: ${{ matrix.identifier }}
continue-on-error: true

- name: Compile extension
shell: sh
env:
SCONS_CACHE: "${{ github.workspace }}/.scons-cache/"
SCONS_CACHE_LIMIT: 7168
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' ${{ env.SCONSFLAGS }} -j2
ls -l project/addons/terrain_3d/bin/
Expand All @@ -43,9 +52,7 @@ jobs:
run: |
strip project/addons/terrain_3d/bin/libterrain.*
ls -l project/addons/terrain_3d/bin/
for addon in ${{ github.workspace }}/project/addons/terrain_3d/; do
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' "$addon"
done
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' ${{ github.workspace }}/project/addons/terrain_3d/
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ jobs:

- name: Compile extension
shell: sh
env:
SCONS_CACHE: "${{ github.workspace }}/.scons-cache/"
SCONS_CACHE_LIMIT: 7168
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' ${{ env.SCONSFLAGS }} -j2
ls -l project/addons/terrain_3d/bin/
- name: Prepare artifact
shell: sh
run: |
strip project/addons/terrain_3d/bin/libterrain.*
strip project/addons/terrain_3d/bin/libterrain.macos.{debug,release}.framework/*
ls -l project/addons/terrain_3d/bin/
for addon in ${{ github.workspace }}/project/addons/terrain_3d/; do
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' "$addon"
done
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' ${{ github.workspace }}/project/addons/terrain_3d/
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 🪟 Build (Windows)
on: workflow_dispatch

env:
SCONSFLAGS: verbose=yes

jobs:
build:
runs-on: ${{ matrix.runner }}
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- identifier: windows-debug
name: Windows Debug
runner: ubuntu-20.04
target: template_debug
platform: windows
arch: x86_64
- identifier: windows-release
name: Windows Release
runner: ubuntu-20.04
target: template_release
platform: windows
arch: x86_64

steps:
- name: Checkout project
uses: actions/checkout@v3
with:
submodules: recursive

- name: (Windows) Install mingw64
if: ${{ startsWith(matrix.identifier, 'windows-') }}
shell: sh
run: |
sudo apt-get install mingw-w64
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
- name: Setup python & scons
uses: ./.github/actions/base-deps

- name: Compile extension
shell: sh
env:
SCONS_CACHE: "${{ github.workspace }}/.scons-cache/"
SCONS_CACHE_LIMIT: 7168
run: |
scons target='${{ matrix.target }}' platform='${{ matrix.platform }}' arch='${{ matrix.arch }}' ${{ env.SCONSFLAGS }} -j2
ls -l project/addons/terrain_3d/bin/
- name: Prepare artifact
shell: sh
run: |
strip project/addons/terrain_3d/bin/libterrain.*
ls -l project/addons/terrain_3d/bin/
cp --no-clobber '${{ github.workspace }}/README.md' '${{ github.workspace }}/LICENSE' ${{ github.workspace }}/project/addons/terrain_3d/
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: |
${{ github.workspace }}/project/
10 changes: 5 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from glob import glob
from pathlib import Path
import os

# TODO: Do not copy environment after godot-cpp/test is updated <https://github.com/godotengine/godot-cpp/blob/master/test/SConstruct>.
env = SConscript("godot-cpp/SConstruct")
Expand All @@ -18,11 +19,10 @@ addon_path = Path(extension_path).parent
# Find the project name from the gdextension file (e.g. example).
project_name = Path(extension_path).stem

# TODO: Cache is disabled currently.
# scons_cache_path = os.environ.get("SCONS_CACHE")
# if scons_cache_path != None:
# CacheDir(scons_cache_path)
# print("Scons cache enabled... (path: '" + scons_cache_path + "')")
scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path != None:
CacheDir(scons_cache_path)
print("Scons cache enabled... (path: '" + scons_cache_path + "')")

# Create the library target (e.g. libexample.linux.debug.x86_64.so).
debug_or_release = "release" if env["target"] == "template_release" else "debug"
Expand Down

0 comments on commit d2c5095

Please sign in to comment.