diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..10dff04 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,25 @@ +name: Publish desktop game builds + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + release: + if: github.ref == 'refs/heads/main' + runs-on: big-ship-unity + steps: + - name: Check out the update + uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ github.sha }} + persist-credentials: false + + - name: Verify and package the desktop players + run: bash Scripts/release.sh build + + - name: Publish the packages to Gitea Releases + env: + RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: bash Scripts/release.sh publish diff --git a/Assets/BigShipTycoon/Editor/TycoonBuild.cs b/Assets/BigShipTycoon/Editor/TycoonBuild.cs index b2761cf..6edc444 100644 --- a/Assets/BigShipTycoon/Editor/TycoonBuild.cs +++ b/Assets/BigShipTycoon/Editor/TycoonBuild.cs @@ -24,7 +24,6 @@ namespace BigShipTycoon.Editor EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) }; PlayerSettings.companyName = "Big Ship Tycoon"; PlayerSettings.productName = "Big Ship Tycoon"; - PlayerSettings.bundleVersion = "0.16.0"; PlayerSettings.defaultScreenWidth = 1920; PlayerSettings.defaultScreenHeight = 1080; PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow; diff --git a/README.md b/README.md index c80fa80..09738aa 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,14 @@ The MEGA liner has two separate fitting areas under **Sun deck**. Fit the **Sky Fleet and voyage chart coastlines use simplified public-domain [Natural Earth land polygons](https://www.naturalearthdata.com/downloads/50m-physical-vectors/50m-land/). +## Download the game + +Open [Releases](https://git.labs.casa/josh/cruiseSimulator/releases) and choose your operating system under the latest release. Windows and Linux packages are both 64-bit. Extract the entire archive and keep the executable with its data folder. On Windows, open `BigShipTycoon.exe`. On Linux, open `BigShipTycoon.x86_64` or run `./BigShipTycoon.x86_64` from the extracted folder. The `SHA256SUMS` attachment contains the checksums for both archives. + +Each push to `main` builds and verifies both players through [Gitea Actions](https://git.labs.casa/josh/cruiseSimulator/actions). A release is published after both archives and their checksums have uploaded. The tag combines the game version in `ProjectSettings/ProjectSettings.asset` with the exact revision’s short commit hash. The Releases page uses the repository’s access permissions. + +The workflow runs on the repository’s `big-ship-unity` runner. Keep it online with the editor from `ProjectSettings/ProjectVersion.txt` and both desktop build modules installed. Use `bash Scripts/release.sh build` to create and verify packages locally in `Builds/Release/`. Set `UNITY` to an editor executable or `UNITY_HUB_ROOT` to the Hub editor directory if Unity is installed elsewhere. + ## Build and verify Install Linux and Windows Build Support through Unity Hub. **Every gameplay or visual revision needs a fresh native Linux build.** These commands verify the economy and write the two desktop builds. diff --git a/Scripts/release.sh b/Scripts/release.sh new file mode 100644 index 0000000..743ac28 --- /dev/null +++ b/Scripts/release.sh @@ -0,0 +1,149 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd -- "$(dirname -- "$0")/.." +project_dir=$PWD +version=$(awk '/^[[:space:]]+bundleVersion:/ { print $2; exit }' ProjectSettings/ProjectSettings.asset) +commit=$(git rev-parse HEAD) +if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then + printf 'Expected a release version in ProjectSettings.asset, got %s\n' "$version" >&2 + exit 1 +fi +if [[ -n ${GITHUB_SHA:-} && $commit != "$GITHUB_SHA" ]]; then + printf 'The checked-out commit does not match the update that triggered this build.\n' >&2 + exit 1 +fi + +tag="v$version-${commit:0:12}" +package="BigShipTycoon-$tag" +out="$project_dir/Builds/Release/$tag" +linux_archive="$package-linux-x86_64.tar.gz" +windows_archive="$package-windows-x86_64.zip" +assets=("$linux_archive" "$windows_archive" SHA256SUMS) +work_dir= +trap 'if [[ -n $work_dir ]]; then rm -rf -- "$work_dir"; fi' EXIT + +run_unity() { + local target=$1 player=$2 log="$out/$1.log" + printf 'Building %s with Unity %s\n' "$target" "$editor_version" + if ! BIG_SHIP_TYCOON_BUILD_PATH="$player" "$editor" \ + -batchmode -nographics -quit -projectPath "$project_dir" -buildTarget "$target" \ + -executeMethod BigShipTycoon.Editor.TycoonBuild.VerifyAndBuild -logFile "$log"; then + tail -n 100 "$log" >&2 + return 1 + fi + grep -F 'Big Ship Tycoon economy verification passed' "$log" + grep -F 'Built Big Ship Tycoon for ' "$log" +} + +build_packages() { + editor_version=$(awk '/^m_EditorVersion:/ { print $2; exit }' ProjectSettings/ProjectVersion.txt) + local hub_root=${UNITY_HUB_ROOT:-"$HOME/Unity/Hub/Editor"} + editor=${UNITY:-"$hub_root/$editor_version/Editor/Unity"} + if [[ ! -x $editor ]]; then + printf 'Install Unity %s with Linux and Windows build support or set UNITY.\n' "$editor_version" >&2 + return 1 + fi + mkdir -p "$out" + work_dir=$(mktemp -d "$project_dir/Builds/.release.XXXXXXXX") + local linux_dir="$work_dir/linux/$package" windows_dir="$work_dir/windows/$package" + run_unity Linux64 "$linux_dir/BigShipTycoon.x86_64" + run_unity Win64 "$windows_dir/BigShipTycoon.exe" + [[ -x $linux_dir/BigShipTycoon.x86_64 && -f $linux_dir/UnityPlayer.so && -d $linux_dir/BigShipTycoon_Data ]] + [[ -f $windows_dir/BigShipTycoon.exe && -f $windows_dir/UnityPlayer.dll && -d $windows_dir/BigShipTycoon_Data ]] + + printf 'Big Ship Tycoon %s\n\nExtract the entire archive, then run ./BigShipTycoon.x86_64 from this folder.\nKeep the executable and data folder together.\n' "$tag" > "$linux_dir/START-HERE.txt" + printf 'Big Ship Tycoon %s\r\n\r\nExtract the entire ZIP, then open BigShipTycoon.exe inside this folder.\r\nKeep the executable and data folder together.\r\n' "$tag" > "$windows_dir/START-HERE.txt" + tar -czf "$work_dir/$linux_archive" -C "$work_dir/linux" "$package" + (cd "$work_dir/windows" && zip -q -r "$work_dir/$windows_archive" "$package") + (cd "$work_dir" && sha256sum "$linux_archive" "$windows_archive" > SHA256SUMS) + local asset + for asset in "${assets[@]}"; do + mv -- "$work_dir/$asset" "$out/$asset" + done + printf 'Packages ready in %s\n' "$out" +} + +release_api() { + local method=$1 endpoint=$2 expected=$3 + shift 3 + http_status=$(curl --silent --show-error --connect-timeout 20 --max-time 480 \ + --header "@$work_dir/auth-header" --header 'Accept: application/json' \ + --request "$method" --output "$work_dir/response.json" --write-out '%{http_code}' \ + "$@" "$api/releases$endpoint") + if [[ " $expected " != *" $http_status "* ]]; then + printf 'Gitea API %s %s returned HTTP %s\n' "$method" "$endpoint" "$http_status" >&2 + jq -r '.message // empty' "$work_dir/response.json" >&2 || true + return 1 + fi +} + +publish_packages() { + : "${GITHUB_REPOSITORY:?Expected the Gitea repository name}" "${GITHUB_SERVER_URL:?Expected the Gitea server}" \ + "${RELEASE_TOKEN:?Expected the Gitea release token}" + (cd "$out" && sha256sum --check SHA256SUMS) + api="${GITHUB_SERVER_URL%/}/api/v1/repos/$GITHUB_REPOSITORY" + work_dir=$(mktemp -d) + (umask 077; printf 'Authorization: token %s\n' "$RELEASE_TOKEN" > "$work_dir/auth-header") + + local body release id asset name old_asset_id page + release_api GET "/tags/$tag" '200 404' + if [[ $http_status == 200 ]]; then + release=$(cat "$work_dir/response.json") + else + # Some configurations omit drafts from the single-tag endpoint. + release= + for ((page=1; ; page++)); do + release_api GET "?draft=true&limit=50&page=$page" 200 + release=$(jq -c --arg tag "$tag" '.[] | select(.tag_name == $tag)' "$work_dir/response.json") + [[ -z $release && $(jq 'length' "$work_dir/response.json") -gt 0 ]] || break + done + fi + + if [[ -z $release ]]; then + body=$(printf '%s\n\n%s\n\n%s\n' \ + "$(git log -1 --format=%s)" \ + 'Download the Windows ZIP or Linux tar.gz and extract the entire archive. Run BigShipTycoon.exe on Windows or BigShipTycoon.x86_64 on Linux.' \ + "Build commit: $commit") + jq -n --arg tag "$tag" --arg commit "$commit" --arg name "Big Ship Tycoon $tag" --arg body "$body" \ + '{tag_name: $tag, target_commitish: $commit, name: $name, body: $body, draft: true}' > "$work_dir/draft.json" + release_api POST '' 201 --json "@$work_dir/draft.json" + release=$(cat "$work_dir/response.json") + fi + + if [[ $(jq -r '.target_commitish' <<< "$release") != "$commit" ]]; then + printf 'Release %s targets a different commit.\n' "$tag" >&2 + return 1 + fi + if [[ $(jq -r '.draft' <<< "$release") == false ]]; then + for name in "${assets[@]}"; do + jq -e --arg name "$name" 'any(.assets[]?; .name == $name and .size > 0)' <<< "$release" >/dev/null + done + printf 'Release %s is already published.\n' "$tag" + return + fi + + id=$(jq -er '.id' <<< "$release") + for name in "${assets[@]}"; do + asset="$out/$name" + # Replace artifacts from an incomplete draft so the checksum file matches this build. + old_asset_id=$(jq -r --arg name "$name" '.assets[]? | select(.name == $name) | .id' <<< "$release") + if [[ -n $old_asset_id ]]; then + release_api DELETE "/$id/assets/$old_asset_id" 204 + fi + printf 'Uploading %s\n' "$name" + release_api POST "/$id/assets" 201 --form "attachment=@$asset;type=application/octet-stream" + jq -e --arg name "$name" --argjson size "$(stat -c %s "$asset")" \ + '.name == $name and .size == $size' "$work_dir/response.json" >/dev/null + done + + release_api PATCH "/$id" 200 --json '{"draft":false}' + jq -e '.draft == false' "$work_dir/response.json" >/dev/null + printf 'Published %s/%s/releases/tag/%s\n' "${GITHUB_SERVER_URL%/}" "$GITHUB_REPOSITORY" "$tag" +} + +case ${1:-} in + build) build_packages ;; + publish) publish_packages ;; + *) printf 'Usage: %s build|publish\n' "$0" >&2; exit 2 ;; +esac