Skip to content

Commit

Permalink
Merge branch 'master' into DI-171---Migrate-workflows-to-use-assert.s…
Browse files Browse the repository at this point in the history
…h-from-a-single-repository
  • Loading branch information
JackPGreen authored Aug 1, 2024
2 parents 8547cd0 + bd417d0 commit 51b127e
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 20 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,36 @@ function should_build_ee() {
fi
}

function get_hz_dist_tar_gz() {
local hz_version=$1
local distribution=$2
local extension=tar.gz
local url

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
elif [[ "$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"
}

function url_contains_password() {
local url=$1
local password=$2
if [[ "$url" == *"$password"* ]]; then
echo "yes"
else
echo "no"
fi
}
28 changes: 28 additions & 0 deletions .github/workflows/build.functions_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,32 @@ 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:[email protected]/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

function assert_url_contains_password {
local url=$1
local password=$2
local expected_result=$3
local actual=$(url_contains_password "$url" "$password")
assert_eq "$expected_result" "$actual" "Url '$url' should$( [ "$expected_result" = "no" ] && echo " NOT") contain $password" || TESTS_RESULT=$?
}

assert_url_contains_password "https://dummy_user:[email protected]/snapshot-internal/com/hazelcast/hazelcast-distribution/5.5.0-SNAPSHOT/hazelcast-distribution-5.5.0-SNAPSHOT.tar.gz" "dummy_password" "yes"
assert_url_contains_password "https://repo1.maven.org/maven2/com/hazelcast/hazelcast-distribution/5.4.0/hazelcast-distribution-5.4.0.tar.gz" "dummy_password" "no"

assert_eq 0 "$TESTS_RESULT" "ALL tests should pass"
21 changes: 18 additions & 3 deletions .github/workflows/publish-brew-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ jobs:
distribution: ${{ env.JAVA_DISTRIBUTION }}

- name: Download the distribution tar.gz file
env:
HZ_SNAPSHOT_INTERNAL_PASSWORD: ${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }}
HZ_SNAPSHOT_INTERNAL_USERNAME: ${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }}
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
. .github/workflows/build.functions.sh
DISTRIBUTION_URL=$(get_hz_dist_tar_gz "${HZ_VERSION}" "${HZ_DISTRIBUTION}")
if [[ "$(url_contains_password "$DISTRIBUTION_URL" "$HZ_SNAPSHOT_INTERNAL_PASSWORD")" == "yes" ]]; 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: |
Expand Down Expand Up @@ -112,3 +120,10 @@ jobs:
run: |
source ./common.sh
brew uninstall ${{ env.HZ_DISTRIBUTION}}@$BREW_PACKAGE_VERSION
- name: Store logs as artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: brew-${{ env.HZ_DISTRIBUTION}}-hz.log
path: hz.log
15 changes: 13 additions & 2 deletions .github/workflows/publish-deb-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ jobs:
distribution: ${{ env.JAVA_DISTRIBUTION }}

- name: Download the distribution tar.gz file
env:
HZ_SNAPSHOT_INTERNAL_PASSWORD: ${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }}
HZ_SNAPSHOT_INTERNAL_USERNAME: ${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }}
run: |
mvn --batch-mode dependency:copy -Dartifact=com.hazelcast:${HZ_DISTRIBUTION}-distribution:${HZ_VERSION}:tar.gz \
-DoutputDirectory=./ -Dmdep.useBaseVersion=true
. .github/workflows/build.functions.sh
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: |
Expand Down Expand Up @@ -89,3 +93,10 @@ jobs:
curl -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \
-X DELETE \
"$DEBIAN_REPO_BASE_URL/${HZ_DISTRIBUTION}-${DEB_PACKAGE_VERSION}-all.deb"
- name: Store logs as artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: deb-${{ env.HZ_DISTRIBUTION}}-hz.log
path: hz.log
2 changes: 1 addition & 1 deletion .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
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'
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:
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/publish-rpm-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ jobs:
yum install -y maven rpm-sign rpm-build wget gettext systemd-rpm-macros
- name: Download the distribution tar.gz file
env:
HZ_SNAPSHOT_INTERNAL_PASSWORD: ${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }}
HZ_SNAPSHOT_INTERNAL_USERNAME: ${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }}
run: |
mvn --batch-mode dependency:copy -Dartifact=com.hazelcast:${HZ_DISTRIBUTION}-distribution:${HZ_VERSION}:tar.gz \
-DoutputDirectory=./ -Dmdep.useBaseVersion=true
. .github/workflows/build.functions.sh
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: |
Expand Down Expand Up @@ -97,3 +101,10 @@ jobs:
curl -H "Authorization: Bearer ${{ env.JFROG_TOKEN }}" \
-X DELETE \
"$RPM_REPO_BASE_URL/${PACKAGE_REPO}/${HZ_DISTRIBUTION}-${RPM_PACKAGE_VERSION}.noarch.rpm"
- name: Store logs as artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: rpm-${{ env.HZ_DISTRIBUTION}}-hz.log
path: hz.log
3 changes: 1 addition & 2 deletions build-hazelcast-deb-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ if [ -z "${PACKAGE_VERSION}" ]; then
exit 1
fi

export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz
source common.sh

if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then
echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory."
exit 1;
fi

source common.sh

echo "Building DEB package $HZ_DISTRIBUTION:${HZ_VERSION} package version ${DEB_PACKAGE_VERSION}"

Expand Down
11 changes: 5 additions & 6 deletions build-hazelcast-homebrew-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ if [ -z "${PACKAGE_VERSION}" ]; then
exit 1
fi

export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz

if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then
echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory."
exit 1;
fi

# With Homebrew we actually don't upload the artifact anywhere, but use the base tar.gz artifact url.
# The package manager then downloads it from there.
Expand All @@ -35,6 +29,11 @@ fi
source common.sh
source packages/brew/brew_functions.sh

if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then
echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory."
exit 1;
fi

echo "Building Homebrew package $HZ_DISTRIBUTION:${HZ_VERSION} package version ${PACKAGE_VERSION}"

ASSET_SHASUM=$(sha256sum "${HZ_DISTRIBUTION_FILE}" | cut -d ' ' -f 1)
Expand Down
4 changes: 1 addition & 3 deletions build-hazelcast-rpm-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ if [ -z "${PACKAGE_VERSION}" ]; then
exit 1
fi

export HZ_DISTRIBUTION_FILE=${HZ_DISTRIBUTION}-distribution-${HZ_VERSION}.tar.gz
source common.sh

if [ ! -f "${HZ_DISTRIBUTION_FILE}" ]; then
echo "File ${HZ_DISTRIBUTION_FILE} doesn't exits in current directory."
exit 1;
fi

source common.sh

echo "Building RPM package $HZ_DISTRIBUTION:${HZ_VERSION} package version ${RPM_PACKAGE_VERSION}"

# Remove previous build, useful on local
Expand Down
2 changes: 2 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ else
export BREW_GIT_REPO_NAME="hazelcast/homebrew-hz"
export BREW_TAP_NAME="hazelcast/hz"
fi

export HZ_DISTRIBUTION_FILE=distribution.tar.gz
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-packaging</artifactId>
<version>5.5.0-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>

<description>A pom.xml file with repository definitions so we can use maven to fetch tar artifacts.</description>

Expand Down

0 comments on commit 51b127e

Please sign in to comment.