moth

Monarch Of The Hill game server
git clone https://git.woozle.org/neale/moth.git

moth / build / ci
Neale Pickett  ·  2023-10-18

ci.sh

 1#! /bin/sh
 2
 3set -e
 4
 5images="ghcr.io/dirtbags/moth dirtbags/moth"
 6
 7ACTION=$1
 8if [ -z "$ACTION" ]; then
 9    echo "Usage: $0 ACTION"
10    exit 1
11fi
12
13log () {
14    printf "=== %s\n" "$*" 1>&2
15}
16
17fail () {
18    printf "\033[31;1m=== FAIL: %s\033[0m\n" "$*" 1>&2
19    exit 1
20}
21
22run () {
23    printf "\033[32m\$\033[0m %s\n" "$*" 1>&2
24    "$@"
25}
26
27tags () {
28    pfx=$1
29    for base in $images; do
30        echo $pfx $base:${CI_COMMIT_REF_NAME}
31        echo $pfx $base:${CI_COMMIT_REF_NAME%.*}
32        echo $pfx $base:${CI_COMMIT_REF_NAME%.*.*}
33    done | uniq
34}
35
36case $ACTION in
37    publish)
38        run docker build \
39            --file build/package/Containerfile \
40            $(tags --tag) \
41            .
42        tags | while read image; do
43            run docker push $image
44        done
45    ;;
46    release)
47        run go build -v ./cmd/mothd
48        run go build -v ./cmd/transpile
49        run tar czf moth-$(git tag --contains).$(uname -s)-$(uname -m).tar.gz mothd transpile theme
50        ;;
51*)
52    echo "Unknown action: $1" 1>&2
53    exit 1
54    ;;
55esac
56