Commit f84ee88f authored by Grégoire Kubler's avatar Grégoire Kubler
Browse files

fix : added missing section in windows:select_jobs to handle case where a tag was created.

parent c9c27818
Loading
Loading
Loading
Loading
+47 −47
Original line number Diff line number Diff line
@@ -100,7 +100,6 @@
              | map(select(.commit.created_at != null and (.commit.created_at <= $before_date)))
          ' <<<"$DEP_TAGS")

        	SELECTED_TAG=""
        	if [[ $(jq length <<<"$TAGS_BEFORE_DATE") != 0 ]]; then
        		BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$TAGS_BEFORE_DATE")
        		echo "Found release : $BRANCH_TO_PULL. Using it as \$BRANCH_TO_PULL."
@@ -302,8 +301,7 @@
            $DEP_ID=$(Invoke-RestMethod -Uri "$API_URL/users/$USER_ID/projects?search=${DEP_NAME}" -Method Get)[0].id
        }
        Write-Host "DEP_ID = $DEP_ID"
        $DEP_URL="$DEP_API_URL"

        $DEP_API_URL="$API_URL/projects/$DEP_ID"

        ######################################################################################################
        # Retrieve the branch to pull
@@ -319,6 +317,8 @@
        $BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull
        Write-Host "Choosing a branch to pull dependending if we are in a Non draft merge request or not."
        Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE"
        Write-Host "CI_COMMIT_TAG = $CI_COMMIT_TAG"
        Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE"

        ################################
        # CASE NON DRAFT MERGE REQUEST
@@ -331,6 +331,7 @@
            Write-Host "NON DRAFT MERGE REQUEST Pipeline detected : Pulling from CI_MERGE_REQUEST_TARGET_BRANCH_NAME : $CI_MERGE_REQUEST_TARGET_BRANCH_NAME."
            Write-Host "Checking if CI_MERGE_REQUEST_TARGET_BRANCH_NAME "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" branch exists, otherwise pull from default."
            $FILTERED_BRANCHES=@($DEP_BRANCHES | Where-Object { $_.name -eq "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"})
            
            if ( ($FILTERED_BRANCHES.Count) -gt 0){
                Write-Host "Found MR target branch in $DEP_NAME."
                $BRANCH_TO_PULL=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
@@ -342,32 +343,32 @@
        ######################################
        # CASE WHERE A COMMIT TAG IS CREATED
        } elseif ( "$CI_COMMIT_TAG" ) {
          $REPO_CURR_TAG_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags/$CI_COMMIT_TAG" -Method Get) | Select-Object commit.created_at)
        	# PROJECT_CURR_TAG_DATE=$(jq '.commit.created_at' <<<$(curl -s "$API_URL/projects/$CI_PROJECT_ID/repository/tags/$CI_COMMIT_TAG"))

            Write-Host "Rretrieving the creation_date of the commit the tag has been created from $DEP_API_URL/repository/tags/$CI_COMMIT_TAG"
            $REPO_CURR_TAG_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags/$CI_COMMIT_TAG" -Method Get).commit.created_at)
            Write-Host "REPO_CURR_TAG_DATE = $REPO_CURR_TAG_DATE"
            Write-Host "Looking for latest release in $DEP_NAME before $CI_COMMIT_TAG was released on project $CI_PROJECT_NAME."
          $DEP_TAGS_BEFORE_DATE=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags?per_page=100" -Method Get) | 
                     Sort-Object -Property commit.created_at -Descending |
                     Where-Object { $_.commit.created_at -eq "$CI_COMMIT_REF_NAME"}
          $DEP_TAGS_BEFORE_DATE=$()
        	# TAGS_BEFORE_DATE=$(jq --slurp --arg before_date "$PROJECT_CURR_TAG_DATE" '
         #      .[]
         #      | map(select(.commit.created_at != null and (.commit.created_at <= $before_date)))
         #  ' <<<"$DEP_TAGS")

        	# SELECTED_TAG=""
        	# if [[ $(jq length <<<"$TAGS_BEFORE_DATE") != 0 ]]; then
        	# 	BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$TAGS_BEFORE_DATE")
        	# 	echo "Found release : $BRANCH_TO_PULL. Using it as \$BRANCH_TO_PULL."
        	# else
        	# 	echo "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG."
        	# 	echo "Retrieving latest repo tag."
        	# 	BRANCH_TO_PULL=$(jq -r '.[0].name' <<<"$DEP_TAGS")
        	# 	echo "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
        	# fi

            Write-Host "Retrieving repo tags from $DEP_API_URL/repository/tags?per_page=100"
            $DEP_TAGS=$($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags?per_page=100" -Method Get) | 
                Sort-Object -Property commit.created_at -Descending)
            Write-Host "DEP_TAGS = $DEP_TAGS"
            
            Write-Host "Looking for latest release in $DEP_NAME before $CI_COMMIT_TAG was released on project $CI_PROJECT_NAME."
            Write-Host "Retrieving repo tags from $DEP_API_URL/repository/tags?per_page=100"
            $DEP_TAGS_BEFORE_DATE=$($DEP_TAGS |
                Where-Object { $_.commit.created_at -le "$REPO_CURR_TAG_DATE"})
            Write-Host "Found $($DEP_TAGS_BEFORE_DATE.Count) tags pre-dating release $CI_COMMIT_TAG."
            $DEP_TAGS_BEFORE_DATE | Select-Object name | Out-String

            if ( $($DEP_TAGS_BEFORE_DATE.Count) -ne 0) {
                $BRANCH_TO_PULL=$DEP_TAGS_BEFORE_DATE[0].name
              Write-Host "Found release : $BRANCH_TO_PULL. Using it as BRANCH_TO_PULL."    
            }
            else {
                Write-Host "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG."
                Write-Host "Retrieving latest repo tag."
                BRANCH_TO_PULL=$DEP_TAGS[0].name
                Write-Host "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
            }
        ###########################################
        # CASE CASUAL COMMIT or Draft MR PIPELINE
        } else {
@@ -391,11 +392,10 @@
        #######################################################
        # Retrieve JOB ID
        ## Prepare pipelines to parse to retrieve the jobs of each pipelines
        
        Write-Host "*************************************************************************"
        Write-Host "*************************************************************************"
        Write-Host "**"
        Write-Host "**           RETRIEVING LATEST SUCCESSFUL PIPELINES IN GIVEN BRANCH"
        Write-Host "**           RETRIEVING LATEST SUCCESSFUL PIPELINES IN REF"
        Write-Host "**                          $BRANCH_TO_PULL"
        Write-Host "**"
        Write-Host "*************************************************************************"