Skip to content

Reuse PR build workflows across branches #956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/get-supported-jdks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Get supported JDKs
description: Get supported JDKs
inputs:
HZ_VERSION:
description: HZ Version
required: true
outputs:
jdks:
value: ${{ steps.get-supported-jdks.outputs.jdks }}
description: Returns supported JDKs
runs:
using: "composite"
steps:
- shell: bash
id: get-supported-jdks
run: |
. .github/scripts/version.functions.sh
HZ_VERSION="${{ inputs.HZ_VERSION }}"
if version_less_than "$HZ_VERSION" "5.4.0"; then
echo "jdks=['11', '17']" >> $GITHUB_OUTPUT
else
echo "jdks=['17', '21']" >> $GITHUB_OUTPUT
fi
4 changes: 4 additions & 0 deletions .github/scripts/version.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function version_less_or_equal() {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}

function version_less_than() {
[ "$1" != "$2" ] && version_less_or_equal "$1" "$2"
}

function get_tags_descending() {
git tag -l "v*" | sort -V -r | grep -v '-'
}
Expand Down
228 changes: 228 additions & 0 deletions .github/workflows/_reusable-build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
name: Build PR

on:
workflow_call:

env:
test_container_name_oss: hazelcast-oss-test
test_container_name_ee: hazelcast-ee-test
docker_log_file_oss: docker-hazelcast-oss-test.log
docker_log_file_ee: docker-hazelcast-ee-test.log

jobs:
prepare:
runs-on: ubuntu-latest
name: Prepare environment
outputs:
HZ_VERSION_OSS: ${{ steps.get_oss_vars.outputs.HZ_VERSION_OSS }}
HZ_VERSION_EE: ${{ steps.get_ee_vars.outputs.HZ_VERSION_EE }}
LAST_RELEASED_HZ_VERSION_OSS: ${{ steps.get_oss_vars.outputs.LAST_RELEASED_HZ_VERSION_OSS }}
HAZELCAST_EE_ZIP_URL: ${{ steps.get_ee_vars.outputs.HAZELCAST_EE_ZIP_URL }}
jdks: ${{ steps.jdks.outputs.jdks }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Forbid .github/release_type file
run: |
if [ -f ".github/release_type" ]; then
echo "Error: .github/release_type file is not allowed in the PRs. It's used only during release creation"
exit 1
fi

- name: Test scripts
# TODO change to refs/heads/master just before the merge
if: github.base_ref == 'refs/heads/reusable-build-pr'
run: |
.github/scripts/test_scripts.sh

- name: Setup OSS variables
id: get_oss_vars
run: |
HZ_VERSION_OSS=$(awk -F '=' '/^ARG HZ_VERSION=/ {print $2}' hazelcast-oss/Dockerfile)
echo "HZ_VERSION_OSS=$HZ_VERSION_OSS" >> $GITHUB_OUTPUT

source hazelcast-oss/maven.functions.sh
LAST_RELEASED_HZ_VERSION_OSS="$(get_latest_version com.hazelcast hazelcast-distribution https://repo1.maven.org/maven2)";
echo "LAST_RELEASED_HZ_VERSION_OSS=$LAST_RELEASED_HZ_VERSION_OSS" >> $GITHUB_OUTPUT

- name: Setup EE variables
id: get_ee_vars
run: |
HZ_VERSION_EE=$(awk -F '=' '/^ARG HZ_VERSION=/ {print $2}' hazelcast-enterprise/Dockerfile)
. .github/scripts/ee-build.functions.sh
echo "HZ_VERSION_EE=$HZ_VERSION_EE" >> $GITHUB_OUTPUT
echo "HAZELCAST_EE_ZIP_URL=$(get_hz_dist_zip "" ${HZ_VERSION_EE})" >> $GITHUB_OUTPUT

- name: Get supported JDKs
id: jdks
uses: ./.github/actions/get-supported-jdks
with:
HZ_VERSION: '${{ steps.get_ee_vars.outputs.HZ_VERSION_EE }}'

build-pr:
runs-on: ubuntu-latest
name: Build with default JDK
needs: [ prepare ]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
fetch-depth: 0

- name: Set up Docker
uses: docker/setup-buildx-action@v3

- name: Build OSS image
run: |
DOCKER_PATH=hazelcast-oss
HZ_VERSION="${{ needs.prepare.outputs.HZ_VERSION_OSS }}"

# duplicated block as GH doesn't support passing sensitive data between jobs
. .github/scripts/oss-build.functions.sh
export HZ_SNAPSHOT_INTERNAL_PASSWORD=${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }}
export HZ_SNAPSHOT_INTERNAL_USERNAME=${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }}
HAZELCAST_OSS_ZIP_URL=$(get_hz_dist_zip "" "${HZ_VERSION}")

curl --fail --silent --show-error --location "$HAZELCAST_OSS_ZIP_URL" --output $DOCKER_PATH/hazelcast-distribution.zip;

docker buildx build --load \
--build-arg HZ_VERSION=${HZ_VERSION} \
--tag hazelcast-oss:test \
"${DOCKER_PATH}"

- name: Run smoke test against OSS image
timeout-minutes: 2
run: |
. .github/scripts/docker.functions.sh
.github/scripts/simple-smoke-test.sh hazelcast-oss:test "${{ env.test_container_name_oss }}" oss "${{ needs.prepare.outputs.HZ_VERSION_OSS }}" "$(get_default_jdk hazelcast-oss)"

- name: Build Test EE image
run: |
DOCKER_PATH=hazelcast-enterprise
HZ_VERSION="${{ needs.prepare.outputs.HZ_VERSION_EE }}"
curl --fail --silent --show-error --location "${{ needs.prepare.outputs.HAZELCAST_EE_ZIP_URL }}" --output $DOCKER_PATH/hazelcast-enterprise-distribution.zip;

docker buildx build --load \
--build-arg HZ_VERSION=${HZ_VERSION} \
--tag hazelcast-ee:test \
"${DOCKER_PATH}"

- name: Run smoke test against EE image
timeout-minutes: 2
run: |
. .github/scripts/docker.functions.sh
export HZ_LICENSEKEY=${{ secrets.HZ_ENTERPRISE_LICENSE }}
.github/scripts/simple-smoke-test.sh hazelcast-ee:test "${{ env.test_container_name_ee }}" ee "${{ needs.prepare.outputs.HZ_VERSION_EE }}" "$(get_default_jdk hazelcast-enterprise)"

- name: Get docker logs
if: ${{ always() }}
run: |
docker logs "${{ env.test_container_name_oss }}" > "${{ env.docker_log_file_oss }}"
docker logs "${{ env.test_container_name_ee }}" > "${{ env.docker_log_file_ee }}"

- name: Store docker logs as artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: docker-logs-${{ github.job }}
path: |
${{ env.docker_log_file_oss }}
${{ env.docker_log_file_ee }}

build-pr-custom-jdk:
runs-on: ubuntu-latest
needs: [ prepare ]
name: Build with jdk-${{ matrix.jdk }}
strategy:
fail-fast: false
matrix:
jdk: ${{ fromJSON(needs.prepare.outputs.jdks) }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
fetch-depth: 0

- name: Set up Docker
uses: docker/setup-buildx-action@v3

- name: Build OSS image
run: |
DOCKER_PATH=hazelcast-oss
HZ_VERSION="${{ needs.prepare.outputs.HZ_VERSION_OSS }}"

# duplicated block as GH doesn't support passing sensitive data between jobs
. .github/scripts/oss-build.functions.sh
export HZ_SNAPSHOT_INTERNAL_PASSWORD=${{ secrets.HZ_SNAPSHOT_INTERNAL_PASSWORD }}
export HZ_SNAPSHOT_INTERNAL_USERNAME=${{ secrets.HZ_SNAPSHOT_INTERNAL_USERNAME }}
HAZELCAST_OSS_ZIP_URL=$(get_hz_dist_zip "" "${HZ_VERSION}")

curl --fail --silent --show-error --location "$HAZELCAST_OSS_ZIP_URL" --output $DOCKER_PATH/hazelcast-distribution.zip;

docker buildx build --load \
--build-arg JDK_VERSION=${{ matrix.jdk }} \
--build-arg HZ_VERSION=${HZ_VERSION} \
--tag hazelcast-oss:test \
"${DOCKER_PATH}"

- name: Run smoke test against OSS image
timeout-minutes: 2
run: |
.github/scripts/simple-smoke-test.sh hazelcast-oss:test "${{ env.test_container_name_oss }}" oss "${{ needs.prepare.outputs.HZ_VERSION_OSS }}" "${{ matrix.jdk }}"

- name: Build Test EE image
run: |
DOCKER_PATH=hazelcast-enterprise
HZ_VERSION="${{ needs.prepare.outputs.HZ_VERSION_EE }}"
curl --fail --silent --show-error --location "${{ needs.prepare.outputs.HAZELCAST_EE_ZIP_URL }}" --output $DOCKER_PATH/hazelcast-enterprise-distribution.zip;

docker buildx build --load \
--build-arg JDK_VERSION=${{ matrix.jdk }} \
--build-arg HZ_VERSION=${HZ_VERSION} \
--tag hazelcast-ee:test \
"${DOCKER_PATH}"

- name: Run smoke test against EE image
timeout-minutes: 2
run: |
export HZ_LICENSEKEY=${{ secrets.HZ_ENTERPRISE_LICENSE }}
.github/scripts/simple-smoke-test.sh hazelcast-ee:test "${{ env.test_container_name_ee }}" ee "${{ needs.prepare.outputs.HZ_VERSION_EE }}" "${{ matrix.jdk }}"

- name: Get docker logs
if: ${{ always() }}
run: |
docker logs "${{ env.test_container_name_oss }}" > "${{ env.docker_log_file_oss }}"
docker logs "${{ env.test_container_name_ee }}" > "${{ env.docker_log_file_ee }}"

- name: Store docker logs as artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: docker-logs-${{ github.job }}-jdk${{ matrix.jdk }}
path: |
${{ env.docker_log_file_oss }}
${{ env.docker_log_file_ee }}

test-push:
name: Test pushing image (dry run)
needs: [ prepare ]
uses: ./.github/workflows/tag_image_push.yml
with:
HZ_VERSION: ${{ needs.prepare.outputs.LAST_RELEASED_HZ_VERSION_OSS }}
RELEASE_TYPE: ALL
DRY_RUN: true
secrets: inherit

test-push-rhel:
name: Test pushing RHEL image (dry run)
needs: [ prepare ]
uses: ./.github/workflows/tag_image_push_rhel.yml
with:
HZ_VERSION: ${{ needs.prepare.outputs.LAST_RELEASED_HZ_VERSION_OSS }}
DRY_RUN: true
secrets: inherit
Loading