Introduce versioning from git tags and improve CI/CD workflows
This commit is contained in:
1 parent
989cb88e0a
commit
e13132c202
6 files changed
+58
-9
No files matched your search
@@ -19,6 +19,9 @@ jobs:
|
||||
steam_branch: public
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# release.sh derives the version from the newest v* tag
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Build and verify
|
||||
env:
|
||||
|
||||
@@ -21,6 +21,9 @@ jobs:
|
||||
latest: "true"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# release.sh derives the version from the newest v* tag
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Log in to the registry
|
||||
env:
|
||||
|
||||
+6
-2
@@ -12,7 +12,8 @@
|
||||
# server reports another one. Default: pz.version in gradle.properties
|
||||
# STEAMCLIENT bundled (default) or steamcmd: replace the server's steamclient.so
|
||||
# files with steamcmd's newer copies
|
||||
# FORGE_VERSION Image label only; set by ci/release.sh
|
||||
# FORGE_VERSION ZomboidForge version (jar manifest, image label); set by ci/release.sh.
|
||||
# Default: 0.0.0-prerelease
|
||||
# STEAM_BUILDID Image label only; set by ci/release.sh
|
||||
|
||||
ARG PZ_BRANCH=public
|
||||
@@ -50,11 +51,14 @@ COPY agent agent
|
||||
COPY patcher patcher
|
||||
COPY --from=server /server/java/projectzomboid.jar /pz/projectzomboid.jar
|
||||
|
||||
# An empty PZ_VERSION keeps pz.version from gradle.properties.
|
||||
# An empty PZ_VERSION keeps pz.version from gradle.properties; an empty FORGE_VERSION gives
|
||||
# the build the fallback version 0.0.0-prerelease (the image has no git history).
|
||||
ARG PZ_VERSION
|
||||
ARG FORGE_VERSION
|
||||
RUN ./gradlew --no-daemon \
|
||||
-Ppz.jar=/pz/projectzomboid.jar \
|
||||
${PZ_VERSION:+-Ppz.version=${PZ_VERSION}} \
|
||||
${FORGE_VERSION:+-Pversion=${FORGE_VERSION}} \
|
||||
build :patcher:patchServerJar
|
||||
|
||||
# --- Stage 3: runtime ------------------------------------------------------------
|
||||
|
||||
@@ -2,6 +2,22 @@ plugins {
|
||||
java
|
||||
}
|
||||
|
||||
// Version: -Pversion if given, else the newest v* git tag, else 0.0.0-prerelease.
|
||||
if (version == Project.DEFAULT_VERSION)
|
||||
{
|
||||
val latestTag = providers.exec {
|
||||
workingDir = layout.settingsDirectory.asFile
|
||||
commandLine("git", "describe", "--tags", "--abbrev=0", "--match", "v*")
|
||||
isIgnoreExitValue = true
|
||||
}
|
||||
|
||||
version = latestTag.standardOutput.asText
|
||||
.map { it.trim().removePrefix("v") }
|
||||
.orElse("")
|
||||
.get()
|
||||
.ifEmpty { "0.0.0-prerelease" }
|
||||
}
|
||||
|
||||
val projectZomboid = extensions.create<ProjectZomboidExtension>("projectZomboid")
|
||||
projectZomboid.serverJar.convention(
|
||||
layout.settingsDirectory.file(
|
||||
|
||||
+30
-6
@@ -7,13 +7,17 @@
|
||||
# <forge>-pz<pz> moves to the newest Steam build of that version
|
||||
# latest only with LATEST=true
|
||||
#
|
||||
# <forge> is the newest v* git tag reachable from HEAD, without the "v" (v0.2.0 -> 0.2.0).
|
||||
# A pre-release version (containing "-", e.g. 0.2.0-rc.1) is built and verified but never
|
||||
# published. Without any v* tag the version is "0.0.0-prerelease".
|
||||
#
|
||||
# Nothing is built when the immutable tag already exists in the registry.
|
||||
#
|
||||
# Environment:
|
||||
# IMAGE Image name without tag, e.g. git.security-command.org/overlord/zomboidforge
|
||||
# PZ_BRANCH Steam branch. Default: public
|
||||
# PZ_VERSION Expected Project Zomboid version. Default: pz.version in gradle.properties
|
||||
# PUBLISH true: push the tags. Default: false (build and verify only)
|
||||
# PUBLISH true: push the tags (not for pre-release versions). Default: false (build and verify only)
|
||||
# LATEST true: also push "latest". Default: false
|
||||
# CONTAINER_ENGINE docker or podman. Default: docker if installed, else podman
|
||||
|
||||
@@ -26,7 +30,7 @@ readonly REPO_ROOT
|
||||
|
||||
readonly IMAGE="${IMAGE:?IMAGE is required}"
|
||||
readonly PZ_BRANCH="${PZ_BRANCH:-public}"
|
||||
readonly PUBLISH="${PUBLISH:-false}"
|
||||
readonly REQUESTED_PUBLISH="${PUBLISH:-false}"
|
||||
readonly LATEST="${LATEST:-false}"
|
||||
|
||||
log() {
|
||||
@@ -59,6 +63,16 @@ gradle_property() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Prints the forge version: the newest v* tag reachable from HEAD without its "v",
|
||||
# or nothing when the repository has no such tag.
|
||||
release_tag_version() {
|
||||
local tag
|
||||
|
||||
if tag="$(git -C "${REPO_ROOT}" describe --tags --abbrev=0 --match 'v*' 2> /dev/null)"; then
|
||||
echo "${tag#v}"
|
||||
fi
|
||||
}
|
||||
|
||||
image_exists() {
|
||||
local reference="$1"
|
||||
"$(container_engine)" manifest inspect "${reference}" > /dev/null 2>&1
|
||||
@@ -104,10 +118,20 @@ push_as() {
|
||||
|
||||
main() {
|
||||
local forge_version
|
||||
local publish="${REQUESTED_PUBLISH}"
|
||||
local pz_version
|
||||
local build_id
|
||||
|
||||
forge_version="$(gradle_property version)"
|
||||
forge_version="$(release_tag_version)"
|
||||
if [[ -z "${forge_version}" ]]; then
|
||||
forge_version="0.0.0-prerelease"
|
||||
log "No v* git tag found (shallow clone without tags?); using version ${forge_version}."
|
||||
fi
|
||||
if [[ "${forge_version}" == *-* ]]; then
|
||||
publish=false
|
||||
log "${forge_version} is a pre-release version; nothing will be published."
|
||||
fi
|
||||
|
||||
pz_version="${PZ_VERSION:-$(gradle_property pz.version)}"
|
||||
build_id="$("${REPO_ROOT}/ci/steam-buildid.sh" "${PZ_BRANCH}")"
|
||||
|
||||
@@ -115,7 +139,7 @@ main() {
|
||||
local version_tag="${IMAGE}:${forge_version}-pz${pz_version}"
|
||||
log "ZomboidForge ${forge_version}, Project Zomboid ${pz_version}, Steam branch ${PZ_BRANCH} build ${build_id}"
|
||||
|
||||
if [[ "${PUBLISH}" == true ]] && image_exists "${immutable_tag}"; then
|
||||
if [[ "${publish}" == true ]] && image_exists "${immutable_tag}"; then
|
||||
log "${immutable_tag} is already published; nothing to do."
|
||||
return
|
||||
fi
|
||||
@@ -123,8 +147,8 @@ main() {
|
||||
build_image "${immutable_tag}" "${forge_version}" "${pz_version}" "${build_id}"
|
||||
verify_build_id "${immutable_tag}" "${build_id}"
|
||||
|
||||
if [[ "${PUBLISH}" != true ]]; then
|
||||
log "Built ${immutable_tag} (PUBLISH is not true; nothing pushed)"
|
||||
if [[ "${publish}" != true ]]; then
|
||||
log "Built ${immutable_tag} (not published)"
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
group=dev.overlord.zomboidforge
|
||||
version=0.1.0-SNAPSHOT
|
||||
|
||||
# Project Zomboid version the build targets. Selects compat/b<major>/, and
|
||||
# :patcher:patchServerJar fails when the server jar reports another version.
|
||||
|
||||
Reference in new issue
Block a user