Skip to content

Commit 0780ea4

Browse files
m4gr3dakien-mga
andcommitted
Add logic to upload the Godot Android library to MavenCentral
Add environment variables to sign the release build for the Godot Android editor and to publish the library to MavenCentral. If the environment vars are not defined, we do a simple unsigned `release_debug` build for the Android editor. Change `config.sh.in` template to use single quotes by default, to prevent expanding special characters in environment variables. To publish to MavenCentral, a new `build-android/upload-mavencentral.sh` script is added. It needs to run after the build using gradle, but we still want it to be optional and used only when making an official release, so we copy the compiled sources in the first step. Co-authored-by: Rémi Verschelde <[email protected]>
1 parent 72cb40f commit 0780ea4

File tree

6 files changed

+121
-34
lines changed

6 files changed

+121
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# User-specific configuration and signing key
1+
# User-specific configuration and signing keys
22
config.sh
3+
*.jks
34
*.pfx
45
*.pkcs12
56

build-android/build.sh

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,46 @@ mkdir godot
1414
cd godot
1515
tar xf /root/godot.tar.gz --strip-components=1
1616

17+
# Environment variables and keystore needed for signing store editor build,
18+
# as well as signing and publishing to MavenCentral.
19+
source /root/keystore/config.sh
20+
21+
store_release="yes"
22+
if [ -z "${GODOT_ANDROID_SIGN_KEYSTORE}" ]; then
23+
echo "No keystore provided to sign the Android release editor build, using debug build instead."
24+
store_release="no"
25+
fi
26+
1727
# Classical
1828

1929
dnf -y install gettext
2030

2131
if [ "${CLASSICAL}" == "1" ]; then
2232
echo "Starting classical build for Android..."
2333

24-
$SCONS platform=android arch=arm32 $OPTIONS target=editor
25-
$SCONS platform=android arch=arm64 $OPTIONS target=editor
26-
$SCONS platform=android arch=x86_32 $OPTIONS target=editor
27-
$SCONS platform=android arch=x86_64 $OPTIONS target=editor
34+
$SCONS platform=android arch=arm32 $OPTIONS target=editor store_release=${store_release}
35+
$SCONS platform=android arch=arm64 $OPTIONS target=editor store_release=${store_release}
36+
$SCONS platform=android arch=x86_32 $OPTIONS target=editor store_release=${store_release}
37+
$SCONS platform=android arch=x86_64 $OPTIONS target=editor store_release=${store_release}
2838

2939
pushd platform/android/java
3040
./gradlew generateGodotEditor
3141
popd
3242

3343
mkdir -p /root/out/tools
34-
cp bin/android_editor.apk /root/out/tools/
44+
# Copy the generated Android editor binaries (apk & aab).
45+
if [ "$store_release" == "yes" ]; then
46+
cp bin/android_editor_builds/android_editor-release.apk /root/out/tools/android_editor.apk
47+
cp bin/android_editor_builds/android_editor-release.aab /root/out/tools/android_editor.aab
48+
else
49+
cp bin/android_editor_builds/android_editor-debug.apk /root/out/tools/android_editor.apk
50+
cp bin/android_editor_builds/android_editor-debug.aab /root/out/tools/android_editor.aab
51+
fi
52+
53+
# Restart from a clean tarball, as we'll copy all the contents
54+
# outside the container for the MavenCentral upload.
55+
rm -rf /root/godot/*
56+
tar xf /root/godot.tar.gz --strip-components=1
3557

3658
$SCONS platform=android arch=arm32 $OPTIONS target=template_debug
3759
$SCONS platform=android arch=arm32 $OPTIONS target=template_release
@@ -47,6 +69,14 @@ if [ "${CLASSICAL}" == "1" ]; then
4769

4870
pushd platform/android/java
4971
./gradlew generateGodotTemplates
72+
73+
if [ "$store_release" == "yes" ]; then
74+
# Copy source folder with compiled libs so we can optionally use it
75+
# in a separate script to upload the templates to MavenCentral.
76+
cp -r /root/godot /root/out/source/
77+
# Backup ~/.gradle too so we can reuse all the downloaded stuff.
78+
cp -r /root/.gradle /root/out/source/.gradle
79+
fi
5080
popd
5181

5282
mkdir -p /root/out/templates

build-android/upload-mavencentral.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#/bin/bash
2+
3+
basedir="$(pwd)"
4+
5+
if [ ! -d "${basedir}/deps/keystore" ]; then
6+
echo "Couldn't find ${basedir}/deps/keystore. Make sure to run this from the root folder of the Git repository."
7+
fi
8+
9+
source ${basedir}/deps/keystore/config.sh
10+
11+
# Release the Godot Android library to MavenCentral
12+
${PODMAN} run -it --rm \
13+
-v ${basedir}/out/android/source:/root/godot -v ${basedir}/deps/keystore:/root/keystore \
14+
localhost/godot-android:${IMAGE_VERSION} bash -c \
15+
"source /root/keystore/config.sh && \
16+
cp -r /root/godot/.gradle /root && \
17+
cd /root/godot/platform/android/java && \
18+
./gradlew publishTemplateReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository"

build-release.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ if [ "${build_classical}" == "1" ]; then
319319
# Editor
320320
binname="${godot_basename}_android_editor.apk"
321321
cp out/android/tools/android_editor.apk ${reldir}/${binname}
322+
binname="${godot_basename}_android_editor.aab"
323+
cp out/android/tools/android_editor.aab ${reldir}/${binname}
322324

323325
# Templates
324326
cp out/android/templates/*.apk ${templatesdir}/

build.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,7 @@ while getopts "h?r:u:p:v:g:b:fsc" opt; do
8383
esac
8484
done
8585

86-
export podman=none
87-
if which podman > /dev/null; then
88-
export podman=podman
89-
elif which docker > /dev/null; then
90-
export podman=docker
91-
fi
92-
93-
if [ "${podman}" == "none" ]; then
94-
echo "Either podman or docker needs to be installed"
95-
exit 1
96-
fi
86+
export podman=${PODMAN}
9787

9888
if [ $UID != 0 ]; then
9989
echo "WARNING: Running as non-root may cause problems for the uwp build"
@@ -150,6 +140,18 @@ if [ ! -d "deps/vulkansdk-macos" ]; then
150140
echo "Missing Vulkan SDK for macOS, we're going to run into issues!"
151141
fi
152142

143+
# Keystore for Android editor signing
144+
# Optional - the config.sh will be copied but if it's not filled in,
145+
# it will do an unsigned build.
146+
if [ ! -d "deps/keystore" ]; then
147+
mkdir -p deps/keystore
148+
cp config.sh deps/keystore/
149+
if [ ! -z "$GODOT_ANDROID_SIGN_KEYSTORE" ]; then
150+
cp "$GODOT_ANDROID_SIGN_KEYSTORE" deps/keystore/
151+
sed -i deps/keystore/config.sh -e "s@$GODOT_ANDROID_SIGN_KEYSTORE@/root/keystore/$GODOT_ANDROID_SIGN_KEYSTORE@"
152+
fi
153+
fi
154+
153155
if [ "${skip_git_checkout}" == 0 ]; then
154156
git clone https://github.com/godotengine/godot git || /bin/true
155157
pushd git
@@ -183,7 +185,7 @@ mkdir -p ${basedir}/out/logs
183185
mkdir -p ${basedir}/mono-glue
184186

185187
export podman_run="${podman} run -it --rm --env BUILD_NAME --env GODOT_VERSION_STATUS --env NUM_CORES --env CLASSICAL=${build_classical} --env MONO=${build_mono} -v ${basedir}/godot-${godot_version}.tar.gz:/root/godot.tar.gz -v ${basedir}/mono-glue:/root/mono-glue -w /root/"
186-
export img_version=4.x-f36
188+
export img_version=$IMAGE_VERSION
187189

188190
mkdir -p ${basedir}/mono-glue
189191
${podman_run} -v ${basedir}/build-mono-glue:/root/build localhost/godot-linux:${img_version} bash build/build.sh 2>&1 | tee ${basedir}/out/logs/mono-glue
@@ -201,7 +203,7 @@ mkdir -p ${basedir}/out/macos
201203
${podman_run} -v ${basedir}/build-macos:/root/build -v ${basedir}/out/macos:/root/out -v ${basedir}/deps/vulkansdk-macos:/root/vulkansdk localhost/godot-osx:${img_version} bash build/build.sh 2>&1 | tee ${basedir}/out/logs/macos
202204

203205
mkdir -p ${basedir}/out/android
204-
${podman_run} -v ${basedir}/build-android:/root/build -v ${basedir}/out/android:/root/out localhost/godot-android:${img_version} bash build/build.sh 2>&1 | tee ${basedir}/out/logs/android
206+
${podman_run} -v ${basedir}/build-android:/root/build -v ${basedir}/out/android:/root/out -v ${basedir}/deps/keystore:/root/keystore localhost/godot-android:${img_version} bash build/build.sh 2>&1 | tee ${basedir}/out/logs/android
205207

206208
mkdir -p ${basedir}/out/ios
207209
${podman_run} -v ${basedir}/build-ios:/root/build -v ${basedir}/out/ios:/root/out localhost/godot-ios:${img_version} bash build/build.sh 2>&1 | tee ${basedir}/out/logs/ios

config.sh.in

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
# Configuration file for user-specific details.
44
# This file is gitignore'd and will be sourced by build scripts.
55

6+
# Note: For passwords or GPG keys, make sure that special characters such
7+
# as $ won't be expanded, by using single quotes to enclose the string,
8+
# or escaping with \$.
9+
10+
# These scripts are designed and tested against podman. They may also work
11+
# with docker, but it's not guaranteed. You can set this variable to the
12+
# relevant tool in your PATH or an absolute path to run it from.
13+
export PODMAN='podman'
14+
615
# Registry for build containers.
716
# The default registry is the one used for official Godot builds.
817
# Note that some of its images are private and only accessible to selected
918
# contributors.
1019
# You can build your own registry with scripts at
1120
# https://github.com/godotengine/build-containers
12-
export REGISTRY="registry.prehensile-tales.com"
21+
export REGISTRY='registry.prehensile-tales.com'
22+
23+
# Version string of the images to use in build.sh.
24+
export IMAGE_VERSION='4.x-f36'
1325

1426
# Default build name used to distinguish between official and custom builds.
15-
export BUILD_NAME="custom_build"
27+
export BUILD_NAME='custom_build'
1628

1729
# Default number of parallel cores for each build.
1830
export NUM_CORES=16
@@ -21,28 +33,50 @@ export NUM_CORES=16
2133
# If you do not fill all SIGN_* fields, signing will be skipped.
2234

2335
# Path to pkcs12 archive.
24-
export SIGN_KEYSTORE=""
36+
export SIGN_KEYSTORE=''
2537

2638
# Password for the private key.
27-
export SIGN_PASSWORD=""
39+
export SIGN_PASSWORD=''
2840

2941
# Name and URL of the signed application.
3042
# Use your own when making a thirdparty build.
31-
export SIGN_NAME=""
32-
export SIGN_URL=""
43+
export SIGN_NAME=''
44+
export SIGN_URL=''
3345

34-
# Hostname or IP address of an macOS host (Needed for signing)
35-
36-
export OSX_HOST=""
46+
# Hostname or IP address of an OSX host (Needed for signing)
47+
48+
export OSX_HOST=''
3749
# ID of the Apple certificate used to sign
38-
export OSX_KEY_ID=""
50+
export OSX_KEY_ID=''
3951
# Bundle id for the signed app
40-
export OSX_BUNDLE_ID=""
52+
export OSX_BUNDLE_ID=''
4153
# Username/password for Apple's signing APIs (used for atltool)
42-
export APPLE_ID=""
43-
export APPLE_ID_PASSWORD=""
54+
export APPLE_ID=''
55+
export APPLE_ID_PASSWORD=''
4456

4557
# NuGet source for publishing .NET packages
46-
export NUGET_SOURCE="nuget.org"
58+
export NUGET_SOURCE='nuget.org'
4759
# API key for publishing NuGet packages to nuget.org
48-
export NUGET_API_KEY=""
60+
export NUGET_API_KEY=''
61+
62+
# MavenCentral (sonatype) credentials
63+
export OSSRH_GROUP_ID=''
64+
export OSSRH_USERNAME=''
65+
export OSSRH_PASSWORD=''
66+
# Sonatype assigned ID used to upload the generated artifacts
67+
export SONATYPE_STAGING_PROFILE_ID=''
68+
# Used to sign the artifacts after they're built
69+
# ID of the GPG key pair, the last eight characters of its fingerprint
70+
export SIGNING_KEY_ID=''
71+
# Passphrase of the key pair
72+
export SIGNING_PASSWORD=''
73+
# Base64 encoded private GPG key
74+
export SIGNING_KEY=''
75+
76+
# Android signing configs
77+
# Path to the Android keystore file used to sign the release build
78+
export GODOT_ANDROID_SIGN_KEYSTORE=''
79+
# Key alias used for signing the release build
80+
export GODOT_ANDROID_KEYSTORE_ALIAS=''
81+
# Password for the key used for signing the release build
82+
export GODOT_ANDROID_SIGN_PASSWORD=''

0 commit comments

Comments
 (0)