116 lines
2.7 KiB
Bash
Executable File
116 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Publishes the mod API (dev.overlord.zomboidforge:api), the mod tools (mod-tools), and the
|
|
# Gradle plugin (dev.overlord.zomboidforge) to the Maven registry of the ZomboidForge Gitea, in
|
|
# the version of the v* git tag on HEAD, without the "v".
|
|
#
|
|
# A pre-release version (containing "-", e.g. 0.3.0-rc.1) is built and tested but never
|
|
# published. Without a v* tag on HEAD nothing is published.
|
|
#
|
|
# Usage:
|
|
# ci/publish.sh test runs the checks of the published modules; needs no credentials
|
|
# ci/publish.sh publish publishes them without running the checks again
|
|
#
|
|
# Environment (publish only):
|
|
# ORG_GRADLE_PROJECT_giteaUsername Gitea user with package write access
|
|
# ORG_GRADLE_PROJECT_giteaPassword Token of that user
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
set -o pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
readonly REPO_ROOT
|
|
|
|
readonly MODULES=(
|
|
api
|
|
mod-tools
|
|
gradle-plugin
|
|
)
|
|
|
|
log() {
|
|
echo "[publish] $*" >&2
|
|
}
|
|
|
|
# Prints the v* tag on HEAD without its "v", or nothing.
|
|
release_tag_version() {
|
|
local tag
|
|
|
|
if tag="$(git -C "${REPO_ROOT}" describe --tags --exact-match --match 'v*' 2> /dev/null)"; then
|
|
echo "${tag#v}"
|
|
fi
|
|
}
|
|
|
|
# Gradle tasks for every module, e.g. ":api:check".
|
|
module_tasks() {
|
|
local task="$1"
|
|
local module
|
|
|
|
for module in "${MODULES[@]}"; do
|
|
echo ":${module}:${task}"
|
|
done
|
|
}
|
|
|
|
run_gradle() {
|
|
local version="$1"
|
|
shift
|
|
|
|
"${REPO_ROOT}/gradlew" \
|
|
--no-daemon \
|
|
--project-dir "${REPO_ROOT}" \
|
|
"-Pversion=${version}" \
|
|
"$@"
|
|
}
|
|
|
|
run_tests() {
|
|
local version="$1"
|
|
local check_tasks
|
|
|
|
mapfile -t check_tasks < <(module_tasks check)
|
|
|
|
log "Testing ZomboidForge ${version}: ${MODULES[*]}"
|
|
run_gradle "${version}" :core:check "${check_tasks[@]}"
|
|
}
|
|
|
|
publish() {
|
|
local version="$1"
|
|
local publish_tasks
|
|
|
|
if [[ "${version}" == *-* ]]; then
|
|
log "${version} is a pre-release version; nothing is published."
|
|
return
|
|
fi
|
|
|
|
mapfile -t publish_tasks < <(module_tasks publishAllPublicationsToGiteaRepository)
|
|
|
|
log "Publishing ZomboidForge ${version}"
|
|
run_gradle "${version}" "${publish_tasks[@]}"
|
|
log "Published ${MODULES[*]} ${version}"
|
|
}
|
|
|
|
main() {
|
|
local step="${1:-}"
|
|
local version
|
|
|
|
version="$(release_tag_version)"
|
|
if [[ -z "${version}" ]]; then
|
|
log "HEAD has no v* git tag (not a release commit, or a shallow clone without tags?); nothing to publish."
|
|
exit 1
|
|
fi
|
|
|
|
case "${step}" in
|
|
test)
|
|
run_tests "${version}"
|
|
;;
|
|
publish)
|
|
publish "${version}"
|
|
;;
|
|
*)
|
|
log "Usage: ci/publish.sh test|publish"
|
|
exit 2
|
|
;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|