Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -316,7 +316,6 @@ ...@@ -316,7 +316,6 @@
$DEFAULT_BRANCH="dev" $DEFAULT_BRANCH="dev"
$BRANCH_TO_PULL=$DEFAULT_BRANCH # default branch to pull $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 "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_COMMIT_TAG = $CI_COMMIT_TAG"
Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE" Write-Host "CI_MERGE_REQUEST_TITLE = $CI_MERGE_REQUEST_TITLE"
...@@ -340,33 +339,35 @@ ...@@ -340,33 +339,35 @@
Write-Host "Branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME not found on repo $DEP_NAME." Write-Host "Branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME not found on repo $DEP_NAME."
Write-Host "Pulling from default branch." Write-Host "Pulling from default branch."
} }
###################################### ######################################
# CASE WHERE A COMMIT TAG IS CREATED # CASE WHERE A COMMIT TAG IS CREATED
} elseif ( "$CI_COMMIT_TAG" ) { } 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" 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=$($(Invoke-RestMethod -Uri "$API_URL/projects/$CI_PROJECT_ID/repository/tags/$CI_COMMIT_TAG" -Method Get).commit.created_at) $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 "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 "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" 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) | $DEP_TAGS = $($(Invoke-RestMethod -Uri "$DEP_API_URL/repository/tags?per_page=100" -Method Get) |
Sort-Object -Property commit.created_at -Descending) Sort-Object -Property {[datetime]$_.commit.created_at} -Descending)
$DEP_TAGS | Select-Object name, @{Name="commit_creation_date"; Expression={$_.commit.created_at}} | Out-String $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 "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" 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." 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 $DEP_TAGS_BEFORE_DATE | Select-Object name | Out-String
if ( $($DEP_TAGS_BEFORE_DATE.Count) -ne 0) { if ( $($DEP_TAGS_BEFORE_DATE.Count) -ne 0) {
$BRANCH_TO_PULL=$DEP_TAGS_BEFORE_DATE[0].name $BRANCH_TO_PULL=$DEP_TAGS_BEFORE_DATE[0].name
Write-Host "Found release : $BRANCH_TO_PULL. Using it as BRANCH_TO_PULL." Write-Host "Found release : $BRANCH_TO_PULL. Using it as BRANCH_TO_PULL."
} }
else { else {
Write-Host "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG." Write-Host "Found no release predating $CI_PROJECT_NAME $CI_COMMIT_TAG's date : $CI_COMMIT_TAG."
Write-Host "Retrieving latest repo tag." Write-Host "Retrieving latest repo tag."
BRANCH_TO_PULL=$DEP_TAGS[0].name BRANCH_TO_PULL=$DEP_TAGS[0].name
Write-Host "\$BRANCH_TO_PULL = $BRANCH_TO_PULL" Write-Host "\$BRANCH_TO_PULL = $BRANCH_TO_PULL"
} }
########################################### ###########################################
# CASE CASUAL COMMIT or Draft MR PIPELINE # CASE CASUAL COMMIT or Draft MR PIPELINE
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment