From 516c52ad207e84fa88606170fdf8d8e94872314c Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 26 May 2019 10:52:09 -0400 Subject: [PATCH] feat(travis): publish nightly builds off Travis-CI --- .travis.yml | 71 +++++++++++++++++++++++++++--- .travis/build-windows.sh | 9 +++- .travis/cirp/check_cache.sh | 8 ++++ .travis/cirp/check_precondition.sh | 11 +++++ .travis/cirp/cleanup1.sh | 10 +++++ .travis/cirp/cleanup2.sh | 10 +++++ .travis/cirp/cleanup3.sh | 11 +++++ .travis/cirp/cleanup4.sh | 10 +++++ .travis/cirp/cleanup5.sh | 17 +++++++ .travis/cirp/collect.sh | 23 ++++++++++ .travis/cirp/install.sh | 61 +++++++++++++++++++++++++ .travis/cirp/publish.sh | 32 ++++++++++++++ .travis/cirp/store.sh | 23 ++++++++++ .travis/cirp/update_cache.sh | 8 ++++ 14 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 .travis/cirp/check_cache.sh create mode 100644 .travis/cirp/check_precondition.sh create mode 100755 .travis/cirp/cleanup1.sh create mode 100755 .travis/cirp/cleanup2.sh create mode 100755 .travis/cirp/cleanup3.sh create mode 100755 .travis/cirp/cleanup4.sh create mode 100755 .travis/cirp/cleanup5.sh create mode 100755 .travis/cirp/collect.sh create mode 100644 .travis/cirp/install.sh create mode 100755 .travis/cirp/publish.sh create mode 100755 .travis/cirp/store.sh create mode 100644 .travis/cirp/update_cache.sh diff --git a/.travis.yml b/.travis.yml index b863ac428..1e5f9c1bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,10 @@ stages: - name: "Windows Stage 3: qTox" if: type = push AND branch = master +env: + global: + - CIRP_GITHUB_REPO_SLUG="qTox/qTox-nightly-releases" + jobs: include: - stage: Linux @@ -82,7 +86,13 @@ jobs: - stage: "Windows Stage 3: qTox" os: linux env: WINDOWS_BUILD_ARCH_CACHE_TRICK_VARIABLE=i686 - script: ./.travis/build-windows.sh i686 release /opt/build-windows/i686 stage3 + script: + - ./.travis/build-windows.sh i686 release /opt/build-windows/i686 stage3 + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./workspace/i686/qtox/release/{setup-qtox-i686-release.exe,setup-qtox-i686-release.exe.sha256,qtox-i686-release.zip,qtox-i686-release.zip.sha256} "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker cache: @@ -91,7 +101,13 @@ jobs: - stage: "Windows Stage 3: qTox" os: linux env: WINDOWS_BUILD_ARCH_CACHE_TRICK_VARIABLE=x86_64 - script: ./.travis/build-windows.sh x86_64 release /opt/build-windows/x86_64 stage3 + script: + - ./.travis/build-windows.sh x86_64 release /opt/build-windows/x86_64 stage3 + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./workspace/x86_64/qtox/release/{setup-qtox-x86_64-release.exe,setup-qtox-x86_64-release.exe.sha256,qtox-x86_64-release.zip,qtox-x86_64-release.zip.sha256} "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker cache: @@ -100,7 +116,13 @@ jobs: - stage: "Windows Stage 3: qTox" os: linux env: WINDOWS_BUILD_ARCH_CACHE_TRICK_VARIABLE=i686 - script: ./.travis/build-windows.sh i686 debug /opt/build-windows/i686 stage3 + script: + - ./.travis/build-windows.sh i686 debug /opt/build-windows/i686 stage3 + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./workspace/i686/qtox/debug/{qtox-i686-debug.zip,qtox-i686-debug.zip.sha256} "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker cache: @@ -109,7 +131,13 @@ jobs: - stage: "Windows Stage 3: qTox" os: linux env: WINDOWS_BUILD_ARCH_CACHE_TRICK_VARIABLE=x86_64 - script: ./.travis/build-windows.sh x86_64 debug /opt/build-windows/x86_64 stage3 + script: + - ./.travis/build-windows.sh x86_64 debug /opt/build-windows/x86_64 stage3 + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./workspace/x86_64/qtox/debug/{qtox-x86_64-debug.zip,qtox-x86_64-debug.zip.sha256} "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker cache: @@ -126,19 +154,48 @@ jobs: - $HOME/Library/Caches/Homebrew before_cache: - brew cleanup - script: "./.travis/$JOB.sh" + script: + - "./.travis/$JOB.sh" + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./{qTox.dmg,qTox.dmg.sha256} "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh - stage: "macOS, AppImage and Flatpak" os: linux env: JOB=APPIMAGE - script: ./appimage/build-appimage.sh + script: + - ./appimage/build-appimage.sh + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./output/* "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker - stage: "macOS, AppImage and Flatpak" os: linux env: JOB=FLATPAK - script: ./flatpak/build-flatpak.sh + script: + - ./flatpak/build-flatpak.sh + - export ARTIFACTS_DIR="$(mktemp -d)" + - cp -a ./output/* "$ARTIFACTS_DIR" + - .travis/cirp/cleanup1.sh + - .travis/cirp/store.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup2.sh services: - docker + - stage: "Nightly publishing" + if: type == cron + script: + - export ARTIFACTS_DIR="$(mktemp -d)" + - .travis/cirp/collect.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup4.sh + - .travis/cirp/publish.sh "$ARTIFACTS_DIR" + - .travis/cirp/cleanup5.sh + cache: + directories: + - /opt/cirp diff --git a/.travis/build-windows.sh b/.travis/build-windows.sh index 72704e0b9..7d793a86e 100755 --- a/.travis/build-windows.sh +++ b/.travis/build-windows.sh @@ -135,10 +135,15 @@ then fi # Generate checksum files for releases -if [ "$STAGE" == "stage3" ] && [ "$BUILD_TYPE" == "release" ] +if [ "$STAGE" == "stage3" ] then readonly OUT_DIR=./workspace/"$ARCH"/qtox/"$BUILD_TYPE"/ - readonly NAME=setup-qtox-"$ARCH"-"$BUILD_TYPE".exe + if [ "$BUILD_TYPE" == "release" ] + then + NAME=setup-qtox-"$ARCH"-"$BUILD_TYPE".exe + sha256sum "$OUT_DIR""$NAME" > "$OUT_DIR""$NAME".sha256 + fi + NAME=qtox-"$ARCH"-"$BUILD_TYPE".zip sha256sum "$OUT_DIR""$NAME" > "$OUT_DIR""$NAME".sha256 fi diff --git a/.travis/cirp/check_cache.sh b/.travis/cirp/check_cache.sh new file mode 100644 index 000000000..f5b5b3bb6 --- /dev/null +++ b/.travis/cirp/check_cache.sh @@ -0,0 +1,8 @@ +if [ -f "/opt/cirp/previous_runs_commit" ] && [ "$(cat /opt/cirp/previous_runs_commit)" == "$(git rev-parse HEAD)" ] +then + # No new commits in the repo + touch /opt/cirp/previous_runs_commit + git log -1 + echo "No new commits in the repo" + exit 0 +fi diff --git a/.travis/cirp/check_precondition.sh b/.travis/cirp/check_precondition.sh new file mode 100644 index 000000000..d5bed1990 --- /dev/null +++ b/.travis/cirp/check_precondition.sh @@ -0,0 +1,11 @@ +if [ ! -z "$TRAVIS_EVENT_TYPE" ] && [ "$TRAVIS_EVENT_TYPE" != "cron" ] +then + echo "Skipping publishing in a non-cron build" + exit 0 +fi + +if [ ! -z "$TRAVIS_PULL_REQUEST" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ] +then + echo "Skipping publishing in a Pull Request" + exit 0 +fi diff --git a/.travis/cirp/cleanup1.sh b/.travis/cirp/cleanup1.sh new file mode 100755 index 000000000..89135893c --- /dev/null +++ b/.travis/cirp/cleanup1.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh +. .travis/cirp/install.sh + +ci-release-publisher cleanup_publish +ci-release-publisher cleanup_store --scope current-job previous-finished-builds \ + --release complete incomplete diff --git a/.travis/cirp/cleanup2.sh b/.travis/cirp/cleanup2.sh new file mode 100755 index 000000000..144bbc93f --- /dev/null +++ b/.travis/cirp/cleanup2.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh +. .travis/cirp/install.sh + +ci-release-publisher cleanup_store --scope current-build \ + --release complete \ + --on-nonallowed-failure diff --git a/.travis/cirp/cleanup3.sh b/.travis/cirp/cleanup3.sh new file mode 100755 index 000000000..a47ff7bdd --- /dev/null +++ b/.travis/cirp/cleanup3.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh +. .travis/cirp/install.sh + +ci-release-publisher cleanup_publish +ci-release-publisher cleanup_store --scope current-build previous-finished-builds \ + --release complete incomplete \ + --on-nonallowed-failure diff --git a/.travis/cirp/cleanup4.sh b/.travis/cirp/cleanup4.sh new file mode 100755 index 000000000..de58be515 --- /dev/null +++ b/.travis/cirp/cleanup4.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh +. .travis/cirp/install.sh + +ci-release-publisher cleanup_publish +ci-release-publisher cleanup_store --scope current-build previous-finished-builds \ + --release complete incomplete diff --git a/.travis/cirp/cleanup5.sh b/.travis/cirp/cleanup5.sh new file mode 100755 index 000000000..a954ad1cd --- /dev/null +++ b/.travis/cirp/cleanup5.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh + +if [ -z "$TRAVIS_TEST_RESULT" ] && [ "$TRAVIS_TEST_RESULT" == "0" ] +then + echo "Build has not failed, skipping cleanup" + exit 0 +fi + +. .travis/cirp/install.sh + +ci-release-publisher cleanup_publish +ci-release-publisher cleanup_store --scope current-build previous-finished-builds \ + --release complete incomplete diff --git a/.travis/cirp/collect.sh b/.travis/cirp/collect.sh new file mode 100755 index 000000000..0e043a46e --- /dev/null +++ b/.travis/cirp/collect.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh + +if [ ! -z "$TRAVIS_TEST_RESULT" ] && [ "$TRAVIS_TEST_RESULT" != "0" ] +then + echo "Build has failed, skipping publishing" + exit 0 +fi + +if [ "$#" != "1" ] +then + echo "Error: No arguments provided. Please specify a directory where to download artifacts to as the first argument." + exit 1 +fi + +ARTIFACTS_DIR="$1" + +. .travis/cirp/install.sh + +ci-release-publisher collect "$ARTIFACTS_DIR" diff --git a/.travis/cirp/install.sh b/.travis/cirp/install.sh new file mode 100644 index 000000000..ae7a21991 --- /dev/null +++ b/.travis/cirp/install.sh @@ -0,0 +1,61 @@ +# Install verifying the hash + +# Get Python >=3.5 +if [ "$TRAVIS_OS_NAME" == "osx" ] +then + brew update + + # make sha256sum available + export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + + brew upgrade python || true + + python --version || true + python3 --version || true + pyenv versions || true + + cd . + cd "$(mktemp -d)" + virtualenv env -p python3 + set +u + source env/bin/activate + set -u + cd - +else + python --version || true + python3 --version || true + pyenv versions || true + + pyenv global 3.6 +fi + +pip install --upgrade pip + +check_sha256() +{ + if ! ( echo "$1 $2" | sha256sum -c --status - ) + then + echo "Error: sha256 of $2 doesn't match the known one." + echo "Expected: $1 $2" + echo -n "Got: " + sha256sum "$2" + exit 1 + else + echo "sha256 matches the expected one: $1" + fi +} + +# Don't install again if already installed. +# OSX keeps re-installing it tough, as it uses a temp per-script virtualenv. +if ! pip list --format=columns | grep '^ci-release-publisher ' +then + cd . + cd "$(mktemp -d)" + VERSION="0.1.0" + FILENAME="ci_release_publisher-$VERSION-py3-none-any.whl" + HASH="384bd9e2b0dd344381c01948e567bb26151636d6fd9b70fc58ef94aeb6be9466" + pip download ci_release_publisher==$VERSION + check_sha256 "$HASH" "$FILENAME" + pip install --no-index --find-links "$PWD" "$FILENAME" + cd - +fi diff --git a/.travis/cirp/publish.sh b/.travis/cirp/publish.sh new file mode 100755 index 000000000..72c4ae54c --- /dev/null +++ b/.travis/cirp/publish.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh + +if [ ! -z "$TRAVIS_TEST_RESULT" ] && [ "$TRAVIS_TEST_RESULT" != "0" ] +then + echo "Build has failed, skipping publishing" + exit 0 +fi + +if [ "$#" != "1" ] +then + echo "Error: No arguments provided. Please specify a directory containing artifacts as the first argument." + exit 1 +fi + +ARTIFACTS_DIR="$1" + +. .travis/cirp/check_cache.sh + +. .travis/cirp/install.sh + +ci-release-publisher publish --latest-release \ + --latest-release-prerelease \ + --numbered-release \ + --numbered-release-keep-count 3 \ + --numbered-release-prerelease \ + "$ARTIFACTS_DIR" + +. .travis/cirp/update_cache.sh diff --git a/.travis/cirp/store.sh b/.travis/cirp/store.sh new file mode 100755 index 000000000..a091b7ffc --- /dev/null +++ b/.travis/cirp/store.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -euo pipefail + +. .travis/cirp/check_precondition.sh + +if [ ! -z "$TRAVIS_TEST_RESULT" ] && [ "$TRAVIS_TEST_RESULT" != "0" ] +then + echo "Build has failed, skipping publishing" + exit 0 +fi + +if [ "$#" != "1" ] +then + echo "Error: No arguments provided. Please specify a directory containing artifacts as the first argument." + exit 1 +fi + +ARTIFACTS_DIR="$1" + +. .travis/cirp/install.sh + +ci-release-publisher store "$ARTIFACTS_DIR" diff --git a/.travis/cirp/update_cache.sh b/.travis/cirp/update_cache.sh new file mode 100644 index 000000000..60c867630 --- /dev/null +++ b/.travis/cirp/update_cache.sh @@ -0,0 +1,8 @@ +if [ ! -z "$TRAVIS_TEST_RESULT" ] && [ "$TRAVIS_TEST_RESULT" != "0" ] +then + echo "Build has failed, skipping updating the cache" + exit 0 +fi + +mkdir -p /opt/cirp +git rev-parse HEAD > /opt/cirp/previous_runs_commit