diff --git a/.github/actions/delivery/action.yml b/.github/actions/delivery/action.yml index c49c92126a9..c17ad3868be 100644 --- a/.github/actions/delivery/action.yml +++ b/.github/actions/delivery/action.yml @@ -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" @@ -49,6 +55,8 @@ runs: - if: ${{ startsWith(inputs.distrib, 'el') }} name: Publish RPMs run: | + set -eux + FILES="*.${{ env.extfile }}" echo "[DEBUG] - Version: ${{ inputs.version }}" @@ -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" @@ -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- + # 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 diff --git a/.github/actions/promote-to-stable/action.yml b/.github/actions/promote-to-stable/action.yml index 249097b4a8d..ff86b903ef4 100644 --- a/.github/actions/promote-to-stable/action.yml +++ b/.github/actions/promote-to-stable/action.yml @@ -22,6 +22,15 @@ inputs: repository_name: description: "The repository name" required: true + 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" @@ -34,14 +43,38 @@ 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 + if [[ ${{ inputs.github_base_ref }} == "master" ]]; then + ROOT_REPO_PATH="rpm-standard-internal" + else + ROOT_REPO_PATH="rpm-standard" + fi + # Build search path based on release_cloud and release_type values + # if cloud, search in testing- 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 rpm-standard/${{ 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" @@ -50,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="rpm-standard/${{ 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 @@ -74,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 diff --git a/.github/workflows/centreon-collect.yml b/.github/workflows/centreon-collect.yml index b339f222923..b13539b7b36 100644 --- a/.github/workflows/centreon-collect.yml +++ b/.github/workflows/centreon-collect.yml @@ -136,6 +136,8 @@ jobs: artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} cache_key: cache-${{ 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) }} @@ -165,6 +167,8 @@ jobs: artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} cache_key: cache-${{ 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] @@ -188,3 +192,6 @@ jobs: minor_version: ${{ needs.get-version.outputs.patch }} 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 }} diff --git a/.github/workflows/get-version.yml b/.github/workflows/get-version.yml index 738c5bd6586..fb0bc1453d5 100644 --- a/.github/workflows/get-version.yml +++ b/.github/workflows/get-version.yml @@ -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: @@ -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 @@ -55,10 +63,43 @@ 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 | release* | hotfix*) + master | [2-9][0-9].[0-9][0-9].x) echo "release=1" >> $GITHUB_OUTPUT ;; + release* | hotfix*) + # 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 + # 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 + ;; *) echo "release=`date +%s`.`echo ${{ github.sha }} | cut -c -7`" >> $GITHUB_OUTPUT ;; diff --git a/.github/workflows/libzmq.yml b/.github/workflows/libzmq.yml index a7308862b55..c8d9c53b58d 100644 --- a/.github/workflows/libzmq.yml +++ b/.github/workflows/libzmq.yml @@ -160,6 +160,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) }} @@ -189,6 +191,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] @@ -212,3 +216,6 @@ jobs: minor_version: ${{ needs.get-version.outputs.patch }} 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 }} diff --git a/.github/workflows/robot-nightly.yml b/.github/workflows/robot-nightly.yml index 8b3c6931def..17ed7652b32 100644 --- a/.github/workflows/robot-nightly.yml +++ b/.github/workflows/robot-nightly.yml @@ -122,6 +122,8 @@ jobs: artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} cache_key: cache-${{ 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) }} @@ -149,3 +151,5 @@ jobs: artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} cache_key: cache-${{ 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 }}