Skip to content

Commit dc5e1ef

Browse files
fix: refactor upstream build triggering and artifact handling in release workflow
1 parent 4e9b02b commit dc5e1ef

1 file changed

Lines changed: 165 additions & 90 deletions

File tree

.github/workflows/create-latest-branch-release.yml

Lines changed: 165 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -97,126 +97,201 @@ jobs:
9797
$shortSha = $latestBranch.sha.Substring(0, 8)
9898
echo "short_sha=$shortSha" >> $env:GITHUB_OUTPUT
9999
100-
- name: Checkout upstream repository
101-
uses: actions/checkout@v4
102-
with:
103-
repository: optiscaler/OptiScaler
104-
ref: ${{ steps.find_branch.outputs.branch_name }}
105-
path: upstream-optiscaler
106-
token: ${{ secrets.GITHUB_TOKEN }}
107-
submodules: recursive
108-
109-
- name: Setup MSBuild
110-
uses: microsoft/setup-msbuild@v2
111-
112-
- name: Setup NuGet
113-
uses: NuGet/setup-nuget@v2
114-
115-
- name: Add msbuild to PATH
116-
uses: microsoft/setup-msbuild@v2
117-
118-
- name: Restore NuGet packages
119-
run: nuget restore upstream-optiscaler/OptiScaler.sln
120-
121-
- name: Build OptiScaler
122-
id: build_optiscaler
100+
- name: Trigger upstream build workflow
101+
id: trigger_build
123102
shell: powershell
124103
run: |
125104
$branchName = "${{ steps.find_branch.outputs.branch_name }}"
126105
$commitSha = "${{ steps.find_branch.outputs.commit_sha }}"
127106
$shortSha = "${{ steps.find_branch.outputs.short_sha }}"
128107
129-
Write-Output "Building OptiScaler from branch: $branchName"
108+
Write-Output "Triggering upstream build for branch: $branchName"
130109
Write-Output "Commit: $commitSha"
131110
132-
# Build the solution
111+
# Set up headers for authenticated API requests
112+
$headers = @{
113+
'Authorization' = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
114+
'Accept' = 'application/vnd.github.v3+json'
115+
'Content-Type' = 'application/json'
116+
}
117+
118+
# Trigger the upstream workflow
119+
$workflowFile = "just_build_no_signature.yml"
120+
$triggerUrl = "https://api.github.com/repos/optiscaler/OptiScaler/actions/workflows/$workflowFile/dispatches"
121+
122+
$body = @{
123+
ref = $branchName
124+
} | ConvertTo-Json
125+
133126
try {
134-
Write-Output "Running MSBuild with verbose logging..."
135-
$buildResult = & msbuild upstream-optiscaler/OptiScaler.sln /p:Configuration=Release /p:Platform=x64 /m /verbosity:normal /flp:logfile=build.log;verbosity=diagnostic
136-
$buildExitCode = $LASTEXITCODE
127+
Write-Output "Triggering workflow at: $triggerUrl"
128+
Write-Output "For branch: $branchName"
137129
138-
Write-Output "MSBuild exit code: $buildExitCode"
130+
$response = Invoke-RestMethod -Uri $triggerUrl -Method POST -Headers $headers -Body $body
131+
Write-Output "✅ Successfully triggered upstream build workflow"
139132
140-
# Show the last 50 lines of the build log if it exists
141-
if (Test-Path "build.log") {
142-
Write-Output "Last 50 lines of build log:"
143-
Get-Content "build.log" | Select-Object -Last 50 | ForEach-Object {
144-
Write-Output "BUILD LOG: $_"
145-
}
146-
}
133+
# Wait a moment for the workflow to start
134+
Start-Sleep -Seconds 10
147135
148-
if ($buildExitCode -ne 0) {
149-
Write-Error "❌ MSBuild failed with exit code: $buildExitCode"
136+
# Get the workflow run ID (we'll need to poll for the latest run)
137+
$runsUrl = "https://api.github.com/repos/optiscaler/OptiScaler/actions/workflows/$workflowFile/runs?branch=$branchName&per_page=1"
138+
$runs = Invoke-RestMethod -Uri $runsUrl -Headers $headers
139+
140+
if ($runs.workflow_runs.Count -eq 0) {
141+
Write-Error "❌ No workflow runs found after triggering"
150142
exit 1
151143
}
152144
153-
Write-Output "✅ MSBuild completed successfully!"
145+
$runId = $runs.workflow_runs[0].id
146+
$runUrl = $runs.workflow_runs[0].html_url
154147
155-
# Debug: List all files in the upstream-optiscaler directory
156-
Write-Output "Searching for build outputs..."
157-
Write-Output "Contents of upstream-optiscaler directory:"
158-
Get-ChildItem -Path "upstream-optiscaler" -Recurse -Include "*.dll", "*.exe", "*.lib" | ForEach-Object {
159-
Write-Output " Found: $($_.FullName)"
160-
}
148+
Write-Output "Workflow run ID: $runId"
149+
Write-Output "Workflow run URL: $runUrl"
161150
162-
# Check if build outputs exist
163-
$dllPath = "upstream-optiscaler\x64\Release\OptiScaler.dll"
164-
if (-not (Test-Path $dllPath)) {
165-
Write-Output "❌ OptiScaler.dll not found at expected location: $dllPath"
166-
167-
# List what files are actually in the output directory
168-
$outputDir = "upstream-optiscaler\x64\Release"
169-
if (Test-Path $outputDir) {
170-
Write-Output "Files in x64\Release directory:"
171-
Get-ChildItem -Path $outputDir -Recurse | ForEach-Object {
172-
Write-Output " $($_.FullName)"
173-
}
174-
} else {
175-
Write-Output "x64\Release directory does not exist"
176-
}
151+
# Store run information for next steps
152+
echo "workflow_run_id=$runId" >> $env:GITHUB_OUTPUT
153+
echo "workflow_run_url=$runUrl" >> $env:GITHUB_OUTPUT
154+
echo "build_successful=true" >> $env:GITHUB_OUTPUT
155+
156+
# Create artifact name
157+
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
158+
$artifactName = "OptiScaler_${branchName}_${shortSha}_${timestamp}"
159+
echo "artifact_name=$artifactName" >> $env:GITHUB_OUTPUT
160+
echo "base_artifact_name=OptiScaler_${branchName}_${shortSha}" >> $env:GITHUB_OUTPUT
161+
162+
} catch {
163+
Write-Error "❌ Failed to trigger upstream workflow: $($_.Exception.Message)"
164+
Write-Error "Response: $($_.Exception.Response)"
165+
exit 1
166+
}
167+
168+
- name: Wait for upstream build to complete
169+
shell: powershell
170+
run: |
171+
$runId = "${{ steps.trigger_build.outputs.workflow_run_id }}"
172+
$maxWaitMinutes = 30
173+
$checkIntervalSeconds = 30
174+
$maxChecks = ($maxWaitMinutes * 60) / $checkIntervalSeconds
175+
176+
Write-Output "Waiting for upstream build to complete..."
177+
Write-Output "Run ID: $runId"
178+
Write-Output "Max wait time: $maxWaitMinutes minutes"
179+
180+
$headers = @{
181+
'Authorization' = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
182+
'Accept' = 'application/vnd.github.v3+json'
183+
}
184+
185+
$runUrl = "https://api.github.com/repos/optiscaler/OptiScaler/actions/runs/$runId"
186+
187+
for ($i = 0; $i -lt $maxChecks; $i++) {
188+
try {
189+
$run = Invoke-RestMethod -Uri $runUrl -Headers $headers
190+
$status = $run.status
191+
$conclusion = $run.conclusion
177192
178-
# Check other possible output locations
179-
$altDirs = @(
180-
"upstream-optiscaler\OptiScaler\x64\Release",
181-
"upstream-optiscaler\Release",
182-
"upstream-optiscaler\x64",
183-
"upstream-optiscaler\OptiScaler\Release"
184-
)
193+
Write-Output "Check $($i + 1)/$maxChecks - Status: $status"
185194
186-
foreach ($dir in $altDirs) {
187-
if (Test-Path $dir) {
188-
Write-Output "Contents of ${dir}:"
189-
Get-ChildItem -Path $dir -Recurse | ForEach-Object {
190-
Write-Output " $($_.FullName)"
191-
}
195+
if ($status -eq "completed") {
196+
if ($conclusion -eq "success") {
197+
Write-Output "✅ Upstream build completed successfully!"
198+
echo "build_successful=true" >> $env:GITHUB_OUTPUT
199+
break
200+
} else {
201+
Write-Error "❌ Upstream build failed with conclusion: $conclusion"
202+
Write-Error "Build URL: ${{ steps.trigger_build.outputs.workflow_run_url }}"
203+
exit 1
192204
}
193205
}
194206
195-
exit 1
207+
if ($i -lt ($maxChecks - 1)) {
208+
Write-Output "Waiting $checkIntervalSeconds seconds before next check..."
209+
Start-Sleep -Seconds $checkIntervalSeconds
210+
}
211+
} catch {
212+
Write-Warning "Error checking build status: $($_.Exception.Message)"
213+
if ($i -lt ($maxChecks - 1)) {
214+
Start-Sleep -Seconds $checkIntervalSeconds
215+
}
196216
}
217+
}
218+
219+
if ($i -eq $maxChecks) {
220+
Write-Error "❌ Timeout waiting for upstream build to complete after $maxWaitMinutes minutes"
221+
Write-Error "Build URL: ${{ steps.trigger_build.outputs.workflow_run_url }}"
222+
exit 1
223+
}
224+
225+
- name: Download artifacts from upstream build
226+
id: download_artifacts
227+
shell: powershell
228+
run: |
229+
$runId = "${{ steps.trigger_build.outputs.workflow_run_id }}"
230+
231+
Write-Output "Downloading artifacts from upstream build..."
232+
Write-Output "Run ID: $runId"
233+
234+
$headers = @{
235+
'Authorization' = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
236+
'Accept' = 'application/vnd.github.v3+json'
237+
}
238+
239+
# Get artifacts for the run
240+
$artifactsUrl = "https://api.github.com/repos/optiscaler/OptiScaler/actions/runs/$runId/artifacts"
241+
$artifacts = Invoke-RestMethod -Uri $artifactsUrl -Headers $headers
242+
243+
if ($artifacts.artifacts.Count -eq 0) {
244+
Write-Error "❌ No artifacts found in upstream build"
245+
exit 1
246+
}
247+
248+
Write-Output "Found $($artifacts.artifacts.Count) artifacts:"
249+
foreach ($artifact in $artifacts.artifacts) {
250+
Write-Output " - $($artifact.name) ($($artifact.size_in_bytes) bytes)"
251+
}
252+
253+
# Download the first artifact (assuming it contains OptiScaler.dll)
254+
$artifact = $artifacts.artifacts[0]
255+
$downloadUrl = $artifact.archive_download_url
256+
257+
Write-Output "Downloading artifact: $($artifact.name)"
258+
259+
try {
260+
Invoke-WebRequest -Uri $downloadUrl -Headers $headers -OutFile "optiscaler-artifact.zip"
261+
Write-Output "✅ Downloaded artifact successfully"
197262
198-
Write-Output "✅ OptiScaler.dll found at: $dllPath"
263+
# Extract the artifact
264+
Expand-Archive -Path "optiscaler-artifact.zip" -DestinationPath "optiscaler-extracted" -Force
265+
Write-Output "✅ Extracted artifact"
199266
200-
# Create artifact name
201-
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
202-
$artifactName = "OptiScaler_${branchName}_${shortSha}_${timestamp}"
267+
# List contents to verify
268+
Write-Output "Artifact contents:"
269+
Get-ChildItem -Path "optiscaler-extracted" -Recurse | ForEach-Object {
270+
Write-Output " $($_.FullName)"
271+
}
203272
204-
echo "build_successful=true" >> $env:GITHUB_OUTPUT
205-
echo "artifact_name=$artifactName" >> $env:GITHUB_OUTPUT
206-
echo "base_artifact_name=OptiScaler_${branchName}_${shortSha}" >> $env:GITHUB_OUTPUT
273+
# Look for OptiScaler.dll
274+
$dllFiles = Get-ChildItem -Path "optiscaler-extracted" -Name "OptiScaler.dll" -Recurse
275+
if ($dllFiles.Count -eq 0) {
276+
Write-Error "❌ OptiScaler.dll not found in downloaded artifact"
277+
exit 1
278+
}
279+
280+
$dllPath = $dllFiles[0].FullName
281+
Write-Output "✅ Found OptiScaler.dll at: $dllPath"
207282
echo "dll_path=$dllPath" >> $env:GITHUB_OUTPUT
208283
209284
} catch {
210-
Write-Error "❌ Build failed: $($_.Exception.Message)"
285+
Write-Error "❌ Failed to download or extract artifact: $($_.Exception.Message)"
211286
exit 1
212287
}
213288
214289
- name: Prepare OptiScaler artifacts
215290
id: prepare_optiscaler
216291
shell: powershell
217292
run: |
218-
$dllPath = "${{ steps.build_optiscaler.outputs.dll_path }}"
219-
$artifactName = "${{ steps.build_optiscaler.outputs.artifact_name }}"
293+
$dllPath = "${{ steps.download_artifacts.outputs.dll_path }}"
294+
$artifactName = "${{ steps.trigger_build.outputs.artifact_name }}"
220295
221296
Write-Output "Preparing OptiScaler artifacts..."
222297
@@ -665,7 +740,7 @@ jobs:
665740
$fileDetails = '${{ steps.prepare_assets.outputs.file_details }}' | ConvertFrom-Json
666741
667742
# Get the release tag for URL construction
668-
$releaseTag = "${{ steps.build_optiscaler.outputs.artifact_name }}"
743+
$releaseTag = "${{ steps.trigger_build.outputs.artifact_name }}"
669744
$repoName = "${{ github.repository }}"
670745
671746
# Format as JSON array for release notes with download URLs
@@ -695,8 +770,8 @@ jobs:
695770
env:
696771
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
697772
with:
698-
tag_name: ${{ steps.build_optiscaler.outputs.artifact_name }}
699-
release_name: ${{ steps.build_optiscaler.outputs.base_artifact_name }} - Latest Branch (${{ steps.find_branch.outputs.branch_name }})
773+
tag_name: ${{ steps.trigger_build.outputs.artifact_name }}
774+
release_name: ${{ steps.trigger_build.outputs.base_artifact_name }} - Latest Branch (${{ steps.find_branch.outputs.branch_name }})
700775
body: |
701776
**Automated Latest Branch Release**
702777
@@ -737,8 +812,8 @@ jobs:
737812
**Build Information:**
738813
- Source Branch: `${{ steps.find_branch.outputs.branch_name }}`
739814
- Source Commit: `${{ steps.find_branch.outputs.commit_sha }}`
740-
- Base Artifact: `${{ steps.build_optiscaler.outputs.base_artifact_name }}`
741-
- Release Tag: `${{ steps.build_optiscaler.outputs.artifact_name }}`
815+
- Base Artifact: `${{ steps.trigger_build.outputs.base_artifact_name }}`
816+
- Release Tag: `${{ steps.trigger_build.outputs.artifact_name }}`
742817
- Trigger: Manual (`${{ github.event_name }}`)
743818
- Our Workflow Run: [View Details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
744819
draft: false
@@ -803,7 +878,7 @@ jobs:
803878
$shortSha = "${{ steps.find_branch.outputs.short_sha }}"
804879
805880
$body = @{
806-
description = "🌟 Automated latest-branch releases for OptiScaler | Latest: ${{ steps.build_optiscaler.outputs.base_artifact_name }} from $branchName@$shortSha"
881+
description = "🌟 Automated latest-branch releases for OptiScaler | Latest: ${{ steps.trigger_build.outputs.base_artifact_name }} from $branchName@$shortSha"
807882
} | ConvertTo-Json
808883
809884
try {

0 commit comments

Comments
 (0)