Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7546918
Initial plan
Copilot Nov 28, 2025
a034eb2
Fix DateTime locale-agnostic serialization using ISO 8601 format
Copilot Nov 28, 2025
dc6fa1f
Apply suggestion from @mazhelez
mazhelez Nov 28, 2025
3e1c750
Add release notes entry for DateTime locale fix (Issue #2045)
Copilot Nov 28, 2025
2833097
Ensure datetime is converted to UTC before calculating duration
Copilot Nov 28, 2025
44c6785
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 2, 2025
c35f62d
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 3, 2025
5702191
Move Issue 2045 release notes to unreleased section above v8.1
Copilot Dec 3, 2025
ad05b6b
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 3, 2025
5952fd6
Merge branch 'main' into copilot/fix-datetime-parsing-bug - resolve R…
Copilot Dec 4, 2025
dbce971
Merge branch 'main' into copilot/fix-datetime-parsing-bug - resolve c…
Copilot Dec 4, 2025
0d64c05
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 8, 2025
049409f
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 8, 2025
6b92269
Refactor datetime parsing into testable function and add locale testing
Copilot Dec 12, 2025
efc102a
Merge branch 'main' into copilot/fix-datetime-parsing-bug
mazhelez Dec 12, 2025
b90d721
Use ConvertToUtcDateTime function from WorkflowPostProcess.ps1 instea…
Copilot Dec 12, 2025
bee17fb
Clean up whitespace in DateTime serialization test for consistency
mazhelez Dec 12, 2025
7594d99
Add GetWorkflowDuration function and update tests for locale handling
mazhelez Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Actions/.Modules/WorkflowPostProcessHelper.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<#
.SYNOPSIS
Helper functions for WorkflowPostProcess action

.DESCRIPTION
Contains utility functions used by the WorkflowPostProcess action and its tests
#>

<#
.SYNOPSIS
Calculate the duration of a workflow from a start time

.DESCRIPTION
Calculates the duration in seconds from the provided start time to the current UTC time.
Handles both DateTime objects and string representations in ISO 8601 format.

.PARAMETER StartTime
The workflow start time as either a DateTime object or a string in ISO 8601 format
Comment on lines +15 to +18
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states that the function "Handles both DateTime objects and string representations in ISO 8601 format," but the implementation actually accepts and parses any date format that InvariantCulture can understand, not just ISO 8601. Consider updating the description to accurately reflect that the function handles various culture-independent date formats or locale-specific formats that can be parsed by InvariantCulture.

Suggested change
Handles both DateTime objects and string representations in ISO 8601 format.
.PARAMETER StartTime
The workflow start time as either a DateTime object or a string in ISO 8601 format
Handles both DateTime objects and string representations in any date format that can be parsed by the invariant culture (e.g., ISO 8601 or other culture-independent formats).
.PARAMETER StartTime
The workflow start time as either a DateTime object or a string in any date format that can be parsed by the invariant culture (such as ISO 8601 or other culture-independent formats)

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter documentation states "a string in ISO 8601 format" but the implementation (line 40) uses InvariantCulture parsing which can accept many different date formats beyond ISO 8601. Consider updating to reflect the actual behavior, such as "a string in ISO 8601 format or other culture-independent date format".

Suggested change
The workflow start time as either a DateTime object or a string in ISO 8601 format
The workflow start time as either a DateTime object or a string in ISO 8601 format or other culture-independent date format

Copilot uses AI. Check for mistakes.

.PARAMETER EndTime
(Optional) The end time as a DateTime object. Defaults to the current UTC time.

.EXAMPLE
$duration = GetWorkflowDuration -StartTime "2025-12-12T10:00:00.0000000Z" -EndTime ([DateTime]::UtcNow)

.EXAMPLE
$duration = GetWorkflowDuration -StartTime ([DateTime]::UtcNow)
#>
function GetWorkflowDuration {
Param(
[Parameter(Mandatory = $true)]
$StartTime,
[Parameter(Mandatory = $false)]
$EndTime = [DateTime]::UtcNow
)

if ($StartTime -is [DateTime]) {
$workflowStartTime = $StartTime.ToUniversalTime()
} else {
$workflowStartTime = [DateTime]::Parse($StartTime, [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::AdjustToUniversal)
}

$workflowDuration = $EndTime.ToUniversalTime().Subtract($workflowStartTime).TotalSeconds
return $workflowDuration
}

Export-ModuleMember -Function GetWorkflowDuration
3 changes: 2 additions & 1 deletion Actions/WorkflowInitialize/WorkflowInitialize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ TestALGoRepository
TestRunnerPrerequisites

# Create a json object that contains an entry for the workflowstarttime
# Use ISO 8601 format for locale-agnostic serialization
$scopeJson = @{
"workflowStartTime" = [DateTime]::UtcNow
"workflowStartTime" = [DateTime]::UtcNow.ToString("o")
} | ConvertTo-Json -Compress

Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "telemetryScopeJson=$scopeJson"
6 changes: 4 additions & 2 deletions Actions/WorkflowPostProcess/WorkflowPostProcess.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ function LogWorkflowEnd($TelemetryScopeJson, $JobContext, $AlGoVersion) {
# Calculate the workflow duration using the github api
if ($telemetryScope -and ($null -ne $telemetryScope.workflowStartTime)) {
Write-Host "Calculating workflow duration..."
$workflowTiming= [DateTime]::UtcNow.Subtract([DateTime]::Parse($telemetryScope.workflowStartTime)).TotalSeconds
Add-TelemetryProperty -Hashtable $AdditionalData -Key 'WorkflowDuration' -Value $workflowTiming

$workflowDuration = GetWorkflowDuration -StartTime $telemetryScope.workflowStartTime
Add-TelemetryProperty -Hashtable $AdditionalData -Key 'WorkflowDuration' -Value $workflowDuration
}

# Log additional telemetry from AL-Go settings
Expand Down Expand Up @@ -102,6 +103,7 @@ function LogWorkflowEnd($TelemetryScopeJson, $JobContext, $AlGoVersion) {
}

Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\TelemetryHelper.psm1" -Resolve)
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\.Modules\WorkflowPostProcessHelper.psm1" -Resolve)

try {
LogWorkflowEnd -TelemetryScopeJson $telemetryScopeJson -JobContext $currentJobContext -AlGoVersion (GetAlGoVersion -ActionsRepo $actionsRepo -ActionRef $actionsRef)
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Issues

- Issue 2045 DateTime parsing fails on non-US locale runners in WorkflowPostProcess.ps1
- AL-Go repositories with large amounts of projects may run into issues with too large environment variables

## AL-Go Telemetry updates
Expand Down
21 changes: 21 additions & 0 deletions Tests/WorkflowPostProcess.Test.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Get-Module TestActionsHelper | Remove-Module -Force
Import-Module (Join-Path $PSScriptRoot 'TestActionsHelper.psm1')
Import-Module (Join-Path $PSScriptRoot '..\Actions\.Modules\WorkflowPostProcessHelper.psm1')
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0

Describe "WorkflowPostProcess Action Tests" {
Expand All @@ -25,4 +26,24 @@ Describe "WorkflowPostProcess Action Tests" {

# Call action

It 'GetWorkflowDuration handles different culture formats correctly' {
$endTimeUTC = [DateTime]::Parse("2025-12-12T10:00:01.0000000Z")

# Test UTC start time
$workflowDuration = GetWorkflowDuration -StartTime "2025-12-12T10:00:00.0000000Z" -EndTime $endTimeUTC
$workflowDuration | Should -Be 1

# Test en-US culture format
$workflowDuration = GetWorkflowDuration -StartTime "12/12/2025 10:00:00 AM" -EndTime $endTimeUTC
$workflowDuration | Should -Be 1

# Test de-DE culture format
$workflowDuration = GetWorkflowDuration -StartTime "12.12.2025 10:00:00" -EndTime $endTimeUTC
$workflowDuration | Should -Be 1

# Test da-DK culture format
$workflowDuration = GetWorkflowDuration -StartTime "12-12-2025 10:00:00" -EndTime $endTimeUTC
$workflowDuration | Should -Be 1
}

}
Loading