From cb4d6281684bcb617900f7550b9ab6fd669bd92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dziedziul?= Date: Fri, 12 Jul 2024 02:28:46 +0200 Subject: [PATCH] Use .github/release_type for controlling releases of the OSS/EE [5.4.z] (#205) Backport of https://github.com/hazelcast/hazelcast-packaging/pull/204 In order to control which editions (OSS/EE/ALL) should be released `.github/release_type` file is introduced. This file is required now for newly created git tags. It should contains only one of the following values: - OSS - EE - ALL When a new tag is pushed we read the file to decide which editions should be released. For manual runs of the `publish-packages.yml` we ignore this file and use `RELEASE_TYPE` input from the workflow `.github/release_type` should be added during the release by the automation. It's forbidden to add it master or maintenance branches through PRs. Fixes: https://hazelcast.atlassian.net/browse/DI-52 Also switches to using internal snapshot maven repository for getting OSS snapshot distribution tar.gz --- .env | 2 + .github/workflows/assert.sh/LICENSE | 21 ++ .github/workflows/assert.sh/assert.sh | 262 +++++++++++++++ .github/workflows/build.functions.sh | 58 ++++ .github/workflows/build.functions_tests.sh | 68 ++++ .github/workflows/publish-brew-package.yml | 121 +++++++ .github/workflows/publish-deb-package.yml | 94 ++++++ .github/workflows/publish-packages.yml | 371 ++++++--------------- .github/workflows/publish-rpm-package.yml | 102 ++++++ build-hazelcast-deb-package.sh | 34 +- build-hazelcast-homebrew-package.sh | 8 +- build-hazelcast-rpm-package.sh | 33 +- common.sh | 7 +- test_common.sh => common_tests.sh | 23 +- packages/brew/test_brew_functions.sh | 23 +- test.sh | 26 -- test_scripts.sh | 5 + 17 files changed, 886 insertions(+), 372 deletions(-) create mode 100644 .env create mode 100644 .github/workflows/assert.sh/LICENSE create mode 100644 .github/workflows/assert.sh/assert.sh create mode 100644 .github/workflows/build.functions.sh create mode 100755 .github/workflows/build.functions_tests.sh create mode 100644 .github/workflows/publish-brew-package.yml create mode 100644 .github/workflows/publish-deb-package.yml create mode 100644 .github/workflows/publish-rpm-package.yml rename test_common.sh => common_tests.sh (86%) delete mode 100755 test.sh create mode 100755 test_scripts.sh diff --git a/.env b/.env new file mode 100644 index 00000000..ff752413 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +JAVA_VERSION=21 +JAVA_DISTRIBUTION=temurin diff --git a/.github/workflows/assert.sh/LICENSE b/.github/workflows/assert.sh/LICENSE new file mode 100644 index 00000000..8e012d07 --- /dev/null +++ b/.github/workflows/assert.sh/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Márk Török + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.github/workflows/assert.sh/assert.sh b/.github/workflows/assert.sh/assert.sh new file mode 100644 index 00000000..401ea869 --- /dev/null +++ b/.github/workflows/assert.sh/assert.sh @@ -0,0 +1,262 @@ +#!/usr/bin/env bash + +##################################################################### +## +## title: Assert Extension +## +## description: +## Assert extension of shell (bash, ...) +## with the common assert functions +## Function list based on: +## http://junit.sourceforge.net/javadoc/org/junit/Assert.html +## Log methods : inspired by +## - https://natelandau.com/bash-scripting-utilities/ +## author: Mark Torok +## +## date: 07. Dec. 2016 +## +## license: MIT +## +##################################################################### + +if command -v tput &>/dev/null && tty -s; then + RED=$(tput setaf 1) + GREEN=$(tput setaf 2) + MAGENTA=$(tput setaf 5) + NORMAL=$(tput sgr0) + BOLD=$(tput bold) +else + RED=$(echo -en "\e[31m") + GREEN=$(echo -en "\e[32m") + MAGENTA=$(echo -en "\e[35m") + NORMAL=$(echo -en "\e[00m") + BOLD=$(echo -en "\e[01m") +fi + +log_header() { + printf "\n${BOLD}${MAGENTA}========== %s ==========${NORMAL}\n" "$@" >&2 +} + +log_success() { + printf "${GREEN}✔ %s${NORMAL}\n" "$@" >&2 +} + +log_failure() { + printf "${RED}✖ %s${NORMAL}\n" "$@" >&2 +} + + +assert_eq() { + local expected="$1" + local actual="$2" + local msg="${3-}" + + if [ "$expected" == "$actual" ]; then + log_success "$expected == $actual :: $msg" || true + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$expected == $actual :: $msg" || true + return 1 + fi +} + +assert_not_eq() { + local expected="$1" + local actual="$2" + local msg="${3-}" + + if [ ! "$expected" == "$actual" ]; then + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$expected != $actual :: $msg" || true + return 1 + fi +} + +assert_true() { + local actual="$1" + local msg="${2-}" + + assert_eq true "$actual" "$msg" + return "$?" +} + +assert_false() { + local actual="$1" + local msg="${2-}" + + assert_eq false "$actual" "$msg" + return "$?" +} + +assert_array_eq() { + + declare -a expected=("${!1-}") + # echo "AAE ${expected[@]}" + + declare -a actual=("${!2}") + # echo "AAE ${actual[@]}" + + local msg="${3-}" + + local return_code=0 + if [ ! "${#expected[@]}" == "${#actual[@]}" ]; then + return_code=1 + fi + + local i + for (( i=1; i < ${#expected[@]} + 1; i+=1 )); do + if [ ! "${expected[$i-1]}" == "${actual[$i-1]}" ]; then + return_code=1 + break + fi + done + + if [ "$return_code" == 1 ]; then + [ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) != (${actual[*]}) :: $msg" || true + fi + + return "$return_code" +} + +assert_array_not_eq() { + + declare -a expected=("${!1-}") + declare -a actual=("${!2}") + + local msg="${3-}" + + local return_code=1 + if [ ! "${#expected[@]}" == "${#actual[@]}" ]; then + return_code=0 + fi + + local i + for (( i=1; i < ${#expected[@]} + 1; i+=1 )); do + if [ ! "${expected[$i-1]}" == "${actual[$i-1]}" ]; then + return_code=0 + break + fi + done + + if [ "$return_code" == 1 ]; then + [ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) == (${actual[*]}) :: $msg" || true + fi + + return "$return_code" +} + +assert_empty() { + local actual=$1 + local msg="${2-}" + + assert_eq "" "$actual" "$msg" + return "$?" +} + +assert_not_empty() { + local actual=$1 + local msg="${2-}" + + assert_not_eq "" "$actual" "$msg" + return "$?" +} + +function join_by() { + local IFS="$1"; + shift; + echo "$*"; + } + +assert_contain() { + local haystack="$1" + local needle="${2-}" + local msg="${3-}" + + if [ -z "${needle:+x}" ]; then + return 0; + fi + + if [ -z "${haystack##*$needle*}" ]; then + log_success "Array [$(join_by "," $haystack)] contains $needle :: $msg" || true + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "Array [$(join_by "," $haystack)] doesn't contain $needle :: $msg" || true + return 1 + fi +} + +assert_not_contain() { + local haystack="$1" + local needle="${2-}" + local msg="${3-}" + + if [ -z "${needle:+x}" ]; then + return 0; + fi + + if [ -z "$haystack" ]; then + log_success "Array [$(join_by "," $haystack)] doesn't contain $needle :: $msg" || true + return 0; + fi + + if [ "${haystack##*$needle*}" ]; then + log_success "Array [$(join_by "," $haystack)] doesn't contain $needle :: $msg" || true + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$haystack contains $needle :: $msg" || true + return 1 + fi +} + +assert_gt() { + local first="$1" + local second="$2" + local msg="${3-}" + + if [[ "$first" -gt "$second" ]]; then + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$first > $second :: $msg" || true + return 1 + fi +} + +assert_ge() { + local first="$1" + local second="$2" + local msg="${3-}" + + if [[ "$first" -ge "$second" ]]; then + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$first >= $second :: $msg" || true + return 1 + fi +} + +assert_lt() { + local first="$1" + local second="$2" + local msg="${3-}" + + if [[ "$first" -lt "$second" ]]; then + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$first < $second :: $msg" || true + return 1 + fi +} + +assert_le() { + local first="$1" + local second="$2" + local msg="${3-}" + + if [[ "$first" -le "$second" ]]; then + return 0 + else + [ "${#msg}" -gt 0 ] && log_failure "$first <= $second :: $msg" || true + return 1 + fi +} diff --git a/.github/workflows/build.functions.sh b/.github/workflows/build.functions.sh new file mode 100644 index 00000000..16eff3d4 --- /dev/null +++ b/.github/workflows/build.functions.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -euo pipefail ${RUNNER_DEBUG:+-x} + +# Checks if we should build the OSS docker image. +# If the workflow was triggered by `pull_request` OSS artifact should be built always. +# For other workflows we should build EE only for 'ALL' and 'OSS' editions. +function should_build_oss() { + + local triggered_by=$1 + local release_type=$2 + + if [[ $triggered_by == "pull_request" || $release_type == "ALL" || $release_type == "OSS" ]]; then + echo "yes" + else + echo "no" + fi +} + +# Checks if we should build the EE docker image. +# If the workflow was triggered by `pull_request` EE artifact should be built always. +# For other workflows we should build EE only for 'All' and 'EE' editions. +function should_build_ee() { + + local triggered_by=$1 + local release_type=$2 + + if [[ $triggered_by == "pull_request" || $release_type == "ALL" || $release_type == "EE" ]]; then + echo "yes" + else + echo "no" + fi +} + +function get_hz_dist_tar_gz() { + local hz_version=$1 + local distribution=$2 + local extension=tar.gz + + if [[ $distribution == "hazelcast" ]]; then + if [[ "${hz_version}" == *"SNAPSHOT"* ]]; then + url="https://${HZ_SNAPSHOT_INTERNAL_USERNAME}:${HZ_SNAPSHOT_INTERNAL_PASSWORD}@repository.hazelcast.com/snapshot-internal/com/hazelcast/hazelcast-distribution/${hz_version}/hazelcast-distribution-${hz_version}.$extension" + else + url="https://repo1.maven.org/maven2/com/hazelcast/hazelcast-distribution/${hz_version}/hazelcast-distribution-${hz_version}.$extension" + fi + fi + + if [[ $distribution == "hazelcast-enterprise" ]]; then + local repository + if [[ "${hz_version}" == *"SNAPSHOT"* ]]; then + repository=snapshot + else + repository=release + fi + url="https://repository.hazelcast.com/${repository}/com/hazelcast/hazelcast-enterprise-distribution/${hz_version}/hazelcast-enterprise-distribution-${hz_version}.$extension" + fi + echo "$url" +} diff --git a/.github/workflows/build.functions_tests.sh b/.github/workflows/build.functions_tests.sh new file mode 100755 index 00000000..357e0dae --- /dev/null +++ b/.github/workflows/build.functions_tests.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +set -eu +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" + +. "$SCRIPT_DIR"/assert.sh/assert.sh +. "$SCRIPT_DIR"/build.functions.sh + +TESTS_RESULT=0 + +function assert_should_build_oss { + local triggered_by=$1 + local release_type=$2 + local expected_should_build_os=$3 + local actual=$(should_build_oss "$triggered_by" "$release_type") + assert_eq "$expected_should_build_os" "$actual" "For triggered_by=$triggered_by release_type=$release_type \ +we should$( [ "$expected_should_build_os" = "no" ] && echo " NOT") build OS" || TESTS_RESULT=$? +} + +log_header "Tests for should_build_oss" +assert_should_build_oss "push" "ALL" "yes" +assert_should_build_oss "push" "OSS" "yes" +assert_should_build_oss "push" "EE" "no" +assert_should_build_oss "workflow_dispatch" "ALL" "yes" +assert_should_build_oss "workflow_dispatch" "OSS" "yes" +assert_should_build_oss "workflow_dispatch" "EE" "no" +assert_should_build_oss "pull_request" "ALL" "yes" +assert_should_build_oss "pull_request" "OSS" "yes" +assert_should_build_oss "pull_request" "EE" "yes" + +function assert_should_build_ee { + local triggered_by=$1 + local release_type=$2 + local expected_should_build_ee=$3 + local actual=$(should_build_ee "$triggered_by" "$release_type") + assert_eq "$expected_should_build_ee" "$actual" "For triggered_by=$triggered_by release_type=$release_type \ +we should$( [ "$expected_should_build_ee" = "no" ] && echo " NOT") build EE" || TESTS_RESULT=$? +} + +log_header "Tests for should_build_ee" +assert_should_build_ee "push" "ALL" "yes" +assert_should_build_ee "push" "OSS" "no" +assert_should_build_ee "push" "EE" "yes" +assert_should_build_ee "workflow_dispatch" "ALL" "yes" +assert_should_build_ee "workflow_dispatch" "OSS" "no" +assert_should_build_ee "workflow_dispatch" "EE" "yes" +assert_should_build_ee "pull_request" "ALL" "yes" +assert_should_build_ee "pull_request" "OSS" "yes" +assert_should_build_ee "pull_request" "EE" "yes" + +function assert_get_hz_dist_tar_gz { + local hz_version=$1 + local distribution=$2 + local expected_url=$3 + local actual_url=$(get_hz_dist_tar_gz "$hz_version" "$distribution") + assert_eq "$expected_url" "$actual_url" "Expected URL for version \"$hz_version\", distribution \"$distribution\"" || TESTS_RESULT=$? +} + +log_header "Tests for get_hz_dist_tar_gz" +export HZ_SNAPSHOT_INTERNAL_USERNAME=dummy_user +export HZ_SNAPSHOT_INTERNAL_PASSWORD=dummy_password +assert_get_hz_dist_tar_gz 5.4.0 hazelcast https://repo1.maven.org/maven2/com/hazelcast/hazelcast-distribution/5.4.0/hazelcast-distribution-5.4.0.tar.gz +assert_get_hz_dist_tar_gz 5.5.0-SNAPSHOT hazelcast https://dummy_user:dummy_password@repository.hazelcast.com/snapshot-internal/com/hazelcast/hazelcast-distribution/5.5.0-SNAPSHOT/hazelcast-distribution-5.5.0-SNAPSHOT.tar.gz + +assert_get_hz_dist_tar_gz 5.4.0 hazelcast-enterprise https://repository.hazelcast.com/release/com/hazelcast/hazelcast-enterprise-distribution/5.4.0/hazelcast-enterprise-distribution-5.4.0.tar.gz +assert_get_hz_dist_tar_gz 5.5.0-SNAPSHOT hazelcast-enterprise https://repository.hazelcast.com/snapshot/com/hazelcast/hazelcast-enterprise-distribution/5.5.0-SNAPSHOT/hazelcast-enterprise-distribution-5.5.0-SNAPSHOT.tar.gz + +assert_eq 0 "$TESTS_RESULT" "ALL tests should pass" diff --git a/.github/workflows/publish-brew-package.yml b/.github/workflows/publish-brew-package.yml new file mode 100644 index 00000000..2c07a15e --- /dev/null +++ b/.github/workflows/publish-brew-package.yml @@ -0,0 +1,121 @@ +name: Publish BREW package + +on: + workflow_call: + inputs: + HZ_VERSION: + description: 'Version of Hazelcast to build the image for, this is the Maven version - e.g.: 5.0.2 or 5.1-SNAPSHOT' + required: true + type: string + HZ_DISTRIBUTION: + description: 'Distribution to be built: hazelcast or hazelcast-enterprise' + required: true + type: string + USE_TEST_REPO: + description: 'Use test repo for publishing' + required: true + type: string + PACKAGE_VERSION: + description: 'Version of the package e.g. 5.1.1, 5.1.1-1, defaults to HZ_VERSION' + type: string + +concurrency: + group: 'brew-${{ github.job }}-${{ inputs.HZ_VERSION }}-${{ inputs.HZ_DISTRIBUTION}}' + +jobs: + homebrew: + runs-on: macos-latest + env: + HZ_VERSION: ${{ inputs.HZ_VERSION }} + PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION || inputs.HZ_VERSION }} + HZ_DISTRIBUTION: ${{ inputs.HZ_DISTRIBUTION }} + USE_TEST_REPO: ${{ inputs.USE_TEST_REPO }} + steps: + - name: Checkout hazelcast-packaging repo + uses: actions/checkout@v4 + + - name: Load env vars from .env file + run: cat .env >> $GITHUB_ENV + + - name: Install up-to-date tools + run: | + brew install gnu-sed + brew install coreutils + + PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH" + sed --version + PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH" + sha256sum --version + echo "PATH=$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH" >> $GITHUB_ENV + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Download the distribution tar.gz file + run: | + . .github/workflows/build.functions.sh + export HZ_SNAPSHOT_INTERNAL_PASSWORD=${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }} + export HZ_SNAPSHOT_INTERNAL_USERNAME=${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }} + DISTRIBUTION_URL=$(get_hz_dist_tar_gz "${HZ_VERSION}" "${HZ_DISTRIBUTION}") + if [[ "DISTRIBUTION_URL" == *"$HZ_SNAPSHOT_INTERNAL_PASSWORD"* ]]; then + echo "Trying to expose a password-protected url of the distribution file, aborting!"; + exit 1; + fi + curl --fail --silent --show-error --location "$DISTRIBUTION_URL" --output distribution.tar.gz + echo "HZ_PACKAGE_URL=$DISTRIBUTION_URL" >> $GITHUB_ENV + + - name: Get homebrew repository + run: | + source ./common.sh + echo "BREW_GIT_REPO_NAME=${BREW_GIT_REPO_NAME}" >> $GITHUB_ENV + + - name: Checkout homebrew-hz repo + uses: actions/checkout@v4 + with: + repository: ${{ env.BREW_GIT_REPO_NAME }} + ref: master + token: ${{ secrets.DEVOPS_SECRET }} + path: 'homebrew-hz' + + - name: Change the artifact in homebrew-hz + run: | + ./build-hazelcast-homebrew-package.sh + + - name: Commit changes & Push to homebrew-hz repo + run: | + source common.sh + + cd homebrew-hz + git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + git add *.rb + if [[ `git status --porcelain --untracked-files=no` ]]; then + git commit -am "Hazelcast Homebrew Package ${{ env.PACKAGE_VERSION }} release" + git pull --rebase + git push + else + echo "No changes, this is probably a re-run." + fi + + - name: Install Hazelcast from Homebrew + run: | + source ./common.sh + brew tap ${BREW_TAP_NAME} + brew install ${{ env.HZ_DISTRIBUTION}}@$BREW_PACKAGE_VERSION + + - name: Run Hazelcast + env: + HZ_LICENSEKEY: ${{ secrets.HZ_LICENSEKEY }} + run: HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & + + - name: Check Hazelcast health + run: | + ./check-hazelcast-health.sh + + - name: Uninstall Hazelcast from homebrew + run: | + source ./common.sh + brew uninstall ${{ env.HZ_DISTRIBUTION}}@$BREW_PACKAGE_VERSION diff --git a/.github/workflows/publish-deb-package.yml b/.github/workflows/publish-deb-package.yml new file mode 100644 index 00000000..29b69f6c --- /dev/null +++ b/.github/workflows/publish-deb-package.yml @@ -0,0 +1,94 @@ +name: Publish DEB package + +on: + workflow_call: + inputs: + HZ_VERSION: + description: 'Version of Hazelcast to build the image for, this is the Maven version - e.g.: 5.0.2 or 5.1-SNAPSHOT' + required: true + type: string + HZ_DISTRIBUTION: + description: 'Distribution to be built: hazelcast or hazelcast-enterprise' + required: true + type: string + USE_TEST_REPO: + description: 'Use test repo for publishing' + required: true + type: string + PACKAGE_VERSION: + description: 'Version of the package e.g. 5.1.1, 5.1.1-1, defaults to HZ_VERSION' + type: string + +env: + JFROG_TOKEN: ${{ secrets.JFROG_TOKEN }} + +concurrency: + group: 'deb-${{ github.job }}-${{ inputs.HZ_VERSION }}-${{ inputs.HZ_DISTRIBUTION}}' + +jobs: + deb: + runs-on: ubuntu-latest + env: + HZ_VERSION: ${{ inputs.HZ_VERSION }} + PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION || inputs.HZ_VERSION }} + HZ_DISTRIBUTION: ${{ inputs.HZ_DISTRIBUTION }} + USE_TEST_REPO: ${{ inputs.USE_TEST_REPO }} + + steps: + - name: Checkout hazelcast-packaging repo + uses: actions/checkout@v4 + + - name: Load env vars from .env file + run: cat .env >> $GITHUB_ENV + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Download the distribution tar.gz file + run: | + . .github/workflows/build.functions.sh + export HZ_SNAPSHOT_INTERNAL_PASSWORD=${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }} + export HZ_SNAPSHOT_INTERNAL_USERNAME=${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }} + DISTRIBUTION_URL=$(get_hz_dist_tar_gz "${HZ_VERSION}" "${HZ_DISTRIBUTION}") + curl --fail --silent --show-error --location "$DISTRIBUTION_URL" --output distribution.tar.gz + + - name: Create & Upload DEB package + run: | + ./build-hazelcast-deb-package.sh + + - name: Calculate Debian Repository Metadata + run: | + source common.sh + + curl --fail-with-body --retry 3 --retry-delay 10 -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \ + -X POST "https://repository.hazelcast.com/api/deb/reindex/${DEBIAN_REPO}" + + - name: Install Hazelcast from deb + env: + HZ_LICENSEKEY: ${{ secrets.HZ_LICENSEKEY }} + run: | + source ./common.sh + wget -qO - https://repository.hazelcast.com/api/gpg/key/public | gpg --dearmor | sudo tee /usr/share/keyrings/hazelcast-archive-keyring.gpg > /dev/null + echo "deb [signed-by=/usr/share/keyrings/hazelcast-archive-keyring.gpg] ${DEBIAN_REPO_BASE_URL} ${PACKAGE_REPO} main" | sudo tee -a /etc/apt/sources.list + sudo apt update && sudo apt install ${{ env.HZ_DISTRIBUTION}}=${HZ_VERSION} + HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & + + - name: Check Hazelcast health + run: | + ./check-hazelcast-health.sh + + - name: Uninstall Hazelcast from deb + run: | + source ./common.sh + sudo apt remove ${{ env.HZ_DISTRIBUTION}} + + - name: Remove deb package from test repo + if: env.USE_TEST_REPO == 'true' + run: | + source ./common.sh + curl -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \ + -X DELETE \ + "$DEBIAN_REPO_BASE_URL/${HZ_DISTRIBUTION}-${DEB_PACKAGE_VERSION}-all.deb" diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml index 8191dda6..6bb0d41a 100644 --- a/.github/workflows/publish-packages.yml +++ b/.github/workflows/publish-packages.yml @@ -2,12 +2,8 @@ name: Publish Hazelcast OS & EE packages on: push: - # Push to master updates the latest snapshot (HZ_VERSION taken from pom.xml) branches: - master - # Push of a matching tag (v*, e.g. v5.0.2) starts build with - # - HZ_VERSION extracted from pom.xml - # - PACKAGE_VERSION extracted from the tag tags: - 'v*' pull_request: @@ -15,7 +11,7 @@ on: workflow_dispatch: inputs: HZ_VERSION: - description: 'Version of Hazelcast to build the image for, this is the Maven version - e.g.: 5.0.2 or 5.1-SNAPSHOT' + description: 'Version of Hazelcast to build the packages from, this is the Maven version - e.g.: 5.0.2 or 5.1-SNAPSHOT' required: true PACKAGE_TYPES: description: 'Packages to build' @@ -27,37 +23,48 @@ on: - deb - rpm - homebrew + RELEASE_TYPE: + description: 'Which editions should be built' + required: true + default: 'EE' + type: choice + options: + - ALL + - OSS + - EE env: EVENT_NAME: ${{ github.event_name }} - PUBLISH: "true" - JFROG_TOKEN: ${{ secrets.JFROG_TOKEN }} - DEVOPS_PRIVATE_KEY: ${{ secrets.DEVOPS_PRIVATE_KEY }} - BINTRAY_PASSPHRASE: ${{ secrets.BINTRAY_PASSPHRASE }} - HZ_LICENSEKEY: ${{ secrets.HZ_LICENSEKEY }} - JAVA_VERSION: "21" - JAVA_DISTRIBUTION: "temurin" + RELEASE_TYPE_FILE: .github/release_type -# Constant for now - should ensure single build, maybe we can limit this to something from github.* -concurrency: single-build +concurrency: + group: '${{ github.workflow }}-${{ github.base_ref || github.ref_name}}' jobs: prepare: runs-on: ubuntu-latest env: + RELEASE_TYPE: ${{ inputs.RELEASE_TYPE || 'EE' }} + PACKAGE_TYPES: ${{ inputs.PACKAGE_TYPES || 'all' }} HZ_VERSION: ${{ github.event.inputs.HZ_VERSION }} - defaults: - run: - working-directory: ./hazelcast-packaging outputs: - hz_version: ${{ steps.hz_version.outputs.hz_version }} - package_version: ${{ steps.package_version.outputs.package_version }} - package_types: ${{ github.event.inputs.package_types || 'all' }} + hz_version: ${{ steps.hz_version_step.outputs.hz_version }} + should_build_oss: ${{ steps.which_editions.outputs.should_build_oss }} + should_build_ee: ${{ steps.which_editions.outputs.should_build_ee }} + should_build_deb: ${{ env.PACKAGE_TYPES == 'all' || env.PACKAGE_TYPES == 'deb' }} + should_build_rpm: ${{ env.PACKAGE_TYPES == 'all' || env.PACKAGE_TYPES == 'rpm' }} + should_build_homebrew: ${{ env.PACKAGE_TYPES == 'all' || env.PACKAGE_TYPES == 'homebrew' }} + use_test_repo: ${{ env.EVENT_NAME == 'pull_request' }} steps: - name: Checkout hazelcast-packaging repo uses: actions/checkout@v4 - with: - path: 'hazelcast-packaging' + + - name: Load env vars from .env file + run: cat .env >> $GITHUB_ENV + + - name: Test scripts + run: | + ./test_scripts.sh - name: Setup JDK uses: actions/setup-java@v4 @@ -66,264 +73,94 @@ jobs: distribution: ${{ env.JAVA_DISTRIBUTION }} - name: Set HZ_VERSION - id: hz_version + id: hz_version_step run: | if [ -z "${{ env.HZ_VERSION }}" ]; then HZ_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) fi - echo "HZ_VERSION=$HZ_VERSION" >> $GITHUB_ENV echo "hz_version=$HZ_VERSION" >> $GITHUB_OUTPUT - - name: Set PACKAGE_VERSION - id: package_version - # If the ref is version (e.g. v5.0.1) tag then use it as package version, - # otherwise use HZ_VERSION for package version (e.g 5.1-SNAPSHOT) - run: | - if [[ "${{ github.ref }}" == "refs/tags/v"* ]]; then - PACKAGE_VERSION=$(echo ${{ github.ref }} | cut -c 12-) - else - PACKAGE_VERSION=${{ env.HZ_VERSION }} - fi - echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV - echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT - - deb: - runs-on: ubuntu-latest - if: ${{ needs.prepare.outputs.package_types == 'all' || needs.prepare.outputs.package_types == 'deb' }} - strategy: - fail-fast: false - matrix: - distribution: [ 'hazelcast', 'hazelcast-enterprise' ] - env: - HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} - PACKAGE_VERSION: ${{ needs.prepare.outputs.package_version }} - HZ_DISTRIBUTION: ${{ matrix.distribution }} - defaults: - run: - working-directory: ./hazelcast-packaging - needs: [prepare] - steps: - - name: Checkout hazelcast-packaging repo - uses: actions/checkout@v4 - with: - path: 'hazelcast-packaging' - - - name: Setup JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DISTRIBUTION }} - - - name: Download the distribution tar.gz file - run: | - HZ_PACKAGE_URL=$(mvn --batch-mode dependency:copy -Dartifact=com.hazelcast:${HZ_DISTRIBUTION}-distribution:${HZ_VERSION}:tar.gz -DoutputDirectory=./ -Dmdep.useBaseVersion=true | grep 'Downloaded from' | grep -Eo "https://[^ >]+${HZ_DISTRIBUTION}-distribution-.*.tar.gz") - echo "HZ_PACKAGE_URL=$HZ_PACKAGE_URL" >> $GITHUB_ENV - - - name: Create & Upload DEB package - run: | - ./build-hazelcast-deb-package.sh - - - name: Calculate Debian Repository Metadata - run: | - source common.sh - - curl --fail-with-body --retry 3 --retry-delay 10 -H "Authorization: Bearer ${{ secrets.JFROG_TOKEN }}" \ - -X POST "https://repository.hazelcast.com/api/deb/reindex/${DEBIAN_REPO}" - - - name: Install Hazelcast from deb - run: | - source ./common.sh - wget -qO - https://repository.hazelcast.com/api/gpg/key/public | gpg --dearmor | sudo tee /usr/share/keyrings/hazelcast-archive-keyring.gpg > /dev/null - echo "deb [signed-by=/usr/share/keyrings/hazelcast-archive-keyring.gpg] ${DEBIAN_REPO_BASE_URL} ${PACKAGE_REPO} main" | sudo tee -a /etc/apt/sources.list - sudo apt update && sudo apt install ${{ env.HZ_DISTRIBUTION}}=${HZ_VERSION} - HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & - - - name: Check Hazelcast health - run: | - ./check-hazelcast-health.sh - - - name: Uninstall Hazelcast from deb - run: | - source ./common.sh - sudo apt remove ${{ env.HZ_DISTRIBUTION}} - - - name: Remove deb package from test repo + - name: Forbid ${{ env.RELEASE_TYPE_FILE }} file in the PRs if: github.event_name == 'pull_request' run: | - source ./common.sh - curl -H "Authorization: Bearer ${{ secrets.JFROG_TOKEN }}" \ - -X DELETE \ - "$DEBIAN_REPO_BASE_URL/${HZ_DISTRIBUTION}-${DEB_PACKAGE_VERSION}-all.deb" - - rpm: - runs-on: ubuntu-latest - if: ${{ needs.prepare.outputs.package_types == 'all' || needs.prepare.outputs.package_types == 'rpm' }} - container: rockylinux:9 - strategy: - fail-fast: false - matrix: - distribution: [ 'hazelcast', 'hazelcast-enterprise' ] - env: - HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} - PACKAGE_VERSION: ${{ needs.prepare.outputs.package_version }} - HZ_DISTRIBUTION: ${{ matrix.distribution }} - defaults: - run: - working-directory: ./hazelcast-packaging - needs: [prepare] - steps: - - name: Checkout hazelcast-packaging repo - uses: actions/checkout@v4 - with: - path: 'hazelcast-packaging' - - - name: Setup JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DISTRIBUTION }} - - - name: Install Required tools - run: | - yum install -y maven rpm-sign rpm-build wget gettext systemd-rpm-macros - - - name: Download the distribution tar.gz file - run: | - HZ_PACKAGE_URL=$(mvn --batch-mode dependency:copy -Dartifact=com.hazelcast:${HZ_DISTRIBUTION}-distribution:${HZ_VERSION}:tar.gz -DoutputDirectory=./ -Dmdep.useBaseVersion=true | grep 'Downloaded from' | grep -Eo "https://[^ >]+${HZ_DISTRIBUTION}-distribution-.*.tar.gz") - echo "HZ_PACKAGE_URL=$HZ_PACKAGE_URL" >> $GITHUB_ENV - - - name: Create & Sign & Upload RPM package - run: | - ./build-hazelcast-rpm-package.sh - - - name: Calculate YUM Repository Metadata - run: | - pwd - ls -lah - source ./common.sh - - curl --fail-with-body --retry 3 --retry-delay 10 -H "Authorization: Bearer ${{ secrets.JFROG_TOKEN }}" \ - -X POST "https://repository.hazelcast.com/api/yum/${RPM_REPO}" - - - name: Install Hazelcast from rpm - run: | - source ./common.sh - wget ${RPM_REPO_BASE_URL}/${PACKAGE_REPO}/hazelcast-rpm-${PACKAGE_REPO}.repo -O hazelcast-rpm-${PACKAGE_REPO}.repo - mv hazelcast-rpm-${PACKAGE_REPO}.repo /etc/yum.repos.d/ - yum install -y ${{ env.HZ_DISTRIBUTION}}-${RPM_HZ_VERSION} - HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & - - - name: Check Hazelcast health - run: | - ./check-hazelcast-health.sh - - - name: Uninstall Hazelcast from rpm - run: | - source ./common.sh - yum remove -y ${{ env.HZ_DISTRIBUTION}}-${RPM_PACKAGE_VERSION} - - - name: Remove rpm package from test repo - if: github.event_name == 'pull_request' - run: | - source ./common.sh - curl -H "Authorization: Bearer ${{ secrets.JFROG_TOKEN }}" \ - -X DELETE \ - "$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" - - homebrew: - runs-on: macos-latest - if: ${{ needs.prepare.outputs.package_types == 'all' || needs.prepare.outputs.package_types == 'homebrew' }} - strategy: - fail-fast: false - matrix: - distribution: [ 'hazelcast', 'hazelcast-enterprise' ] - env: - HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} - PACKAGE_VERSION: ${{ needs.prepare.outputs.package_version }} - HZ_DISTRIBUTION: ${{ matrix.distribution }} - defaults: - run: - working-directory: ./hazelcast-packaging - needs: [prepare] - steps: - - name: Checkout hazelcast-packaging repo - uses: actions/checkout@v4 - with: - path: 'hazelcast-packaging' - - - name: Install up-to-date tools - run: | - brew install gnu-sed - brew install coreutils - - PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" - sed --version - PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" - sha256sum --version - echo "PATH=/usr/local/opt/coreutils/libexec/gnubin:/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" >> $GITHUB_ENV - - - name: Run script tests - run: | - ./test.sh - - - name: Setup JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DISTRIBUTION }} - - - name: Download the distribution tar.gz file - run: | - HZ_PACKAGE_URL=$(mvn --batch-mode dependency:copy -Dartifact=com.hazelcast:${HZ_DISTRIBUTION}-distribution:${HZ_VERSION}:tar.gz -DoutputDirectory=./ -Dmdep.useBaseVersion=true | grep 'Downloaded from' | grep -Eo "https://[^ >]+${HZ_DISTRIBUTION}-distribution-.*.tar.gz") - echo "HZ_PACKAGE_URL=$HZ_PACKAGE_URL" >> $GITHUB_ENV - - - name: Get homebrew repository - run: | - source ./common.sh - echo "BREW_GIT_REPO_NAME=${BREW_GIT_REPO_NAME}" >> $GITHUB_ENV - - - name: Checkout homebrew-hz repo - uses: actions/checkout@v4 - with: - repository: ${{ env.BREW_GIT_REPO_NAME }} - ref: master - token: ${{ secrets.DEVOPS_SECRET }} - path: 'homebrew-hz' - - - name: Change the artifact in homebrew-hz - run: | - ./build-hazelcast-homebrew-package.sh - - - name: Commit changes & Push to homebrew-hz repo - run: | - source common.sh + if [ -f "${{ env.RELEASE_TYPE_FILE }}" ]; then + echo "Error: ${{ env.RELEASE_TYPE_FILE }} file is not allowed in the PRs. It's used only during release creation" + exit 1 + fi - cd ../homebrew-hz - git config --global user.name 'devOpsHazelcast' - git config --global user.email 'devops@hazelcast.com' - git add *.rb - if [[ `git status --porcelain --untracked-files=no` ]]; then - git commit -am "Hazelcast Homebrew Package ${{ env.PACKAGE_VERSION }} release" - git pull --rebase - git push + - name: Read release type from the file + run: | + if [ -f ${{ env.RELEASE_TYPE_FILE }} ]; then + echo "RELEASE_TYPE=$(cat ${{ env.RELEASE_TYPE_FILE }})" >> $GITHUB_ENV else - echo "No changes, this is probably a re-run." + echo "File '${{ env.RELEASE_TYPE_FILE }}' does not exist." fi - - name: Install Hazelcast from Homebrew + - name: Check which editions should be built + id: which_editions run: | - source ./common.sh - brew tap ${BREW_TAP_NAME} - brew install ${{ env.HZ_DISTRIBUTION}}@$BREW_PACKAGE_VERSION + . .github/workflows/build.functions.sh + + release_type=${{ env.RELEASE_TYPE }} + triggered_by=${{ github.event_name }} + should_build_oss=$(should_build_oss "$triggered_by" "$release_type") + should_build_ee=$(should_build_ee "$triggered_by" "$release_type") + echo "should_build_ee=${should_build_ee}" >> $GITHUB_OUTPUT + echo "should_build_oss=${should_build_oss}" >> $GITHUB_OUTPUT - - name: Run Hazelcast - run: HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & + deb-ee: + if: needs.prepare.outputs.should_build_deb == 'true' && needs.prepare.outputs.should_build_ee == 'yes' + needs: [prepare] + uses: ./.github/workflows/publish-deb-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast-enterprise + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} + deb-oss: + needs: [ prepare ] + if: needs.prepare.outputs.should_build_deb == 'true' && needs.prepare.outputs.should_build_oss == 'yes' + uses: ./.github/workflows/publish-deb-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} - - name: Check Hazelcast health - run: | - ./check-hazelcast-health.sh + rpm-ee: + if: needs.prepare.outputs.should_build_rpm == 'true' && needs.prepare.outputs.should_build_ee == 'yes' + needs: [prepare] + uses: ./.github/workflows/publish-rpm-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast-enterprise + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} + rpm-oss: + needs: [ prepare ] + if: needs.prepare.outputs.should_build_rpm == 'true' && needs.prepare.outputs.should_build_oss == 'yes' + uses: ./.github/workflows/publish-rpm-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} - - name: Uninstall Hazelcast from homebrew - run: | - source ./common.sh - brew uninstall ${{ env.HZ_DISTRIBUTION}}@$BREW_PACKAGE_VERSION + brew-ee: + if: needs.prepare.outputs.should_build_homebrew == 'true' && needs.prepare.outputs.should_build_ee == 'yes' + needs: [prepare] + uses: ./.github/workflows/publish-brew-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast-enterprise + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} + brew-oss: + needs: [ prepare ] + if: needs.prepare.outputs.should_build_homebrew == 'true' && needs.prepare.outputs.should_build_oss == 'yes' && !contains(needs.prepare.outputs.hz_version, 'SNAPSHOT') + uses: ./.github/workflows/publish-brew-package.yml + secrets: inherit + with: + HZ_VERSION: ${{ needs.prepare.outputs.hz_version }} + HZ_DISTRIBUTION: hazelcast + USE_TEST_REPO: ${{ needs.prepare.outputs.use_test_repo }} diff --git a/.github/workflows/publish-rpm-package.yml b/.github/workflows/publish-rpm-package.yml new file mode 100644 index 00000000..710bc963 --- /dev/null +++ b/.github/workflows/publish-rpm-package.yml @@ -0,0 +1,102 @@ +name: Publish DEB package + +on: + workflow_call: + inputs: + HZ_VERSION: + description: 'Version of Hazelcast to build the image for, this is the Maven version - e.g.: 5.0.2 or 5.1-SNAPSHOT' + required: true + type: string + HZ_DISTRIBUTION: + description: 'Distribution to be built: hazelcast or hazelcast-enterprise' + required: true + type: string + USE_TEST_REPO: + description: 'Use test repo for publishing' + required: true + type: string + PACKAGE_VERSION: + description: 'Version of the package e.g. 5.1.1, 5.1.1-1, defaults to HZ_VERSION' + type: string + +env: + JFROG_TOKEN: ${{ secrets.JFROG_TOKEN }} + DEVOPS_PRIVATE_KEY: ${{ secrets.DEVOPS_PRIVATE_KEY }} + BINTRAY_PASSPHRASE: ${{ secrets.BINTRAY_PASSPHRASE }} + +concurrency: + group: 'rpm-${{ github.job }}-${{ inputs.HZ_VERSION }}-${{ inputs.HZ_DISTRIBUTION}}' + +jobs: + rpm: + runs-on: ubuntu-latest + container: rockylinux:9 + env: + HZ_VERSION: ${{ inputs.HZ_VERSION }} + PACKAGE_VERSION: ${{ inputs.PACKAGE_VERSION || inputs.HZ_VERSION }} + HZ_DISTRIBUTION: ${{ inputs.HZ_DISTRIBUTION }} + USE_TEST_REPO: ${{ inputs.USE_TEST_REPO }} + steps: + - name: Checkout hazelcast-packaging repo + uses: actions/checkout@v4 + + - name: Load env vars from .env file + run: cat .env >> $GITHUB_ENV + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Install Required tools + run: | + yum install -y maven rpm-sign rpm-build wget gettext systemd-rpm-macros + + - name: Download the distribution tar.gz file + run: | + . .github/workflows/build.functions.sh + export HZ_SNAPSHOT_INTERNAL_PASSWORD=${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }} + export HZ_SNAPSHOT_INTERNAL_USERNAME=${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }} + DISTRIBUTION_URL=$(get_hz_dist_tar_gz "${HZ_VERSION}" "${HZ_DISTRIBUTION}") + curl --fail --silent --show-error --location "$DISTRIBUTION_URL" --output distribution.tar.gz + + - name: Create & Sign & Upload RPM package + run: | + ./build-hazelcast-rpm-package.sh + + - name: Calculate YUM Repository Metadata + run: | + pwd + ls -lah + source ./common.sh + + curl --fail-with-body --retry 3 --retry-delay 10 -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \ + -X POST "https://repository.hazelcast.com/api/yum/${RPM_REPO}" + + - name: Install Hazelcast from rpm + env: + HZ_LICENSEKEY: ${{ secrets.HZ_LICENSEKEY }} + run: | + source ./common.sh + wget ${RPM_REPO_BASE_URL}/${PACKAGE_REPO}/hazelcast-rpm-${PACKAGE_REPO}.repo -O hazelcast-rpm-${PACKAGE_REPO}.repo + mv hazelcast-rpm-${PACKAGE_REPO}.repo /etc/yum.repos.d/ + yum install -y ${{ env.HZ_DISTRIBUTION}}-${RPM_HZ_VERSION} + HAZELCAST_CONFIG="$(pwd)/config/integration-test-hazelcast.yaml" hz-start > hz.log 2>&1 & + + - name: Check Hazelcast health + run: | + ./check-hazelcast-health.sh + + - name: Uninstall Hazelcast from rpm + run: | + source ./common.sh + yum remove -y ${{ env.HZ_DISTRIBUTION}}-${RPM_PACKAGE_VERSION} + + - name: Remove rpm package from test repo + if: env.USE_TEST_REPO == 'true' + run: | + source ./common.sh + curl -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \ + -X DELETE \ + "$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" diff --git a/build-hazelcast-deb-package.sh b/build-hazelcast-deb-package.sh index e42e635a..0039ab8d 100755 --- a/build-hazelcast-deb-package.sh +++ b/build-hazelcast-deb-package.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -x +set -euo pipefail ${RUNNER_DEBUG:+-x} if [ -z "${HZ_DISTRIBUTION}" ]; then echo "Variable HZ_DISTRIBUTION is not set. It must be set to 'hazelcast' for OS, 'hazelcast-enterprise' for EE" @@ -17,7 +17,7 @@ if [ -z "${PACKAGE_VERSION}" ]; then exit 1 fi -export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz +export HZ_DISTRIBUTION_FILE=distribution.tar.gz if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory." @@ -61,22 +61,24 @@ dpkg-deb --build build/deb/hazelcast DEB_FILE=${HZ_DISTRIBUTION}-${DEB_PACKAGE_VERSION}-all.deb mv build/deb/hazelcast.deb "$DEB_FILE" -if [ "${PUBLISH}" == "true" ]; then - echo "Publishing $DEB_FILE to jfrog" +echo "Publishing $DEB_FILE to jfrog" - DEB_SHA256SUM=$(sha256sum $DEB_FILE | cut -d ' ' -f 1) - DEB_SHA1SUM=$(sha1sum $DEB_FILE | cut -d ' ' -f 1) - DEB_MD5SUM=$(md5sum $DEB_FILE | cut -d ' ' -f 1) +DEB_SHA256SUM=$(sha256sum $DEB_FILE | cut -d ' ' -f 1) +DEB_SHA1SUM=$(sha1sum $DEB_FILE | cut -d ' ' -f 1) +DEB_MD5SUM=$(md5sum $DEB_FILE | cut -d ' ' -f 1) +PACKAGE_URL="$DEBIAN_REPO_BASE_URL/${DEB_FILE}" +HTTP_STATUS=$(curl -o /dev/null --silent --head --write-out '%{http_code}' -H "Authorization: Bearer ${JFROG_TOKEN}" "$PACKAGE_URL") + +if [ "$HTTP_STATUS" -eq 200 ]; then # Delete any package that exists - previous version of the same package - curl -H "Authorization: Bearer ${JFROG_TOKEN}" \ + curl --fail-with-body -H "Authorization: Bearer ${JFROG_TOKEN}" \ -X DELETE \ - "$DEBIAN_REPO_BASE_URL/${DEB_FILE}" - - curl -H "Authorization: Bearer ${JFROG_TOKEN}" -H "X-Checksum-Deploy: false" -H "X-Checksum-Sha256: $DEB_SHA256SUM" \ - -H "X-Checksum-Sha1: $DEB_SHA1SUM" -H "X-Checksum-MD5: $DEB_MD5SUM" \ - -T"$DEB_FILE" \ - -X PUT \ - "$DEBIAN_REPO_BASE_URL/$DEB_FILE;deb.distribution=${PACKAGE_REPO};deb.component=main;deb.component=${HZ_MINOR_VERSION};deb.architecture=all" - + "$PACKAGE_URL" fi + +curl --fail-with-body -H "Authorization: Bearer ${JFROG_TOKEN}" -H "X-Checksum-Deploy: false" -H "X-Checksum-Sha256: $DEB_SHA256SUM" \ + -H "X-Checksum-Sha1: $DEB_SHA1SUM" -H "X-Checksum-MD5: $DEB_MD5SUM" \ + -T"$DEB_FILE" \ + -X PUT \ + "$PACKAGE_URL;deb.distribution=${PACKAGE_REPO};deb.component=main;deb.component=${HZ_MINOR_VERSION};deb.architecture=all" diff --git a/build-hazelcast-homebrew-package.sh b/build-hazelcast-homebrew-package.sh index 1b055ab8..6cf8b6d0 100755 --- a/build-hazelcast-homebrew-package.sh +++ b/build-hazelcast-homebrew-package.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -x +set -euo pipefail ${RUNNER_DEBUG:+-x} if [ -z "${HZ_DISTRIBUTION}" ]; then echo "Variable HZ_DISTRIBUTION is not set. It must be set to 'hazelcast' for OS, 'hazelcast-enterprise' for EE" @@ -17,7 +17,7 @@ if [ -z "${PACKAGE_VERSION}" ]; then exit 1 fi -export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz +export HZ_DISTRIBUTION_FILE=distribution.tar.gz if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory." @@ -40,7 +40,7 @@ echo "Building Homebrew package $HZ_DISTRIBUTION:${HZ_VERSION} package version $ ASSET_SHASUM=$(sha256sum "${HZ_DISTRIBUTION_FILE}" | cut -d ' ' -f 1) TEMPLATE_FILE="$(pwd)/packages/brew/hazelcast-template.rb" -cd ../homebrew-hz || exit 1 +cd homebrew-hz || exit 1 function updateClassName { class=$1 @@ -91,7 +91,7 @@ if [[ "$RELEASE_TYPE" = "stable" ]]; then fi else # Update 'hazelcast-snapshot/beta/dr' - # only if the version is greater than (new release) or equal to highest version + # only if the version is greater than (new release) or equal to the highest version UPDATE_LATEST="true" versions=("${HZ_DISTRIBUTION}"-[0-9]*\.rb) for version in "${versions[@]}" diff --git a/build-hazelcast-rpm-package.sh b/build-hazelcast-rpm-package.sh index ec6719e1..9e37bae7 100755 --- a/build-hazelcast-rpm-package.sh +++ b/build-hazelcast-rpm-package.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -x +set -euo pipefail ${RUNNER_DEBUG:+-x} source common.sh @@ -19,7 +19,7 @@ if [ -z "${PACKAGE_VERSION}" ]; then exit 1 fi -export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz +export HZ_DISTRIBUTION_FILE=distribution.tar.gz if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory." @@ -63,20 +63,23 @@ rpmbuild --define "_topdir $(realpath build/rpmbuild)" -bb build/rpmbuild/rpm/ha rpm --define "_gpg_name deploy@hazelcast.com" --addsign build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm -if [ "${PUBLISH}" == "true" ]; then - RPM_SHA256SUM=$(sha256sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) - RPM_SHA1SUM=$(sha1sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) - RPM_MD5SUM=$(md5sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) +RPM_SHA256SUM=$(sha256sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) +RPM_SHA1SUM=$(sha1sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) +RPM_MD5SUM=$(md5sum "build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" | cut -d ' ' -f 1) - # Delete any package that exists - previous version of the same package - curl -H "Authorization: Bearer ${JFROG_TOKEN}" \ - -X DELETE \ - "$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" - curl -H "Authorization: Bearer ${JFROG_TOKEN}" -H "X-Checksum-Deploy: false" -H "X-Checksum-Sha256: $RPM_SHA256SUM" \ - -H "X-Checksum-Sha1: $RPM_SHA1SUM" -H "X-Checksum-MD5: $RPM_MD5SUM" \ - -T"build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" \ - -X PUT \ - "$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" +PACKAGE_URL="$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" +HTTP_STATUS=$(curl -o /dev/null --silent --head --write-out '%{http_code}' -H "Authorization: Bearer ${JFROG_TOKEN}" "$PACKAGE_URL") +if [ "$HTTP_STATUS" -eq 200 ]; then + # Delete any package that exists - previous version of the same package + curl --fail-with-body -H "Authorization: Bearer ${JFROG_TOKEN}" \ + -X DELETE \ + "$PACKAGE_URL" fi + +curl --fail-with-body -H "Authorization: Bearer ${JFROG_TOKEN}" -H "X-Checksum-Deploy: false" -H "X-Checksum-Sha256: $RPM_SHA256SUM" \ + -H "X-Checksum-Sha1: $RPM_SHA1SUM" -H "X-Checksum-MD5: $RPM_MD5SUM" \ + -T"build/rpmbuild/RPMS/noarch/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm" \ + -X PUT \ + "$PACKAGE_URL" diff --git a/common.sh b/common.sh index c1b7b199..add9e6d4 100755 --- a/common.sh +++ b/common.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [ -z "${USE_TEST_REPO}" ]; then + echo "Variable USE_TEST_REPO is not set." + exit 1 +fi + export RELEASE_TYPE=stable if [[ "$HZ_VERSION" == *"SNAPSHOT"* ]]; then export RELEASE_TYPE=snapshot @@ -53,7 +58,7 @@ export RPM_PACKAGE_VERSION BREW_PACKAGE_VERSION=$(echo $PACKAGE_VERSION | tr '[:upper:]' '[:lower:]' | sed -r -r 's/(-)/\./g') export BREW_PACKAGE_VERSION -if [ "${EVENT_NAME}" == "pull_request" ]; then +if [ "${USE_TEST_REPO}" == "true" ]; then # PRs publish to test repositories and install the packages from there export DEBIAN_REPO=debian-test-local export DEBIAN_REPO_BASE_URL="https://repository.hazelcast.com/${DEBIAN_REPO}" diff --git a/test_common.sh b/common_tests.sh similarity index 86% rename from test_common.sh rename to common_tests.sh index 1c9af8de..997f9d1a 100755 --- a/test_common.sh +++ b/common_tests.sh @@ -1,27 +1,8 @@ #!/usr/bin/env bash -function findScriptDir() { - CURRENT=$PWD +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" - DIR=$(dirname "$0") - cd "$DIR" || exit - TARGET_FILE=$(basename "$0") - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ] - do - TARGET_FILE=$(readlink "$TARGET_FILE") - DIR=$(dirname "$TARGET_FILE") - cd "$DIR" || exit - TARGET_FILE=$(basename "$TARGET_FILE") - done - - SCRIPT_DIR=$(pwd -P) - # Restore current directory - cd "$CURRENT" || exit -} - -findScriptDir +export USE_TEST_REPO=true . "$SCRIPT_DIR"/packages/tests-common/assert.sh/assert.sh . "$SCRIPT_DIR"/common.sh diff --git a/packages/brew/test_brew_functions.sh b/packages/brew/test_brew_functions.sh index d470625b..131a4dd8 100755 --- a/packages/brew/test_brew_functions.sh +++ b/packages/brew/test_brew_functions.sh @@ -1,27 +1,6 @@ #!/usr/bin/env bash -function findScriptDir() { - CURRENT=$PWD - - DIR=$(dirname "$0") - cd "$DIR" || exit - TARGET_FILE=$(basename "$0") - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ] - do - TARGET_FILE=$(readlink "$TARGET_FILE") - DIR=$(dirname "$TARGET_FILE") - cd "$DIR" || exit - TARGET_FILE=$(basename "$TARGET_FILE") - done - - SCRIPT_DIR=$(pwd -P) - # Restore current directory - cd "$CURRENT" || exit -} - -findScriptDir +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" . "$SCRIPT_DIR"/../tests-common/assert.sh/assert.sh . "$SCRIPT_DIR"/functions.sh diff --git a/test.sh b/test.sh deleted file mode 100755 index 6345eb25..00000000 --- a/test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -function findScriptDir() { - CURRENT=$PWD - - DIR=$(dirname "$0") - cd "$DIR" || exit - TARGET_FILE=$(basename "$0") - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ] - do - TARGET_FILE=$(readlink "$TARGET_FILE") - DIR=$(dirname "$TARGET_FILE") - cd "$DIR" || exit - TARGET_FILE=$(basename "$TARGET_FILE") - done - - SCRIPT_DIR=$(pwd -P) - # Restore current directory - cd "$CURRENT" || exit -} - -findScriptDir - -find "$SCRIPT_DIR" -name "test_*.sh" -print0 | xargs -0 -n1 bash diff --git a/test_scripts.sh b/test_scripts.sh new file mode 100755 index 00000000..deb6bf23 --- /dev/null +++ b/test_scripts.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" + +find "$SCRIPT_DIR" -name "*_tests.sh" -print0 | xargs -0 -n1 bash