diff --git a/.github/workflows/hidrive-next-build.yml b/.github/workflows/hidrive-next-build.yml index 15bdb72925359..dfa0cf7443049 100644 --- a/.github/workflows/hidrive-next-build.yml +++ b/.github/workflows/hidrive-next-build.yml @@ -284,41 +284,143 @@ jobs: name: Trigger remote workflow needs: [ hidrive-next-build, upload-to-artifactory ] # Trigger remote build on "ionos-dev|ionos-stable" branch *push* defined in the on:push:branches - if: github.event_name == 'push' && ( github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable' ) + # Can be disabled via repository variable 'DISABLE_REMOTE_TRIGGER' (set to 'true' to disable) + # Configure at: https://github.com/IONOS-Productivity/nc-server/settings/variables/actions + if: | + always() && + github.event_name == 'push' && + (github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable') && + needs.hidrive-next-build.result == 'success' && + needs.upload-to-artifactory.result == 'success' && + vars.DISABLE_REMOTE_TRIGGER != 'true' steps: + - name: Check prerequisites + run: | + echo "Checking if all required variables are set..." + error_count=0 + + if [ -z "${{ secrets.GITLAB_TOKEN }}" ]; then + echo "::error::GITLAB_TOKEN secret is not set" + error_count=$((error_count + 1)) + fi + + if [ -z "${{ secrets.GITLAB_TRIGGER_URL }}" ]; then + echo "::error::GITLAB_TRIGGER_URL secret is not set" + error_count=$((error_count + 1)) + fi + + if [ -z "${{ needs.hidrive-next-build.outputs.NC_VERSION }}" ]; then + echo "::error::NC_VERSION output from hidrive-next-build job is not set" + error_count=$((error_count + 1)) + else + echo "✓ NC_VERSION: ${{ needs.hidrive-next-build.outputs.NC_VERSION }}" + fi + + if [ -z "${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" ]; then + echo "::error::ARTIFACTORY_LAST_BUILD_PATH output from upload-to-artifactory job is not set" + error_count=$((error_count + 1)) + else + echo "✓ ARTIFACTORY_LAST_BUILD_PATH: ${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" + fi + + if [ -z "${{ github.sha }}" ]; then + echo "::error::github.sha is not set" + error_count=$((error_count + 1)) + else + echo "✓ GITHUB_SHA: ${{ github.sha }}" + fi + + if [ -z "${{ github.run_id }}" ]; then + echo "::error::github.run_id is not set" + error_count=$((error_count + 1)) + else + echo "✓ BUILD_ID: ${{ github.run_id }}" + fi + + if [ $error_count -ne 0 ]; then + echo "::error::Required variables are not set. Aborting." + exit 1 + fi + + echo "✅ All required variables are set" + - name: Trigger remote workflow run: | - # Enable command echo + # Enable command echo for debugging purposes set -x - # The 'ionos-dev' branch will trigger remote "dev" branch workflow - GITLAB_BRANCH="dev" + # Branch to GitLab Trigger Mapping (see HDNEXT-1373): + # | ref_name | GITLAB_REF | BUILD_TYPE | + # |--------------|------------|------------| + # | ionos-dev | main | dev | + # | ionos-stable | main | stable | - # set ARTIFACTORY_STAGE_PREFIX=stable on ionos-stable branch + BUILD_TYPE="dev" + + # Override build type for stable branch if [ ${{ github.ref_name }} == "ionos-stable" ]; then - GITLAB_BRANCH="stable" + BUILD_TYPE="stable" fi - # Call webhook - curl \ - --silent \ - --insecure \ - --request POST \ - --fail-with-body \ - -o response.json \ - --form token=${{ secrets.GITLAB_TOKEN }} \ - --form ref="${GITLAB_BRANCH}" \ - --form "variables[GITHUB_SHA]=${{ github.sha }}" \ - --form "variables[ARTIFACTORY_LAST_BUILD_PATH]=${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" \ - --form "variables[NC_VERSION]=${{ needs.hidrive-next-build.outputs.NC_VERSION }}" \ - --form "variables[BUILD_ID]=${{ github.run_id }}" \ - "${{ secrets.GITLAB_TRIGGER_URL }}" || ( RETCODE="$?"; jq . response.json; exit "$RETCODE" ) + # Construct source build URL for traceability + SOURCE_BUILD_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + echo "Source Build URL: $SOURCE_BUILD_URL" + + # Trigger GitLab pipeline via webhook with retry logic (3 attempts with exponential backoff) + MAX_ATTEMPTS=3 + ATTEMPT=1 + TRIGGER_SUCCESS=false + DELAY_SEC=5 + + while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do + echo "Trigger attempt $ATTEMPT of $MAX_ATTEMPTS..." + + if curl \ + --silent \ + --insecure \ + --request POST \ + --fail-with-body \ + -o response.json \ + --form token=${{ secrets.GITLAB_TOKEN }} \ + --form ref="main" \ + --form "variables[GITHUB_SHA]=${{ github.sha }}" \ + --form "variables[ARTIFACTORY_LAST_BUILD_PATH]=${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" \ + --form "variables[NC_VERSION]=${{ needs.hidrive-next-build.outputs.NC_VERSION }}" \ + --form "variables[BUILD_ID]=${{ github.run_id }}" \ + --form "variables[BUILD_TYPE]=${BUILD_TYPE}" \ + --form "variables[SOURCE_BUILD_URL]=${SOURCE_BUILD_URL}" \ + "${{ secrets.GITLAB_TRIGGER_URL }}"; then + TRIGGER_SUCCESS=true + echo "✅ Trigger successful on attempt $ATTEMPT" + break + else + RETCODE="$?" + echo "⚠️ Trigger attempt $ATTEMPT failed with code $RETCODE" + if [ -f response.json ]; then + jq . response.json || cat response.json + fi + if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then + echo "Waiting ${DELAY_SEC} seconds before retry..." + sleep $DELAY_SEC + DELAY_SEC=$((DELAY_SEC * 2)) # Exponential backoff: 5s, 10s, 20s + fi + fi + + ATTEMPT=$((ATTEMPT + 1)) + done + + if [ "$TRIGGER_SUCCESS" != "true" ]; then + echo "❌ Trigger failed after $MAX_ATTEMPTS attempts" + if [ -f response.json ]; then + jq . response.json || cat response.json + fi + exit 1 + fi # Disable command echo set +x # Print and parse json - # jq . response.json echo "json<> $GITHUB_OUTPUT cat response.json >> $GITHUB_OUTPUT echo "END" >> $GITHUB_OUTPUT