Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
270 lines (230 loc) · 9.75 KB
/
Copy pathaction.yml
File metadata and controls
270 lines (230 loc) · 9.75 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
name: "Tobi Validator GitHub Action"
description: "Run Tobi Validator canon or golden checks for Tsubasa artifacts without access tokens"
branding:
icon: "shield"
color: "purple"
inputs:
version:
description: "Public Tobi Validator binary release tag"
required: false
default: "stage1-tobi-validator-v0.7.0"
archive_name:
description: "Optional explicit bundle archive name. When omitted, the action infers the archive from runner OS and architecture."
required: false
default: ""
archive_sha256_name:
description: "Optional explicit checksum sidecar name. When omitted, the action uses <archive_name>.sha256."
required: false
default: ""
mode:
description: "Validator mode: canon or golden"
required: true
canon_input:
description: "Path to the input file for canon mode"
required: false
default: "examples/sample.tsubasa"
golden_fixtures:
description: "Path to the fixture JSON for golden mode"
required: false
default: "examples/golden/fixtures.json"
runs:
using: "composite"
steps:
- name: Validate inputs
shell: pwsh
run: |
$mode = "${{ inputs.mode }}".ToLowerInvariant()
if ($mode -ne "canon" -and $mode -ne "golden") {
throw "Input 'mode' must be either 'canon' or 'golden'."
}
- name: Resolve platform archive names
shell: pwsh
run: |
$explicitArchive = "${{ inputs.archive_name }}"
$explicitSha = "${{ inputs.archive_sha256_name }}"
$version = "${{ inputs.version }}"
$runnerOs = "$env:RUNNER_OS"
$runnerArch = "$env:RUNNER_ARCH"
if ([string]::IsNullOrWhiteSpace($explicitArchive)) {
switch ($runnerOs) {
"Windows" {
if ($runnerArch -ne "X64") {
throw "Unsupported Windows runner architecture for Tobi Validator: $runnerArch"
}
$archiveName = "windows-x86_64-release-archive.zip"
}
"Linux" {
if ($runnerArch -ne "X64") {
throw "Unsupported Linux runner architecture for Tobi Validator: $runnerArch"
}
$archiveName = "linux-x86_64-release-archive.zip"
}
"macOS" {
if ($runnerArch -eq "ARM64") {
$archiveName = "macos-arm64-release-archive.zip"
}
elseif ($runnerArch -eq "X64") {
$archiveName = "macos-x86_64-release-archive.zip"
}
else {
throw "Unsupported macOS runner architecture for Tobi Validator: $runnerArch"
}
}
default {
throw "Unsupported runner OS for Tobi Validator: $runnerOs"
}
}
}
else {
$archiveName = $explicitArchive
}
if ([string]::IsNullOrWhiteSpace($explicitSha)) {
$shaName = "$archiveName.sha256"
}
else {
$shaName = $explicitSha
}
"TOBI_ARCHIVE_NAME=$archiveName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"TOBI_ARCHIVE_SHA256_NAME=$shaName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"TOBI_RUNNER_OS=$runnerOs" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"TOBI_RUNNER_ARCH=$runnerArch" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "Resolved Tobi archive: $archiveName"
Write-Host "Resolved Tobi checksum sidecar: $shaName"
- name: Download public release bundle
shell: pwsh
env:
TOBI_VERSION: ${{ inputs.version }}
run: |
$version = [Uri]::EscapeDataString($env:TOBI_VERSION)
$archiveName = [Uri]::EscapeDataString($env:TOBI_ARCHIVE_NAME)
$shaName = [Uri]::EscapeDataString($env:TOBI_ARCHIVE_SHA256_NAME)
$releaseUrl = "https://github.com/OrganeticSphere/tobi-validator/releases/download/$version"
Invoke-WebRequest -Uri "$releaseUrl/$archiveName" -OutFile $env:TOBI_ARCHIVE_NAME
Invoke-WebRequest -Uri "$releaseUrl/$shaName" -OutFile $env:TOBI_ARCHIVE_SHA256_NAME
- name: Verify bundle checksum
shell: pwsh
run: |
$expectedLine = (Get-Content "$env:TOBI_ARCHIVE_SHA256_NAME" -Raw).Trim()
$expectedHash = ($expectedLine -split '\s+')[0].ToLowerInvariant()
if ($expectedHash -notmatch '^[a-f0-9]{64}$') {
throw "Invalid SHA-256 checksum sidecar."
}
$actualHash = (Get-FileHash "$env:TOBI_ARCHIVE_NAME" -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -ne $expectedHash) {
throw "Archive checksum mismatch. Expected $expectedHash but got $actualHash."
}
- name: Extract bundle
shell: pwsh
run: |
$archiveName = "$env:TOBI_ARCHIVE_NAME"
$workDir = Join-Path $env:RUNNER_TEMP ("tobi-" + [Guid]::NewGuid().ToString("N"))
$stagingDir = Join-Path $workDir "staging"
$bundleDir = Join-Path $workDir "bundle"
New-Item -ItemType Directory -Path $stagingDir -Force | Out-Null
New-Item -ItemType Directory -Path $bundleDir -Force | Out-Null
function Expand-TobiArchive {
param(
[Parameter(Mandatory = $true)]
[string] $Source,
[Parameter(Mandatory = $true)]
[string] $Destination
)
if ($Source.EndsWith(".zip", [System.StringComparison]::OrdinalIgnoreCase)) {
Expand-Archive -LiteralPath $Source -DestinationPath $Destination -Force
}
elseif ($Source.EndsWith(".tar.gz", [System.StringComparison]::OrdinalIgnoreCase)) {
tar -xzf $Source -C $Destination
if ($LASTEXITCODE -ne 0) {
throw "tar extraction failed for $Source"
}
}
else {
throw "Unsupported Tobi archive format: $Source"
}
}
function Find-TobiExecutable {
param(
[Parameter(Mandatory = $true)]
[string] $Root
)
if ("$env:TOBI_RUNNER_OS" -eq "Windows") {
return Get-ChildItem -Path $Root -Filter "tobi.exe" -File -Recurse | Select-Object -First 1
}
return Get-ChildItem -Path $Root -Filter "tobi" -File -Recurse | Select-Object -First 1
}
Expand-TobiArchive -Source $archiveName -Destination $stagingDir
$directExe = Find-TobiExecutable -Root $stagingDir
if ($null -ne $directExe) {
"TOBI_BUNDLE_DIR=$stagingDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
return
}
$payloadArchive = Get-ChildItem -Path $stagingDir -File -Recurse |
Where-Object {
$_.Name.EndsWith(".zip", [System.StringComparison]::OrdinalIgnoreCase) -or
$_.Name.EndsWith(".tar.gz", [System.StringComparison]::OrdinalIgnoreCase)
} |
Sort-Object FullName |
Select-Object -First 1
if ($null -eq $payloadArchive) {
throw "No Tobi executable or nested platform archive was found under $stagingDir."
}
$payloadShaPath = "$($payloadArchive.FullName).sha256"
if (-not (Test-Path -LiteralPath $payloadShaPath)) {
throw "Nested platform archive checksum sidecar not found: $payloadShaPath"
}
$expectedLine = (Get-Content -LiteralPath $payloadShaPath -Raw).Trim()
$expectedHash = ($expectedLine -split '\s+')[0].ToLowerInvariant()
if ($expectedHash -notmatch '^[a-f0-9]{64}$') {
throw "Invalid SHA-256 checksum sidecar."
}
$actualHash = (Get-FileHash -LiteralPath $payloadArchive.FullName -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -ne $expectedHash) {
throw "Nested platform archive checksum mismatch. Expected $expectedHash but got $actualHash."
}
Expand-TobiArchive -Source $payloadArchive.FullName -Destination $bundleDir
"TOBI_BUNDLE_DIR=$bundleDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Resolve extracted tobi executable
shell: pwsh
run: |
$bundleDir = "$env:TOBI_BUNDLE_DIR"
if ([string]::IsNullOrWhiteSpace($bundleDir)) {
$bundleDir = "tobi-bundle"
}
if ("$env:TOBI_RUNNER_OS" -eq "Windows") {
$exe = Get-ChildItem -Path $bundleDir -Filter "tobi.exe" -File -Recurse | Select-Object -First 1
$exeLabel = "tobi.exe"
}
else {
$exe = Get-ChildItem -Path $bundleDir -Filter "tobi" -File -Recurse | Select-Object -First 1
$exeLabel = "tobi"
}
if ($null -eq $exe) {
throw "$exeLabel was not found anywhere under $bundleDir after archive extraction."
}
if ("$env:TOBI_RUNNER_OS" -ne "Windows") {
chmod +x $exe.FullName
if ($LASTEXITCODE -ne 0) {
throw "Failed to mark Tobi executable as executable: $($exe.FullName)"
}
}
"TOBI_EXE_PATH=$($exe.FullName)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Run canon
if: ${{ inputs.mode == 'canon' }}
shell: pwsh
run: |
$inputPath = "${{ inputs.canon_input }}"
if (-not (Test-Path -LiteralPath $inputPath)) {
throw "Canon input not found: $inputPath"
}
$resolvedInput = (Resolve-Path -LiteralPath $inputPath).Path
& "$env:TOBI_EXE_PATH" canon $resolvedInput
- name: Run golden
if: ${{ inputs.mode == 'golden' }}
shell: pwsh
run: |
$fixturesPath = "${{ inputs.golden_fixtures }}"
if (-not (Test-Path -LiteralPath $fixturesPath)) {
throw "Fixture file not found: $fixturesPath"
}
$resolvedFixtures = (Resolve-Path -LiteralPath $fixturesPath).Path
& "$env:TOBI_EXE_PATH" golden $resolvedFixtures