aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux/build-debian.sh
blob: ff7d9dbbe74edc7f81f95c54ae8839929f55f7ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash

set -exo pipefail

export DEBEMAIL="rafael+deb@rafaelmartins.eng.br"
export DEBFULLNAME="Automatic Builder (github-actions)"
export DEB_BUILD_OPTIONS="noddebs"

export DIST="$(echo "${TARGET}" | cut -d- -f2)"

MY_P="${PN}_${PV}"
ARCH="$(echo "${TARGET}" | cut -d- -f3)"

REV=
case ${DIST} in
    bullseye)
        REV="1~11bullseye"
        ;;
    bookworm)
        REV="1~12bookworm"
        ;;
    sid)
        REV="1~sid"
        DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS} nocheck"
        ;;
    focal)
        REV="1~11.0focal"
        ;;
    jammy)
        REV="1~12.0jammy"
        DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS} nocheck"
        ;;
    kinetic)
        REV="1~12.1kinetic"
        DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS} nocheck"
        ;;
    *)
        echo "error: unsupported dist: ${DIST}"
        exit 1
        ;;
esac

download_pbuilder_chroot() {
    local index="$(wget -q -O- https://distfiles.rgm.io/pbuilder-chroots/LATEST/)"
    local archive="$(echo "${index}" | sed -n "s/.*\(pbuilder-chroot-${DIST}-${ARCH}-.*\)\.sha512.*/\1/p" | head -n 1)"
    local p="$(echo "${index}" | sed -n "s/.*pbuilder-chroot-${DIST}-${ARCH}-\(.*\)\.tar.*\.sha512.*/pbuilder-chroots-\1/p" | head -n 1)"

    pushd "${SRCDIR}" > /dev/null

    wget -c "https://distfiles.rgm.io/pbuilder-chroots/${p}/${archive}"{,.sha512}
    sha512sum --check --status "${archive}.sha512"

    sudo rm -rf /tmp/pbuilder
    mkdir /tmp/pbuilder
    fakeroot tar --checkpoint=1000 -xf "${archive}" -C /tmp/pbuilder

    popd > /dev/null
}

download_orig() {
    local i=0
    local out=0
    local url="https://distfiles.rgm.io/${PN}/${P}/${P}.tar.xz"

    while [[ $i -lt 20 ]]; do
        set +ex
        ((i++))
        echo "waiting for ${P}.tar.xz: $i/20"
        wget -q --spider --tries 1 "${url}"
        out=$?
        set -ex

        if [[ $out -eq 0 ]]; then
            wget -c "${url}"
            mv "${P}.tar.xz" "${BUILDDIR}/${MY_P}.orig.tar.xz"
            return
        fi

        if [[ $out -ne 8 ]]; then
            exit $out
        fi

        sleep 30
    done

    echo "failed to find orig distfile. please check if that task succeeded."
    exit 1
}

create_reprepro_conf() {
    echo "Origin: blogc"
    echo "Label: blogc"
    echo "Codename: ${DIST}"
    echo "Architectures: source amd64"
    echo "Components: main"
    echo "Description: Apt repository containing blogc snapshots"
    echo
}

download_orig

rm -rf "${BUILDDIR}/${P}"
tar -xf "${BUILDDIR}/${MY_P}.orig.tar.xz" -C "${BUILDDIR}"
cp -r "${SRCDIR}/debian" "${BUILDDIR}/${P}/"

pushd "${BUILDDIR}/${P}" > /dev/null

## skip build silently when new version is older than last changelog version (version bump)
if ! dch \
    --distribution "${DIST}" \
    --newversion "${PV}-${REV}" \
    "Automated build for ${DIST}"
then
    exit 0
fi

download_pbuilder_chroot

sudo cowbuilder \
    --update \
    --basepath "/tmp/pbuilder/${DIST}-${ARCH}/base.cow"

RES="${BUILDDIR}/deb/${DIST}"
mkdir -p "${RES}"

pdebuild \
    --pbuilder cowbuilder \
    --buildresult "${RES}" \
    --debbuildopts -sa \
    -- --basepath "/tmp/pbuilder/${DIST}-${ARCH}/base.cow"

popd > /dev/null

mkdir -p "${BUILDDIR}/deb-repo/conf"
create_reprepro_conf > "${BUILDDIR}/deb-repo/conf/distributions"

pushd "${BUILDDIR}/deb-repo" > /dev/null

for i in "../deb/${DIST}"/*.changes; do
    reprepro include "${DIST}" "${i}"
done

popd > /dev/null

tar \
    -cJf "blogc-deb-repo-${DIST}-${ARCH}-${PV}.tar.xz" \
    --exclude ./deb-repo/conf \
    --exclude ./deb-repo/db \
    ./deb-repo

tar \
    -cJf "blogc-deb-${DIST}-${ARCH}-${PV}.tar.xz" \
    ./deb