Add a new workflow to test that updater works as expected (#10599)
* Add workflow for installing latest version of netdata, building from source of this branch & running the updater. Add script build-dist to create the artifacts used for the update. * Add more distributions, arguments in updater script & accomodate review comment * Run updater within docker for 6 distributions * Remove unecessary change in updater * Correct netdata_version --> updater_version in check-updater script * Review comments: remove unused vars & replace == with =
kaskavel committed
Mar 3, 2021 at 21:36 UTC
cadbb5056d839e3bd72805e4f7ccdc76d2c4dbd3
3 files changed
+171
.github/scripts/build-dist.sh
new
+70
@@ -0,0 +1,70 @@
1
+#!/bin/sh
2
+#
3
+# Builds the netdata-vX.y.Z-xxxx.tar.gz source tarball (dist)
4
+
5
+set -e
6
+
7
+# shellcheck source=.github/scripts/functions.sh
8
+. "$(dirname "$0")/functions.sh"
9
+
10
+NAME="${NAME:-netdata}"
11
+VERSION="${VERSION:-"$(git describe --always)"}"
12
+BASENAME="$NAME-$VERSION"
13
+
14
+prepare_build() {
15
+ progress "Preparing build"
16
+ (
17
+ test -d artifacts || mkdir -p artifacts
18
+ echo "${VERSION}" > packaging/version
19
+ ) >&2
20
+}
21
+
22
+build_dist() {
23
+ progress "Building dist"
24
+ (
25
+ command -v git > /dev/null && [ -d .git ] && git clean -d -f
26
+ autoreconf -ivf
27
+ ./configure \
28
+ --prefix=/usr \
29
+ --sysconfdir=/etc \
30
+ --localstatedir=/var \
31
+ --libexecdir=/usr/libexec \
32
+ --with-zlib \
33
+ --with-math \
34
+ --with-user=netdata \
35
+ CFLAGS=-O2
36
+ make dist
37
+ mv "${BASENAME}.tar.gz" artifacts/
38
+ ) >&2
39
+}
40
+
41
+prepare_assets() {
42
+ progress "Preparing assets"
43
+ (
44
+ cp packaging/version artifacts/latest-version.txt
45
+ cd artifacts || exit 1
46
+ ln -f "${BASENAME}.tar.gz" netdata-latest.tar.gz
47
+ ln -f "${BASENAME}.gz.run" netdata-latest.gz.run
48
+ sha256sum -b ./* > "sha256sums.txt"
49
+ ) >&2
50
+}
51
+
52
+steps="prepare_build build_dist prepare_assets"
53
+
54
+_main() {
55
+ for step in $steps; do
56
+ if ! run "$step"; then
57
+ if [ -t 1 ]; then
58
+ debug
59
+ else
60
+ fail "Build failed"
61
+ fi
62
+ fi
63
+ done
64
+
65
+ echo "🎉 All Done!"
66
+}
67
+
68
+if [ -n "$0" ] && [ x"$0" != x"-bash" ]; then
69
+ _main "$@"
70
+fi
.github/scripts/check-updater.sh
new
+38
@@ -0,0 +1,38 @@
1
+#!/bin/sh
2
+#
3
+set -e
4
+# shellcheck source=.github/scripts/functions.sh
5
+. "$(dirname "$0")/functions.sh"
6
+
7
+check_successfull_update() {
8
+ progress "Check netdata version after update"
9
+ (
10
+ netdata_version=$(netdata -v | awk '{print $2}')
11
+ updater_version=$(cat packaging/version)
12
+ if [ "$netdata_version" = "$updater_version" ]; then
13
+ echo "Update successfull!"
14
+ else
15
+ exit 1
16
+ fi
17
+ ) >&2
18
+}
19
+
20
+steps="check_successfull_update"
21
+
22
+_main() {
23
+ for step in $steps; do
24
+ if ! run "$step"; then
25
+ if [ -t 1 ]; then
26
+ debug
27
+ else
28
+ fail "Build failed"
29
+ fi
30
+ fi
31
+ done
32
+
33
+ echo "🎉 All Done!"
34
+}
35
+
36
+if [ -n "$0" ] && [ x"$0" != x"-bash" ]; then
37
+ _main "$@"
38
+fi
.github/workflows/updater.yml
new
+63
@@ -0,0 +1,63 @@
1
+---
2
+name: Updater
3
+on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+jobs:
12
+ source-build:
13
+ name: Install, Build & Update
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ distro:
18
+ - 'debian:10'
19
+ - 'ubuntu:20.10'
20
+ - 'alpine:3.13'
21
+ - 'centos:8'
22
+ - 'clearlinux:latest'
23
+ - 'fedora:33'
24
+ include:
25
+ - distro: 'alpine:3.13'
26
+ pre: 'apk add -U bash'
27
+ - distro: 'centos:8'
28
+ rmjsonc: 'dnf remove -y json-c-devel'
29
+ - distro: 'debian:10'
30
+ pre: 'apt-get update'
31
+ - distro: 'ubuntu:20.10'
32
+ pre: 'apt-get update'
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - name: Git clone repository
36
+ uses: actions/checkout@v2
37
+ - name: Install required packages & build tarball
38
+ run: |
39
+ ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata-all
40
+ .github/scripts/build-dist.sh
41
+ - name: Run a dockerised web server to serve files used by the custom update script
42
+ run: |
43
+ docker run -dit --name my-apache-app -p 8080:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
44
+ - name: Replace URLs in updater script to point at the local web server
45
+ run: |
46
+ ORIG_TARBALL="export NETDATA_TARBALL_URL=.*"
47
+ ORIG_CHECKSUM="export NETDATA_TARBALL_CHECKSUM_URL=.*"
48
+ CURRENT_VERSION="current_version=.*"
49
+ NEW_TARBALL="export NETDATA_TARBALL_URL=http://localhost:8080/artifacts/netdata-latest.tar.gz"
50
+ NEW_CHECKSUM="export NETDATA_TARBALL_CHECKSUM_URL=http://localhost:8080/artifacts/sha256sums.txt"
51
+ sed -i "s|${ORIG_TARBALL}|${NEW_TARBALL}|g" packaging/installer/netdata-updater.sh
52
+ sed -i "s|${ORIG_CHECKSUM}|${NEW_CHECKSUM}|g" packaging/installer/netdata-updater.sh
53
+ sed -i "s|"current_version=.*"|"current_version=1"|g" packaging/installer/netdata-updater.sh
54
+ - name: Install netdata and run the updater on ${{ matrix.distro }}
55
+ env:
56
+ PRE: ${{ matrix.pre }}
57
+ run: |
58
+ echo $PRE > ./prep-cmd.sh
59
+ docker build . -f .github/dockerfiles/Dockerfile.build_test -t test --build-arg BASE=${{ matrix.distro }}
60
+ docker run --network host -w /netdata test \
61
+ /bin/sh -c '/netdata/packaging/installer/kickstart.sh --dont-wait \
62
+ && /netdata/packaging/installer/netdata-updater.sh --not-running-from-cron --no-updater-self-update \
63
+ && bash /netdata/.github/scripts/check-updater.sh'