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

fix : added datetime typing to date sorting for release jobs to ensure date...

fix : added datetime typing to date sorting for release jobs to ensure date was not treated as a string
parent fc894284
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -316,7 +316,6 @@
        $DEFAULT_BRANCH="dev"
        $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"

@@ -340,20 +339,21 @@
                Write-Host "Branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME not found on repo $DEP_NAME."
                Write-Host "Pulling from default branch."
            }

        ######################################
        # CASE WHERE A COMMIT TAG IS CREATED
        } elseif ( "$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 "$API_URL/projects/$CI_PROJECT_ID/repository/tags/$CI_COMMIT_TAG" -Method Get).commit.created_at)
          Write-Host "Retrieving the creation_date of the commit the tag has been created from $API_URL/projects/$CI_PROJECT_ID/repository/tags/$CI_COMMIT_TAG"
          $REPO_CURR_TAG_DATE = [datetime]$($(Invoke-RestMethod -Uri "$API_URL/projects/$CI_PROJECT_ID/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."
          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)
            $DEP_TAGS | Select-Object name, @{Name="commit_creation_date"; Expression={$_.commit.created_at}} | Out-String
              Sort-Object -Property {[datetime]$_.commit.created_at} -Descending)
          $DEP_TAGS | Select-Object name, @{Name="commit_creation_date"; Expression={[datetime]$_.commit.created_at}} | Out-String
          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"})
          $DEP_TAGS_BEFORE_DATE = $DEP_TAGS | Where-Object { [datetime]$_.commit.created_at -le [datetime]$REPO_CURR_TAG_DATE }
          Write-Host "Found $($DEP_TAGS_BEFORE_DATE.Count) tags for $DEP_NAME pre-dating release $CI_COMMIT_TAG."
          $DEP_TAGS_BEFORE_DATE | Select-Object name | Out-String

@@ -367,6 +367,7 @@
              BRANCH_TO_PULL=$DEP_TAGS[0].name
              Write-Host "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
          }

        ###########################################
        # CASE CASUAL COMMIT or Draft MR PIPELINE
        } else {