Skip to content

Commit

Permalink
feat: add packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Apr 11, 2024
1 parent 0ac88fb commit 1c8232a
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 29 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/appimage-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: AppImage Build

on:
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:
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2

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

- name: Load dotenv
run: just bump-version

# Install FUSE (https://github.com/AppImage/AppImageKit/wiki/FUSE)
- name: Install pkg2image dependencies
run: |
sudo add-apt-repository universe
sudo apt install libfuse2
# Install pkg2appimage and build the game (https://github.com/AppImageCommunity/pkg2appimage)
- name: Build AppImage
run: |
wget -c $(wget -q https://api.github.com/repos/AppImageCommunity/pkg2appimage/releases -O - | grep "pkg2appimage-.*-x86_64.AppImage" | grep browser_download_url | head -n 1 | cut -d '"' -f 4)
chmod +x ./pkg2appimage-*.AppImage
./pkg2appimage-*.AppImage public/packaging/appimage/recipe.yml
- name: Rename the AppImage
run: mv ./out/*.AppImage ${{ env.game_name }}-${{ env.game_version }}.AppImage

- uses: actions/upload-artifact@v4
with:
name: ${{ env.game_name }}-${{ env.game_version }}.AppImage
path: ./

# Publish, on each release
- name: Publish AppImage
if: startsWith(github.ref, 'refs/tags/')
run: |
gh release upload ${{ env.game_version }} ./${{ env.game_name }}-${{ env.game_version }}.AppImage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/snapcraft-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Snapcraft Build

on:
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:
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2

- name: Load dotenv
run: just bump-version

- name: Build snap package
uses: snapcore/action-build@v1
with:
path: public/packaging
id: snapcraft

# Push, on each release, to the stable channel
- uses: snapcore/action-publish@v1
if: startsWith(github.ref, 'refs/tags/')
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_STORE_LOGIN }}
with:
snap: ${{ steps.snapcraft.outputs.snap }}
release: stable
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ repos:
LICENSE.md|
LICENSES/|
public/|
README.md
README.md|
RELEASING.md
)
- id: format-shaders
name: format shaders
Expand Down
64 changes: 36 additions & 28 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

set dotenv-load := true


# === Aliases ===

[private]
Expand All @@ -22,26 +21,22 @@ main_dir := home_dir / ".mkflower"
cache_dir := main_dir / "cache"
bin_dir := main_dir / "bin"

# Local directories
# Local directories for game exports
build_dir := justfile_directory() / "build"
dist_dir := justfile_directory() / "dist"

# Godot variables
godot_version := env_var('GODOT_VERSION')
godot_platform := if arch() == "x86" {
"linux.x86_32"
} else {
if arch() == "x86_64" {
} else if arch() == "x86_64" {
"linux.x86_64"
} else {
if arch() == "arm" {
"linux.arm32"
} else {
if arch() == "aarch64" {
"linux.arm64"
} else { "" }
}
}
} else if arch() == "arm" {
"linux.arm32"
} else if arch() == "aarch64" {
"linux.arm64"
} else {
""
}
godot_filename := "Godot_v" + godot_version + "_" + godot_platform
godot_template := "Godot_v" + godot_version + "_export_templates.tpz"
Expand All @@ -64,7 +59,13 @@ venv_dir := justfile_directory() / "venv"

# Butler binary
butler_bin := bin_dir / "butler"
butler_platform := if arch() == "x86" { "linux-386" } else { if arch() == "x86_64" { "linux-amd64" } else{ "" } }
butler_platform := if arch() == "x86" {
"linux-386"
} else if arch() == "x86_64" {
"linux-amd64"
} else {
""
}

# === Commands ===

Expand All @@ -80,9 +81,8 @@ butler_platform := if arch() == "x86" { "linux-386" } else { if arch() == "x86_6

# === Installer ===
#
# Recipes that check and/or install some binaries like Godot, Bulter ...
# This means the user doesn't have to worry about installation,
# and can be sure that the same code is running in CI and locally.
# Recipes for checking and/or installing binaries like Godot and Butler.
# Ensures consistent environments across CI and local development.

# Download Godot
[private]
Expand All @@ -91,7 +91,7 @@ install-godot: makedirs
unzip -o {{ cache_dir }}/{{ godot_filename }}.zip -d {{ cache_dir }}
cp {{ cache_dir }}/{{ godot_filename }} {{ godot_bin }}

# Download Godot if not already done
# Check and download Godot if not already installed
[private]
@check-godot:
[ ! -e {{ godot_bin }} ] && just install-godot || true
Expand All @@ -104,7 +104,7 @@ install-templates: makedirs
mkdir -p {{ godot_templates_dir }}
cp {{ cache_dir }}/templates/* {{ godot_templates_dir }}

# Download Godot export templates if not already done
# Check and download Godot export templates if not already installed
[private]
@check-templates:
[ ! -d {{ godot_templates_dir }} ] && just install-templates || true
Expand All @@ -117,15 +117,16 @@ install-butler: makedirs
mv {{ cache_dir }}/butler {{ butler_bin }}
chmod +x {{ butler_bin }}

# Download Butler if not already done
# Check and download Butler if not already installed
[private]
@check-butler:
[ ! -e {{ butler_bin }} ] && just install-butler || true

# === Python ===
#
# Recipes that use python or python packages.
# This ensures that all python packages are installed in a virtual environment.
# Recipes for working with Python and Python packages.
# These recipes ensure that Python packages are installed within a virtual environment,
# providing a clean and isolated environment.

export PIP_REQUIRE_VIRTUALENV := "true"

Expand All @@ -146,8 +147,10 @@ credits:

# === Godot ===
#
# Recipes around the Godot binary.
# This simplifies some recurring tasks, such as installing addons.
# Recipes for managing the Godot binary.
# These recipes simplify common tasks such as installing addons, importing game resources,
# and opening the Godot editor.


# Godot binary wrapper
godot *ARGS: check-godot check-templates
Expand All @@ -169,12 +172,18 @@ godot *ARGS: check-godot check-templates
just godot --editor

# === Butler ===
#
# Recipes for managing the Butler binary.

# Bulter wrapper
butler *ARGS: check-butler
{{ butler_bin }} {{ ARGS }}

# === Export ===
#
# Recipes for exporting the game to different platforms.
# Handles tasks such as updating version information, preparing directories,
# and exporting the game for Windows, MacOS, Linux, and the web.

# Updates the game version for export
@bump-version:
Expand Down Expand Up @@ -220,8 +229,7 @@ export: export-windows export-mac export-linux

# === Clean ===
#
# Recipes that clean up the project, deleting
# files and folders created by this Justfile.
# Recipes for cleaning up the project, removing files and folders created by this Justfile.

# Remove game plugins
clean-addons:
Expand All @@ -241,8 +249,8 @@ clean: clean-addons clean-resources clean-export

# === CI ===
#
# Recipes launched by CI steps.
# They can be run locally, but requires the setup of some environment variables.
# Recipes triggered by CI steps.
# Can be run locally but requires setup of environment variables.

# Add some variables to Github env
ci-load-dotenv:
Expand Down
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,98 @@ A template to create new [Godot Engine](https://godotengine.org/) project.
Eventually, you can remove any unused files, such as irrelevant github workflows for your project.
Feel free to replace the License with one suited for your project.

## Installation

### From a release

Released binaries are available on Itch.io and
on the Github repository, in the release section.

Download the zip archive, accordingly to your OS, and unzip it.

- **Windows**: Double click on `Greeter.exe`.
- **MacOS**: Double click on `Greeter.app`.
- **Linux**: In a terminal, run `./Greeter.x86_64`.

### From Snap

With the [Snap command line](https://manpages.ubuntu.com/manpages/focal/en/man8/snap.8.html), run:
```
snap install godot-template
```

To run the game:
```
godot-template.greeter
```

### From an AppImage

The AppImage is available on the Github
repository, in the release section.

More details on how to run an AppImage, on the
[official documentation](https://docs.appimage.org/introduction/quickstart.html#how-to-run-an-appimage).

### From source

> [!IMPORTANT]
> For this installation, you need to have
> the Godot Editor installed.
Clone the source locally:
```
git clone https://github.com/MechanicalFlower/godot-template.git
```

You need to install addons first:
```
godot --headless --script plug.gd install
```

And simply run the game as any Godot project:
```
godot
```

## Development

The project use:
- [`just`](https://just.systems/man/en/) as command runner,
- [`pre-commit`](https://pre-commit.com/) to run formatters, this requires [Python 3](https://docs.python.org/3/).

> [!IMPORTANT]
> Actually, `just` recipes only support Linux.
To check all available recipes, run:
```
just
```

To run formatters:
```
just fmt
```

To install, and run the game:
```
just install-addons
just godot
```

> [!TIP]
> In `just` recipes, the Godot Editor is installed
> automatically. This ensure that you
> use the right version of the engine.
## Contributing

![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)

We welcome community contributions to this project.

Please read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.

## Releasing

Please read our [Release Guide](RELEASING.md) for more information on how we manage our releases.
Loading

0 comments on commit 1c8232a

Please sign in to comment.