Skip to content

Commit

Permalink
fix: use a custom export plugin to set build info (#41)
Browse files Browse the repository at this point in the history
* ci: run link checker only on pull request

* style: use an array like other workflows

* ci: rework renovate config to use a branch name for commit

* ci: load env vars before setup cache

* ci: better events to start snapcraft build

* chore: clean pre-commit config

* chore: better gitattributes

* build: add custom exportbuild info

* chore: add progress bar to curl

* chore: add changelog entry

* chore: update credits
  • Loading branch information
florianvazelle authored Feb 4, 2024
1 parent 0abc25d commit ee356f7
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 58 deletions.
9 changes: 8 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Properly detect languages on Github.
*.gd linguist-language=GDScript

# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
*.gd linguist-language=GDScript

# The above only works properly for Git 2.10+, so for older versions
# we need to manually list the binary files we don't want modified.
*.mp3 binary
*.png binary
*.hdr binary
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"fileMatch": ["^plug\\.gd$"],
"matchStrings": [
"\\s+plug\\(\"(?<gitUrl>.*?)\",\\ \\{\\s*\"commit\":\\ \"(?<currentValue>)(?<currentDigest>.*)\""
"\\s+plug\\(\"(?<gitUrl>.*?)\",\\ \\{\\s*\"commit\":\\ \"(?<currentDigest>.*)\",\\s*\"renovate-branch\":\\ \"(?<currentValue>.*)\""
],
"depNameTemplate": "{{{gitUrl}}}",
"packageNameTemplate": "https://github.com/{{{gitUrl}}}",
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/links.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Link Checker

on:
push:
pull_request:
types: [opened, edited, review_requested, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
linkchecker:

runs-on: ubuntu-latest

steps:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/lint_pr_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ name: Lint PR Title

on:
pull_request_target:
types:
- opened
- edited
- synchronize
types: [opened, edited, synchronize]

permissions:
pull-requests: read
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ jobs:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v1

- name: Load dotenv
run: just ci-load-dotenv

- name: Cache Godot
uses: actions/cache@v4
with:
Expand All @@ -76,9 +79,6 @@ jobs:
~/.local/share/godot/export_templates
key: ${{ env.godot_version }}

- name: Load dotenv
run: just ci-load-dotenv

- name: Export
run: just export-web

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/snapcraft-build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: Snapcraft Build

on:
push:
workflow_dispatch:
# Ensure the build works on main
push:
branches: [main]
# Ensure the build works on each pull request
pull_request:
# Build and publish on release
release:
types: [published]

jobs:
build:
Expand All @@ -22,9 +29,9 @@ jobs:
path: public/packaging
id: snapcraft

# Push, on each tag, to the stable channel
# Push, on each release, to the stable channel
- uses: snapcore/action-publish@v1
if: startsWith(github.ref, 'refs/tags/')
if: ${{ env.GITHUB_EVENT_NAME == 'release' }}
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_STORE_LOGIN }}
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data_*/
.plugged/
addons/*
!addons/gd-plug/
!addons/export-build-info/

# Python-specific ignores
venv/
Expand Down
14 changes: 8 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files # Prevent giant files from being committed
args: ['--maxkb=1500']
- id: fix-byte-order-marker # Prevents weird UTF-8 encoding edge cases
- id: check-case-conflict # Check if case-insensitive filesystems would bork
- id: check-docstring-first # Check for if docstring was misplaced
Expand Down Expand Up @@ -30,16 +32,16 @@ repos:
exclude: '^addons/gd-plug/'
- repo: local
hooks:
- id: lower-case-only
name: lower case only
- id: check-filenames-are-lowercase
name: check that filenames are lowercase
entry: filenames must be lower-case or lower_case only
language: fail
files: '[^a-z0-9._/-]'
exclude: |
(?x)^(
.godot/|
.reuse/|
addons/|
addons/gd-plug/|
CHANGELOG.md|
CONTRIBUTING.md|
CREDITS.md|
Expand All @@ -49,13 +51,13 @@ repos:
public/|
README.md
)
- id: check-shaders
name: check shaders
- id: format-shaders
name: format shaders
entry: clang-format
args:
- --style=llvm
- -Werror
- -i
language: system
files: \.gdshader$
exclude: ^addons/
exclude: ^addons/gd-plug/
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Copyright: 2019 Tomek
License: MIT
Source: https://github.com/KoBeWi/Godot-Universal-Fade

Files: addons/coi_serviceworker/*
Copyright: 2023 nisovin
License: MIT
Source: https://github.com/nisovin/godot-coi-serviceworker

# Models

Files: assets/blocks/*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Deprecated
### Removed
### Fixed
- Use a custom `EditorExportPlugin` to set build info ([#41](https://github.com/MechanicalFlower/Marble/pull/41))
### Security
### Dependencies
- Bump `actions/cache` from 3 to 4 ([#40](https://github.com/MechanicalFlower/Marble/pull/40))
Expand Down
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- "[addons/gd-plug/*](https://github.com/imjp94/gd-plug)" by **Tan Jian Ping** licensed under [MIT](./LICENSES/MIT.txt)
- "[addons/debug_menu/*](https://github.com/godot-extended-libraries/godot-debug-menu)" by **Hugo Locurcio and contributors** licensed under [MIT](./LICENSES/MIT.txt)
- "[addons/UniversalFade/*](https://github.com/KoBeWi/Godot-Universal-Fade)" by **Tomek** licensed under [MIT](./LICENSES/MIT.txt)
- "[addons/coi_serviceworker/*](https://github.com/nisovin/godot-coi-serviceworker)" by **nisovin** licensed under [MIT](./LICENSES/MIT.txt)
## Models
- "[assets/blocks/*](https://github.com/Zylann/marbles)" by **Zylann** licensed under [MIT](./LICENSES/MIT.txt)
## Textures
Expand Down
15 changes: 5 additions & 10 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ game_itchio_key := env_var_or_default('GAME_ITCHIO_KEY', "")
# Build info
datetime := `date '+%Y%m%d'`
short_version := replace_regex(game_version, "([0-9]+).([0-9]+).[0-9]+", "$1.$2")
build_date := `date +'%Y/%m/%d'`
commit_hash := `git log --pretty=format:"%H" -1`

# Python virtualenv
Expand All @@ -71,7 +70,7 @@ butler_platform := if arch() == "x86" { "linux-386" } else { if arch() == "x86_6

# Display all commands
@default:
echo "OS: {{ os() }} - ARCH: {{ arch() }}\n"
echo -e "OS: {{ os() }} - ARCH: {{ arch() }}\n"
just --list

# Create directories
Expand All @@ -88,7 +87,7 @@ butler_platform := if arch() == "x86" { "linux-386" } else { if arch() == "x86_6
# Download Godot
[private]
install-godot: makedirs
curl -L --silent -X GET "https://github.com/godotengine/godot-builds/releases/download/{{ godot_version }}/{{ godot_filename }}.zip" --output {{ cache_dir }}/{{ godot_filename }}.zip
curl -L --progress-bar -X GET "https://github.com/godotengine/godot-builds/releases/download/{{ godot_version }}/{{ godot_filename }}.zip" --output {{ cache_dir }}/{{ godot_filename }}.zip
unzip -o {{ cache_dir }}/{{ godot_filename }}.zip -d {{ cache_dir }}
cp {{ cache_dir }}/{{ godot_filename }} {{ godot_bin }}

Expand All @@ -100,7 +99,7 @@ install-godot: makedirs
# Download Godot export templates
[private]
install-templates: makedirs
curl -L --silent -X GET "https://github.com/godotengine/godot-builds/releases/download/{{ godot_version }}/{{ godot_template }}" --output {{ cache_dir }}/{{ godot_template }}
curl -L --progress-bar -X GET "https://github.com/godotengine/godot-builds/releases/download/{{ godot_version }}/{{ godot_template }}" --output {{ cache_dir }}/{{ godot_template }}
unzip -o {{ cache_dir }}/{{ godot_template }} -d {{ cache_dir }}
mkdir -p {{ godot_templates_dir }}
cp {{ cache_dir }}/templates/* {{ godot_templates_dir }}
Expand Down Expand Up @@ -133,7 +132,7 @@ export PIP_REQUIRE_VIRTUALENV := "true"
# Python virtualenv wrapper
[private]
@venv *ARGS:
[ ! -d {{ venv_dir }} ] && python3 -m venv {{ venv_dir }} || true
[ ! -d {{ venv_dir }} ] && python3 -m venv {{ venv_dir }} && touch {{ venv_dir }}/.gdignore || true
. {{ venv_dir }}/bin/activate && {{ ARGS }}

# Run files formatters
Expand Down Expand Up @@ -194,10 +193,6 @@ butler *ARGS: check-butler
sed -i "s,releases/download/.*/Marble-linux-v.*\.zip$,releases/download/{{ game_version }}/Marble-linux-v{{ game_version }}\.zip,g" ./public/packaging/snap/snapcraft.yaml
sed -i "s,Version=.*$,Version={{ game_version }},g" ./public/packaging/org.mechanicalflower.Marble.desktop

echo "Create the override.cfg"
touch override.cfg
echo -e '[build_info]\npackage/version="{{ game_version }}"\npackage/build_date="{{ build_date }}"\nsource/commit="{{ commit_hash }}"' > override.cfg

[private]
pre-export: clean-addons makedirs bump-version install-addons import-resources

Expand Down Expand Up @@ -237,7 +232,7 @@ export: export-windows export-mac export-linux
# Remove game plugins
clean-addons:
rm -rf .plugged
[ -f plug.gd ] && find addons/ -type d -not -name 'addons' -not -name 'gd-plug' -exec rm -rf {} \; || true
[ -f plug.gd ] && (cd addons/ && git clean -f -X -d) || true

# Remove files created by Godot
clean-resources:
Expand Down
19 changes: 19 additions & 0 deletions addons/export-build-info/build_info.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const BUILD_INFO_VERSION := "application/config/version"
const BUILD_INFO_COMMIT := "custom_options/build_info/commit"
const BUILD_INFO_DATE := "custom_options/build_info/date"


static func setup_build_info_settings():
var output := []

# Commit Hash
OS.execute("git", ["log", '--pretty=format:"%H"', "-1"], output, false)
output[0] = output[0].trim_suffix("\n")
ProjectSettings.set_as_internal(BUILD_INFO_COMMIT, true)
ProjectSettings.set_setting(BUILD_INFO_COMMIT, output[0])

# Datetime
OS.execute("date", ["+%Y/%m/%d"], output, false)
output[1] = output[1].trim_suffix("\n")
ProjectSettings.set_as_internal(BUILD_INFO_DATE, true)
ProjectSettings.set_setting(BUILD_INFO_DATE, output[1])
7 changes: 7 additions & 0 deletions addons/export-build-info/export_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends EditorExportPlugin

const BuildInfo := preload("res://addons/export-build-info/build_info.gd")


func _export_begin(_features, _is_debug, _path, _flags) -> void:
BuildInfo.setup_build_info_settings()
15 changes: 15 additions & 0 deletions addons/export-build-info/label.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@tool
extends Label

const BuildInfo := preload("res://addons/export-build-info/build_info.gd")


func _ready():
var build_version = ProjectSettings.get_setting(BuildInfo.BUILD_INFO_VERSION)
var build_commit = ProjectSettings.get_setting(BuildInfo.BUILD_INFO_COMMIT)
var build_date = ProjectSettings.get_setting(BuildInfo.BUILD_INFO_DATE)

if build_version and build_commit and build_date:
set_text("v%s @ %s\n%s" % [build_version, build_commit.left(7), build_date])
else:
set_text("")
7 changes: 7 additions & 0 deletions addons/export-build-info/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="build_info"
description=""
author="florianvazelle"
version="0.0.0"
script="plugin.gd"
17 changes: 17 additions & 0 deletions addons/export-build-info/plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@tool
extends EditorPlugin

const BuildInfo := preload("res://addons/export-build-info/build_info.gd")

var export_plugin := preload("res://addons/export-build-info/export_plugin.gd").new()


func _enter_tree():
add_export_plugin(export_plugin)

if Engine.is_editor_hint():
BuildInfo.setup_build_info_settings()


func _exit_tree():
remove_export_plugin(export_plugin)
12 changes: 6 additions & 6 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="override.cfg"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
Expand Down Expand Up @@ -35,8 +35,8 @@ application/modify_resources=true
application/icon=""
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version="1.4.6.20240114"
application/product_version="1.4.6.20240114"
application/file_version="1.4.6.20240204"
application/product_version="1.4.6.20240204"
application/company_name="Mechanical Flower"
application/product_name="Marble"
application/file_description=""
Expand Down Expand Up @@ -70,7 +70,7 @@ runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="override.cfg"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
Expand Down Expand Up @@ -110,7 +110,7 @@ runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="override.cfg"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
Expand Down Expand Up @@ -217,7 +217,7 @@ runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="override.cfg"
include_filter=""
exclude_filter=""
export_path=""
encryption_include_filters=""
Expand Down
12 changes: 9 additions & 3 deletions plug.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ extends "res://addons/gd-plug/plug.gd"
func _plugging():
plug(
"godot-extended-libraries/godot-debug-menu",
{"commit": "9d36ea23661d095198ff7fcfff2715172f73c983"}
{"commit": "9d36ea23661d095198ff7fcfff2715172f73c983", "renovate-branch": "master"}
)
plug(
"KoBeWi/Godot-Universal-Fade",
{"commit": "f091514bba652880f81c5bc8809e0ee4498988ea", "renovate-branch": "master"}
)
plug(
"nisovin/godot-coi-serviceworker",
{"commit": "de1be2989eda4c7d77a08b8c56cd94c769181c4e", "renovate-branch": "main"}
)
plug("KoBeWi/Godot-Universal-Fade", {"commit": "f091514bba652880f81c5bc8809e0ee4498988ea"})
plug("nisovin/godot-coi-serviceworker", {"commit": "de1be2989eda4c7d77a08b8c56cd94c769181c4e"})
7 changes: 6 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ SettingsManager="*res://scripts/framework/settings_manager.gd"
Shake="*res://scripts/shake.gd"
DebugMenu="*res://addons/debug_menu/debug_menu.tscn"

[custom_options]

build_info/commit="8ae31e80beb2a3f9b2f8682c2e6488e90aa01de9"
build_info/date="2024/02/04"

[display]

window/stretch/mode="viewport"
Expand All @@ -40,7 +45,7 @@ window/size/height=720

[editor_plugins]

enabled=PackedStringArray("res://addons/debug_menu/plugin.cfg", "res://addons/coi_serviceworker/plugin.cfg")
enabled=PackedStringArray("res://addons/coi_serviceworker/plugin.cfg", "res://addons/debug_menu/plugin.cfg", "res://addons/export-build-info/plugin.cfg")

[filesystem]

Expand Down
Loading

0 comments on commit ee356f7

Please sign in to comment.