-
Notifications
You must be signed in to change notification settings - Fork 24
85 lines (69 loc) · 2.86 KB
/
part-compute-version.yml
File metadata and controls
85 lines (69 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: ~Compute Version
on:
workflow_call:
inputs:
prereleaseSlug:
required: false
type: string
checkTagIsUnique:
required: false
type: boolean
outputs:
COALESCE_VERSION:
description: "COALESCE_VERSION"
value: ${{ jobs.version.outputs.COALESCE_VERSION }}
jobs:
version:
runs-on: ubuntu-latest
outputs:
COALESCE_VERSION: ${{ steps.version.outputs.COALESCE_VERSION }}
steps:
- uses: actions/checkout@v6
- name: "Verify and set COALESCE_VERSION variable"
id: version
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$apiBaseUrl = "${{ github.api_url }}/repos/${{ github.repository }}/actions"
$runInfo = curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$apiBaseUrl/runs/${{ github.run_id }}";
$workflowId = $runInfo | jq -r .workflow_id;
$createdAt = $runInfo | jq -r .created_at;
$createdAtPST = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( [System.DateTimeOffset](Get-Date -Date $createdAt), "America/Los_Angeles" );
echo "workflowId: $workflowId";
echo "createdAt: $createdAt ($createdAtPST)";
# Get how many runs of this workflow have happened today
$dateFormat = "yyyy-MM-ddT00:00:00K"
$revRequestUrl = "$apiBaseUrl/workflows/$workflowId/runs?created=$($createdAtPST.ToString($dateFormat))..$($createdAtPST.AddDays(1).ToString($dateFormat))";
$rev = curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $revRequestUrl | jq .total_count;
# Current version number is sourced from the top of CHANGELOG.md
$version = Get-Content -Path CHANGELOG.md -TotalCount 1
$version = $version.Trim('#').Trim()
$date = $createdAtPST.ToString("yyyyMMdd")
$prereleaseSlug = "${{ inputs.prereleaseSlug }}"
echo "Version from $($path): $version";
echo "Prerelease: $prereleaseSlug";
echo "Date: $date";
echo "Rev: $rev";
echo "checkTagIsUnique: ${{ inputs.checkTagIsUnique }}";
if ($prereleaseSlug) {
$version = "$version-$prereleaseSlug.$date.$rev"
}
echo "Computed version: $version";
try
{
[System.Management.Automation.SemanticVersion]::Parse($version);
}
catch
{
Write-Error "'$version' is an invalid SemVer version"
exit 1
}
if ("${{ inputs.checkTagIsUnique }}" -eq "true") {
if (git tag -l "$version") {
Write-Error "Tag $version already exists.";
exit 1;
}
}
echo "COALESCE_VERSION=$version" >> $env:GITHUB_OUTPUT
echo "# Version $version" >> $env:GITHUB_STEP_SUMMARY