Skip to content
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

fix(ci): handle concurrent hotfix and release #1191

Merged
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
35 changes: 33 additions & 2 deletions .github/actions/delivery/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ inputs:
stability:
description: "The package stability (stable, testing, unstable)"
required: true
release_type:
description: "Type of release (hotfix, release)"
required: true
release_cloud:
description: "Release context (cloud or not cloud)"
required: true

runs:
using: "composite"
Expand Down Expand Up @@ -49,6 +55,8 @@ runs:
- if: ${{ env.extfile == 'rpm' }}
name: Publish RPMs
run: |
set -eux

FILES="*.${{ env.extfile }}"

echo "[DEBUG] - Version: ${{ inputs.version }}"
Expand All @@ -64,8 +72,17 @@ runs:
exit 1
fi

# DEBUG
echo "[DEBUG] - Version: ${{ inputs.version }}"
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
echo "[DEBUG] - module_name: ${{ inputs.module_name }}"
echo "[DEBUG] - release_cloud: ${{ inputs.release_cloud }}"
echo "[DEBUG] - release_type: ${{ inputs.release_type }}"

# Create ARCH dirs
mkdir noarch x86_64

# Get ARCH target for files to deliver and regroupe them by ARCH
for FILE in $FILES; do
echo "[DEBUG] - File: $FILE"

Expand All @@ -76,13 +93,27 @@ runs:
mv "$FILE" "$ARCH"
done

# Build upload target path based on release_cloud and release_type values
# if cloud, deliver to testing-<release_type>
# if non-cloud, delivery to testing as usual
if [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "hotfix" ]] || [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "release" ]]; then
ROOT_REPO_PATH="rpm-standard-internal"
UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}-${{ inputs.release_type }}/$ARCH/RPMS/${{ inputs.module_name }}/"
elif [[ ${{ inputs.release_cloud }} -eq 0 ]]; then
ROOT_REPO_PATH="rpm-standard"
UPLOAD_REPO_PATH="${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/RPMS/${{ inputs.module_name }}/"
else
echo "Invalid combination of release_type and release_cloud"
fi

# Deliver based on inputs
for ROOT_REPO_PATH in "rpm-standard" "rpm-standard-internal"; do
for ARCH in "noarch" "x86_64"; do
if [ "$(ls -A $ARCH)" ]; then
if [ "${{ inputs.stability }}" == "stable" ]; then
jf rt upload "$ARCH/*.rpm" "$ROOT_REPO_PATH/${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/RPMS/${{ inputs.module_name }}/" --flat
echo "[DEBUG] - Stability is ${{ inputs.stability }}, not delivering."
else
jf rt upload "$ARCH/*.rpm" "$ROOT_REPO_PATH/${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" --sync-deletes="$ROOT_REPO_PATH/${{ inputs.version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" --flat
jf rt upload "$ARCH/*.rpm" "$ROOT_REPO_PATH/$UPLOAD_REPO_PATH" --flat
fi
fi
done
Expand Down
36 changes: 33 additions & 3 deletions .github/actions/promote-to-stable/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ inputs:
github_base_ref:
description: "Release base ref"
required: true
release_type:
description: "Type of release (hotfix, release)"
required: true
release_cloud:
description: "Release context (cloud or not cloud)"
required: true

runs:
using: "composite"
Expand All @@ -37,10 +43,14 @@ runs:
- name: Promote RPM packages to stable
if: ${{ startsWith(inputs.distrib, 'el') }}
run: |
set -x
set -eux

# DEBUG
echo "[DEBUG] - Major version: ${{ inputs.major_version }}"
echo "[DEBUG] - Minor version: ${{ inputs.minor_version }}"
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
echo "[DEBUG] - release_cloud: ${{ inputs.release_cloud }}"
echo "[DEBUG] - release_type: ${{ inputs.release_type }}"

# Cloud specific promote
# delivery by default to onprem, override to internal if base branch is master
Expand All @@ -50,9 +60,21 @@ runs:
ROOT_REPO_PATH="rpm-standard"
fi

# Build search path based on release_cloud and release_type values
# if cloud, search in testing-<release_type> path
# if non-cloud, search in the testing usual path
if [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "hotfix" ]] || [[ ${{ inputs.release_cloud }} -eq 1 && ${{ inputs.release_type }} == "release" ]];then
SEARCH_REPO_PATH="${{ inputs.major_version }}/${{ inputs.distrib }}/testing-${{ inputs.release_type }}/$ARCH/${{ inputs.module_name }}"
elif [[ ${{ inputs.release_cloud }} -eq 0 ]];then
SEARCH_REPO_PATH="${{ inputs.major_version }}/${{ inputs.distrib }}/testing/$ARCH/${{ inputs.module_name }}"
else
echo "Invalid combination of release_type and release_cloud"
fi

# Search for testing packages candidate for promote
for ARCH in "noarch" "x86_64"; do
echo "[DEBUG] - Get artifactory path of $ARCH testing artifacts to promote to stable."
SRC_PATHS=$(jf rt s --include-dirs $ROOT_REPO_PATH/${{ inputs.major_version }}/${{ inputs.distrib }}/testing/$ARCH/${{ inputs.module_name }}/*.rpm | jq -r '.[].path')
SRC_PATHS=$(jf rt search --include-dirs $ROOT_REPO_PATH/$SEARCH_REPO_PATH/*.rpm | jq -r '.[].path')
if [[ ${SRC_PATHS[@]} ]]; then
for SRC_PATH in ${SRC_PATHS[@]}; do
echo "[DEBUG] - Source path found: $SRC_PATH"
Expand All @@ -61,18 +83,26 @@ runs:
echo "[DEBUG] - No source path found."
continue
fi

# Build target path based on ARCH
echo "[DEBUG] - Build $ARCH artifactory target path."
TARGET_PATH="$ROOT_REPO_PATH/${{ inputs.major_version }}/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/RPMS/${{ inputs.module_name }}/"
echo "[DEBUG] - Target path: $TARGET_PATH"

# Download candidates for promote
echo "[DEBUG] - Promoting $ARCH testing artifacts to stable."
for ARTIFACT in ${SRC_PATHS[@]}; do
echo "[DEBUG] - Downloading $ARTIFACT from TESTING."
jf rt download $ARTIFACT --flat
done

# Upload previously downloaded candidates to TARGET_PATH
for ARTIFACT_DL in $(dir|grep -E "*.rpm"); do
echo "[DEBUG] - Promoting (upload) $ARTIFACT_DL to stable $TARGET_PATH."
jf rt upload "$ARTIFACT_DL" "$TARGET_PATH" --flat
done

# Cleanup before next round of candidates
rm -f *.rpm
done
shell: bash
Expand All @@ -85,7 +115,7 @@ runs:
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"

echo "[DEBUG] - Get path of testing DEB packages to promote to stable."
SRC_PATHS=$(jf rt s --include-dirs apt-standard-${{ inputs.major_version }}-testing/pool/${{ inputs.module_name }}/*.deb | jq -r '.[].path')
SRC_PATHS=$(jf rt s --include-dirs apt-standard-${{ inputs.major_version }}-testing/pool/${{ inputs.module_name }}/${{ inputs.release_type }}/*.deb | jq -r '.[].path')

if [[ ${SRC_PATHS[@]} ]]; then
for SRC_PATH in ${SRC_PATHS[@]}; do
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/centreon-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-rpm-centreon-collect-${{ matrix.distrib }}-${{ matrix.arch }}-${{ github.head_ref || github.ref_name }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}

deliver-deb:
if: ${{ contains(fromJson('["testing", "stable"]'), needs.get-version.outputs.stability) }}
Expand Down Expand Up @@ -178,6 +180,8 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-deb-centreon-collect-${{ matrix.distrib }}-${{ matrix.arch }}-${{ github.head_ref || github.ref_name }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}

promote:
needs: [get-version]
Expand All @@ -202,3 +206,5 @@ jobs:
stability: ${{ needs.get-version.outputs.stability }}
repository_name: standard
github_base_ref: ${{ github.base_ref }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}
35 changes: 32 additions & 3 deletions .github/workflows/get-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ on:
environment:
description: "branch stability (stable, testing, unstable, canary)"
value: ${{ jobs.get-version.outputs.environment }}
release_type:
description: "type of release (hotfix, release)"
value: ${{ jobs.get-version.outputs.release_type }}
release_cloud:
description: "context of release (cloud or not cloud)"
value: ${{ jobs.get-version.outputs.release_cloud }}

jobs:
get-version:
Expand All @@ -34,6 +40,8 @@ jobs:
release: ${{ steps.get_version.outputs.release }}
stability: ${{ steps.get_version.outputs.stability }}
environment: ${{ steps.get_version.outputs.env }}
release_type: ${{ steps.get_version.outputs.release_type }}
release_cloud: ${{ steps.get_version.outputs.release_cloud}}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -55,6 +63,7 @@ jobs:

- id: get_version
run: |
set -x
IMG_VERSION=$( cat `ls .github/docker/Dockerfile.centreon-collect-* | grep -v test` vcpkg.json | md5sum | awk '{print substr($1, 0, 8)}')
TEST_IMG_VERSION=$(cat .github/docker/Dockerfile.centreon-collect-*-test .github/scripts/collect-prepare-test-robot.sh resources/*.sql | md5sum | cut -c1-8)
VERSION=$(awk '$1 ~ "COLLECT_MAJOR" {maj=substr($2, 1, length($2)-1)} $1 ~ "COLLECT_MINOR" {min=substr($2, 1, length($2)-1) ; print maj "." min}' CMakeLists.txt)
Expand All @@ -70,21 +79,41 @@ jobs:
BRANCHNAME="$GITHUB_HEAD_REF"
fi

echo "BRANCHNAME is: $BRANCHNAME"

# Set default release values
GITHUB_RELEASE_CLOUD=0
GITHUB_RELEASE_TYPE=$(echo $BRANCHNAME |cut -d '-' -f 1)

case "$BRANCHNAME" in
master | [2-9][0-9].[0-9][0-9].x)
echo "release=1" >> $GITHUB_OUTPUT
;;
release* | hotfix*)
# Handle workflow_dispatch run triggers
# Handle workflow_dispatch run triggers and run a dispatch ONLY for cloud release
GITHUB_RELEASE_BRANCH_BASE_REF_NAME="$(gh pr view $BRANCHNAME -q .baseRefName --json headRefName,baseRefName,state)"
echo "GITHUB_RELEASE_BRANCH_BASE_REF_NAME is: $GITHUB_RELEASE_BRANCH_BASE_REF_NAME"
GITHUB_RELEASE_BRANCH_PR_STATE="$(gh pr view $BRANCHNAME -q .state --json headRefName,baseRefName,state)"
echo "GITHUB_RELEASE_BRANCH_PR_STATE is: $GITHUB_RELEASE_BRANCH_PR_STATE"

# Check if the release context (cloud and hotfix or cloud and release)
if [[ "$GITHUB_RELEASE_BRANCH_BASE_REF_NAME" == "master" ]] && [[ "$GITHUB_RELEASE_BRANCH_PR_STATE" == "OPEN" ]]; then
# This case is specific to cloud release
echo "release=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT
# Get release pull request ID
GITHUB_RELEASE_BRANCH_PR_NUMBER="$(gh pr view $BRANCHNAME -q .[] --json number)"
# Set release cloud to 1 (0=not-cloud, 1=cloud)
GITHUB_RELEASE_CLOUD=1
# Debug
echo "GITHUB_RELEASE_TYPE is: $GITHUB_RELEASE_TYPE"
echo "GITHUB_RELEASE_BRANCH_PR_NUMBER is: $GITHUB_RELEASE_BRANCH_PR_NUMBER"
echo "GITHUB_RELEASE_CLOUD is: $GITHUB_RELEASE_CLOUD"
# Github ouputs
echo "release=`echo $GITHUB_RELEASE_BRANCH_PR_NUMBER`.`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT
echo "release_type=$GITHUB_RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "release_cloud=$GITHUB_RELEASE_CLOUD" >> $GITHUB_OUTPUT
else
echo "release=1" >> $GITHUB_OUTPUT
echo "release_cloud=$GITHUB_RELEASE_CLOUD" >> $GITHUB_OUTPUT
echo "release_type=$GITHUB_RELEASE_TYPE" >> $GITHUB_OUTPUT
fi
;;
*)
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/libzmq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-rpm-libzmq-${{ matrix.distrib }}-${{ matrix.arch }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}

deliver-deb:
if: ${{ contains(fromJson('["testing", "unstable"]'), needs.get-version.outputs.stability) }}
Expand Down Expand Up @@ -197,6 +199,8 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-deb-libzmq-${{ matrix.distrib }}-${{ matrix.arch }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}

promote:
needs: [get-version]
Expand All @@ -221,3 +225,5 @@ jobs:
stability: ${{ needs.get-version.outputs.stability }}
repository_name: standard
github_base_ref: ${{ github.base_ref }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}
4 changes: 4 additions & 0 deletions .github/workflows/robot-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-rpm-centreon-collect-${{ matrix.distrib }}-amd64-${{ github.head_ref || github.ref_name }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}

deliver-deb:
if: ${{ contains(fromJson('["unstable"]'), needs.get-version.outputs.stability) }}
Expand Down Expand Up @@ -171,3 +173,5 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
cache_key: ${{ github.run_id }}-${{ github.sha }}-deb-centreon-collect-${{ matrix.distrib }}-${{ matrix.arch }}-${{ github.head_ref || github.ref_name }}
stability: ${{ needs.get-version.outputs.stability }}
release_type: ${{ needs.get-version.outputs.release_type }}
release_cloud: ${{ needs.get-version.outputs.release_cloud }}