mirror of
https://github.com/cmderdev/cmder.git
synced 2026-04-15 06:44:31 +08:00
Compare commits
29 Commits
dax/fix-gi
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddaa2f1c4e | ||
|
|
00a140dac9 | ||
|
|
75cd20b7ff | ||
|
|
dc7e1c144f | ||
|
|
55251f7cc3 | ||
|
|
0983e9b763 | ||
|
|
cb59bb54b0 | ||
|
|
c882ade42d | ||
|
|
dcbb0e9203 | ||
|
|
f3fa589ac3 | ||
|
|
32cf8767f5 | ||
|
|
03deb9d859 | ||
|
|
01d01c6a57 | ||
|
|
25ea725338 | ||
|
|
cbc7f53cd3 | ||
|
|
31e73cce59 | ||
|
|
2de93d1d55 | ||
|
|
aa801c2c17 | ||
|
|
1418da1c18 | ||
|
|
05b24c2173 | ||
|
|
f69c1db205 | ||
|
|
165ca3b05b | ||
|
|
be3d66d8a3 | ||
|
|
35c1cd6f42 | ||
|
|
07a2c6e5cd | ||
|
|
7cfa69fe74 | ||
|
|
74b089662c | ||
|
|
ed5ebfe5ba | ||
|
|
86d1cbcfa0 |
137
.github/workflows/build.yml
vendored
137
.github/workflows/build.yml
vendored
@@ -12,6 +12,7 @@ on:
|
||||
- "v*"
|
||||
pull_request:
|
||||
branches: [ "master", "development" ]
|
||||
workflow_dispatch:
|
||||
|
||||
#---------------------------------#
|
||||
# environment configuration #
|
||||
@@ -47,31 +48,48 @@ jobs:
|
||||
$cmderVersion = Get-VersionStr
|
||||
$buildTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
||||
|
||||
# Determine branch link (handle PR merge refs)
|
||||
$branchName = "${{ github.ref_name }}"
|
||||
# Determine branch and PR information
|
||||
$refName = "${{ github.ref_name }}"
|
||||
$headRef = "${{ github.head_ref }}"
|
||||
$eventName = "${{ github.event_name }}"
|
||||
$prNumber = $null
|
||||
$actualBranchName = $refName
|
||||
$branchLink = ""
|
||||
if ($branchName -match '^(\d+)/(merge|head)$') {
|
||||
# This is a PR merge/head ref, link to the PR
|
||||
$prLink = ""
|
||||
|
||||
# Check if this is a PR merge ref (e.g., "3061/merge")
|
||||
if ($refName -match '^(\d+)/(merge|head)$') {
|
||||
$prNumber = $Matches[1]
|
||||
$branchLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
|
||||
} elseif ("${{ github.event_name }}" -eq "pull_request") {
|
||||
# This is a pull request event, link to the PR
|
||||
$branchLink = "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
|
||||
# Use head_ref for the actual branch name if available
|
||||
if ($headRef) {
|
||||
$actualBranchName = $headRef
|
||||
}
|
||||
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
|
||||
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
|
||||
} elseif ($eventName -eq "pull_request") {
|
||||
# This is a pull request event
|
||||
$prNumber = "${{ github.event.pull_request.number }}"
|
||||
if ($headRef) {
|
||||
$actualBranchName = $headRef
|
||||
}
|
||||
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
|
||||
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
|
||||
} else {
|
||||
# Regular branch, link to the branch tree
|
||||
$branchLink = "https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}"
|
||||
$branchLink = "https://github.com/${{ github.repository }}/tree/$refName"
|
||||
}
|
||||
|
||||
$summary = @"
|
||||
## 📦 Build Cmder - Workflow Summary
|
||||
|
||||
<small>Build started: $buildTime</small>
|
||||
<small>Build started: ``$buildTime``</small>
|
||||
|
||||
### Repository Information
|
||||
| Property | Value |
|
||||
| --- | --- |
|
||||
| Repository | [``${{ github.repository }}``](https://github.com/${{ github.repository }}) |
|
||||
| Branch | [``$branchName``]($branchLink) |
|
||||
| Branch | [``$actualBranchName``]($branchLink) |
|
||||
$(if ($prNumber) { "| Pull Request | [#$prNumber]($prLink) |" })
|
||||
| Commit | [``${{ github.sha }}``](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |
|
||||
| Actor | [@${{ github.actor }}](https://github.com/${{ github.actor }}) |
|
||||
| Workflow | ``${{ github.workflow }}`` |
|
||||
@@ -79,18 +97,34 @@ jobs:
|
||||
|
||||
---
|
||||
|
||||
### 📁 Vendor Packages
|
||||
### 🗃️ Vendor Packages ([sources.json](vendor/sources.json))
|
||||
| Package | Version |
|
||||
| --- | --- |
|
||||
"@
|
||||
|
||||
# Read vendor sources.json and add to summary
|
||||
$vendorSources = Get-Content "vendor/sources.json" | ConvertFrom-Json
|
||||
$vendorSources = Get-Content -Raw "vendor/sources.json" | ConvertFrom-Json
|
||||
if ($vendorSources.Count -eq 0) {
|
||||
$summary += "`n| _No vendor packages found_ | |"
|
||||
} else {
|
||||
foreach ($vendor in $vendorSources) {
|
||||
$summary += "`n| ``$($vendor.name)`` | $($vendor.version) |"
|
||||
# Create release link based on vendor package
|
||||
$versionLink = "$($vendor.version)"
|
||||
if ($vendor.url) {
|
||||
# Extract owner/repo/tag from the URL and create release link
|
||||
# Handle both /releases/download/ and /archive/ URLs
|
||||
if ($vendor.url -match 'github\.com/([^/]+)/([^/]+)/(releases/download|archive)/([^/]+)') {
|
||||
$owner = $Matches[1]
|
||||
$repo = $Matches[2]
|
||||
$pathType = $Matches[3]
|
||||
$tag = $Matches[4]
|
||||
if ($pathType -eq 'archive') {
|
||||
$tag = $tag -replace '\.(?:tar\.gz|tgz|zip)$', ''
|
||||
}
|
||||
$versionLink = "[$($vendor.version)](https://github.com/$owner/$repo/releases/tag/$tag)"
|
||||
}
|
||||
}
|
||||
$summary += "`n| ``$($vendor.name)`` | $versionLink |"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +133,7 @@ jobs:
|
||||
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
|
||||
- name: Add MSBuild to PATH
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: Build Cmder Launcher
|
||||
shell: pwsh
|
||||
@@ -114,8 +148,6 @@ jobs:
|
||||
|
||||
---
|
||||
|
||||
### Build Status
|
||||
|
||||
✅ Cmder built successfully.
|
||||
|
||||
"@
|
||||
@@ -128,29 +160,33 @@ jobs:
|
||||
run: .\pack.ps1 -verbose
|
||||
|
||||
- name: Upload artifact (cmder.zip)
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: build/cmder.zip
|
||||
name: cmder.zip
|
||||
archive: false
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload artifact (cmder.7z)
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: build/cmder.7z
|
||||
name: cmder.7z
|
||||
archive: false
|
||||
|
||||
- name: Upload artifact (cmder_mini.zip)
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: build/cmder_mini.zip
|
||||
name: cmder_mini.zip
|
||||
archive: false
|
||||
|
||||
- name: Upload artifact (hashes.txt)
|
||||
uses: actions/upload-artifact@v6
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
path: build/hashes.txt
|
||||
name: hashes.txt
|
||||
archive: false
|
||||
|
||||
- name: Summary - Artifacts uploaded
|
||||
if: success()
|
||||
@@ -158,56 +194,29 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
$summary = @"
|
||||
# Source utility functions
|
||||
. scripts/utils.ps1
|
||||
|
||||
---
|
||||
$summary = @"
|
||||
|
||||
### 🗃️ Artifacts
|
||||
|
||||
| Artifact | Size | Download | Hash (SHA256) |
|
||||
| --- | --- | --- | --- |
|
||||
| Artifact | Size | Hash (SHA256) |
|
||||
| --- | --- | --- |
|
||||
"@
|
||||
|
||||
# Function to get artifact download URL with retry logic
|
||||
function Get-ArtifactDownloadUrl {
|
||||
param(
|
||||
[string]$ArtifactName,
|
||||
[int]$MaxRetries = 3,
|
||||
[int]$DelaySeconds = 2
|
||||
)
|
||||
# Get all files from the build directory (excluding directories and hidden files)
|
||||
if (Test-Path "build") {
|
||||
$buildFiles = Get-ChildItem -Path "build" -File | Where-Object { -not $_.Name.StartsWith('.') } | Sort-Object Name
|
||||
|
||||
for ($i = 0; $i -lt $MaxRetries; $i++) {
|
||||
try {
|
||||
# Use GitHub CLI to get artifact information
|
||||
$artifactsJson = gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" --jq ".artifacts[] | select(.name == `"$ArtifactName`")"
|
||||
|
||||
if ($artifactsJson) {
|
||||
$artifact = $artifactsJson | ConvertFrom-Json
|
||||
if ($artifact.archive_download_url) {
|
||||
return $artifact.archive_download_url
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Attempt $($i + 1) failed to get artifact URL for $ArtifactName : $_"
|
||||
}
|
||||
|
||||
if ($i -lt ($MaxRetries - 1)) {
|
||||
Start-Sleep -Seconds $DelaySeconds
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
$artifacts = @("cmder.zip", "cmder.7z", "cmder_mini.zip", "hashes.txt")
|
||||
foreach ($artifact in $artifacts) {
|
||||
$path = "build/$artifact"
|
||||
if (Test-Path $path) {
|
||||
$size = (Get-Item $path).Length / 1MB
|
||||
foreach ($file in $buildFiles) {
|
||||
$artifact = $file.Name
|
||||
$path = $file.FullName
|
||||
$sizeFormatted = Format-FileSize -Bytes $file.Length
|
||||
$hash = (Get-FileHash $path -Algorithm SHA256).Hash
|
||||
|
||||
# Try to get the actual artifact download URL
|
||||
$downloadUrl = Get-ArtifactDownloadUrl -ArtifactName $artifact
|
||||
$downloadUrl = Get-ArtifactDownloadUrl -ArtifactName $artifact -Repository "${{ github.repository }}" -RunId "${{ github.run_id }}"
|
||||
$warning = ""
|
||||
|
||||
if (-not $downloadUrl) {
|
||||
@@ -219,13 +228,13 @@ jobs:
|
||||
# Determine emoji based on file type
|
||||
if ($artifact -match '\.txt$') {
|
||||
$emoji = "📄"
|
||||
} elseif ($artifact -match '\.(zip|7z)$') {
|
||||
} elseif ($artifact -match '\.(zip|rar|7z)$') {
|
||||
$emoji = "🗄️"
|
||||
} else {
|
||||
$emoji = "📦"
|
||||
}
|
||||
|
||||
$summary += "`n| $emoji ``$artifact`` | $([math]::Round($size, 2)) MB | [📥 Download$warning]($downloadUrl) | ``$hash`` |"
|
||||
$summary += "`n| $emoji [``$artifact``$warning]($downloadUrl) | $sizeFormatted | ``$hash`` |"
|
||||
}
|
||||
}
|
||||
$summary += "`n"
|
||||
@@ -233,7 +242,7 @@ jobs:
|
||||
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
files: |
|
||||
build/cmder.zip
|
||||
|
||||
2
.github/workflows/codeql.yml
vendored
2
.github/workflows/codeql.yml
vendored
@@ -79,7 +79,7 @@ jobs:
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
- name: Add MSBuild to PATH
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
uses: microsoft/setup-msbuild@v3
|
||||
|
||||
- name: Build Cmder Launcher
|
||||
shell: pwsh
|
||||
|
||||
45
.github/workflows/tests.yml
vendored
45
.github/workflows/tests.yml
vendored
@@ -79,8 +79,11 @@ jobs:
|
||||
# Get vendor versions from sources.json
|
||||
$vendorInfo = @()
|
||||
$sources = Get-Content "vendor\sources.json" -Raw | ConvertFrom-Json
|
||||
$vendorDirs = $sources.PSObject.Properties | ForEach-Object { $_.Name }
|
||||
foreach ($dir in $vendorDirs) {
|
||||
foreach ($source in $sources) {
|
||||
$dir = $source.name
|
||||
if (-not $dir) {
|
||||
continue
|
||||
}
|
||||
$versionFile = "vendor/$dir/.cmderver"
|
||||
if (Test-Path $versionFile) {
|
||||
$version = Get-Content $versionFile -Raw
|
||||
@@ -100,7 +103,7 @@ jobs:
|
||||
if ($vendorInfo.Count -eq 0) {
|
||||
$summary += "_No vendor version information available._"
|
||||
} else {
|
||||
$summary += $vendorInfo -join '`n'
|
||||
$summary += $vendorInfo -join "`n"
|
||||
}
|
||||
)
|
||||
|
||||
@@ -121,34 +124,64 @@ jobs:
|
||||
|
||||
- name: Testing Clink Shell
|
||||
id: test-clink
|
||||
shell: pwsh
|
||||
run: |
|
||||
$startTime = Get-Date
|
||||
cmd /c vendor\init.bat /v /d /t
|
||||
$duration = [math]::Round(((Get-Date) - $startTime).TotalSeconds, 2)
|
||||
echo "duration=$duration" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: Summary - Clink Shell test
|
||||
if: success()
|
||||
shell: pwsh
|
||||
run: |
|
||||
"| Clink Shell | ✅ Passed | Cmd shell initialization |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
$duration = "${{ steps.test-clink.outputs.duration }}"
|
||||
if ($duration) {
|
||||
$duration = "$duration s"
|
||||
} else {
|
||||
$duration = "N/A"
|
||||
}
|
||||
"| Clink Shell | ✅ Passed | $duration |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
- name: Testing PowerShell
|
||||
id: test-powershell
|
||||
shell: pwsh
|
||||
run: |
|
||||
$startTime = Get-Date
|
||||
PowerShell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "$env:CMDER_DEBUG='1'; . 'vendor\profile.ps1'"
|
||||
$duration = [math]::Round(((Get-Date) - $startTime).TotalSeconds, 2)
|
||||
echo "duration=$duration" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: Summary - PowerShell test
|
||||
if: success()
|
||||
shell: pwsh
|
||||
run: |
|
||||
"| PowerShell | ✅ Passed | Profile script execution |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
$duration = "${{ steps.test-powershell.outputs.duration }}"
|
||||
if ($duration) {
|
||||
$duration = "$duration s"
|
||||
} else {
|
||||
$duration = "N/A"
|
||||
}
|
||||
"| PowerShell | ✅ Passed | $duration |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
- name: Testing Bash
|
||||
id: test-bash
|
||||
shell: pwsh
|
||||
run: |
|
||||
$startTime = Get-Date
|
||||
bash vendor/cmder.sh
|
||||
$duration = [math]::Round(((Get-Date) - $startTime).TotalSeconds, 2)
|
||||
echo "duration=$duration" >> $env:GITHUB_OUTPUT
|
||||
|
||||
- name: Summary - Bash test
|
||||
if: success()
|
||||
shell: pwsh
|
||||
run: |
|
||||
"| Bash | ✅ Passed | Bash environment initialization |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
$duration = "${{ steps.test-bash.outputs.duration }}"
|
||||
if ($duration) {
|
||||
$duration = "$duration s"
|
||||
} else {
|
||||
$duration = "N/A"
|
||||
}
|
||||
"| Bash | ✅ Passed | $duration |" | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
|
||||
- name: Summary - All tests completed
|
||||
if: success()
|
||||
|
||||
10
.github/workflows/vendor.yml
vendored
10
.github/workflows/vendor.yml
vendored
@@ -45,10 +45,10 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
$currentVersion = (Get-Content .\vendor\sources.json | ConvertFrom-Json)
|
||||
$currentVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json)
|
||||
. .\scripts\update.ps1 -verbose
|
||||
Set-GHVariable -Name COUNT_UPDATED -Value $count
|
||||
$newVersion = (Get-Content .\vendor\sources.json | ConvertFrom-Json)
|
||||
$newVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json)
|
||||
$listUpdated = ""
|
||||
$updateMessage = "| Name | Old Version | New Version |`n| :--- | ---- | ---- |`n"
|
||||
foreach ($s in $newVersion) {
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
if ($count -eq 0) { return }
|
||||
Set-GHVariable -Name LIST_UPDATED -Value $listUpdated.Trim(', ')
|
||||
|
||||
echo "UPDATE_MESSAGE<<<EOF`n$updateMessage`n<EOF" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||
echo "UPDATE_MESSAGE<<EOF`n$updateMessage`nEOF" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||
|
||||
- name: Summary - Update check results
|
||||
shell: pwsh
|
||||
@@ -88,7 +88,7 @@ jobs:
|
||||
|
||||
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8
|
||||
|
||||
- uses: peter-evans/create-pull-request@v7
|
||||
- uses: peter-evans/create-pull-request@v8
|
||||
if: env.COUNT_UPDATED > 0
|
||||
with:
|
||||
title: 'Updates to `${{ env.COUNT_UPDATED }}` vendored dependencies'
|
||||
@@ -105,7 +105,7 @@ jobs:
|
||||
if: env.COUNT_UPDATED > 0
|
||||
shell: pwsh
|
||||
run: |
|
||||
$Summary = @"
|
||||
$summary = @"
|
||||
### 🎉 Pull Request Created
|
||||
|
||||
A pull request has been created to update the vendor dependencies.
|
||||
|
||||
@@ -70,7 +70,7 @@ if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
|
||||
foreach ($t in $targets.GetEnumerator()) {
|
||||
Create-Archive "$cmderRoot" "$saveTo\$($t.Name)" $t.Value
|
||||
$hash = (Digest-Hash "$saveTo\$($t.Name)")
|
||||
Add-Content -path "$saveTo\hashes.txt" -value ($t.Name + ' ' + $hash)
|
||||
Add-Content -path "$saveTo\hashes.txt" -value ($t.Name + "`t" + $hash)
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
|
||||
@@ -249,3 +249,107 @@ function Download-File {
|
||||
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
|
||||
$wc.DownloadFile($Url, $File)
|
||||
}
|
||||
|
||||
function Format-FileSize {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Formats a file size in bytes to a human-readable string using binary units.
|
||||
|
||||
.DESCRIPTION
|
||||
Converts file sizes to appropriate binary units (B, KiB, MiB, GiB) for better readability.
|
||||
|
||||
.PARAMETER Bytes
|
||||
The file size in bytes to format.
|
||||
|
||||
.EXAMPLE
|
||||
Format-FileSize -Bytes 1024
|
||||
Returns "1.00 KiB"
|
||||
|
||||
.EXAMPLE
|
||||
Format-FileSize -Bytes 15728640
|
||||
Returns "15.00 MiB"
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[double]$Bytes
|
||||
)
|
||||
|
||||
if ($Bytes -ge 1GB) {
|
||||
return "{0:N2} GiB" -f ($Bytes / 1GB)
|
||||
} elseif ($Bytes -ge 1MB) {
|
||||
return "{0:N2} MiB" -f ($Bytes / 1MB)
|
||||
} elseif ($Bytes -ge 1KB) {
|
||||
return "{0:N2} KiB" -f ($Bytes / 1KB)
|
||||
} else {
|
||||
return "{0:N0} B" -f $Bytes
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ArtifactDownloadUrl {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieves the download URL for a GitHub Actions artifact with retry logic.
|
||||
|
||||
.DESCRIPTION
|
||||
Uses the GitHub CLI to fetch artifact information from the GitHub API with automatic retries.
|
||||
Falls back to returning $null if all attempts fail.
|
||||
|
||||
.PARAMETER ArtifactName
|
||||
The name of the artifact to retrieve the download URL for.
|
||||
|
||||
.PARAMETER Repository
|
||||
The GitHub repository in the format "owner/repo".
|
||||
|
||||
.PARAMETER RunId
|
||||
The GitHub Actions workflow run ID.
|
||||
|
||||
.PARAMETER MaxRetries
|
||||
Maximum number of retry attempts. Default is 3.
|
||||
|
||||
.PARAMETER DelaySeconds
|
||||
Delay in seconds between retry attempts. Default is 2.
|
||||
|
||||
.EXAMPLE
|
||||
Get-ArtifactDownloadUrl -ArtifactName "cmder.zip" -Repository "cmderdev/cmder" -RunId "123456789"
|
||||
|
||||
.EXAMPLE
|
||||
Get-ArtifactDownloadUrl -ArtifactName "build-output" -Repository "owner/repo" -RunId "987654321" -MaxRetries 5 -DelaySeconds 3
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ArtifactName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Repository,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$RunId,
|
||||
|
||||
[int]$MaxRetries = 3,
|
||||
[int]$DelaySeconds = 2
|
||||
)
|
||||
|
||||
for ($i = 0; $i -lt $MaxRetries; $i++) {
|
||||
try {
|
||||
# Use GitHub CLI to get artifact information
|
||||
$artifactsJson = gh api "repos/$Repository/actions/runs/$RunId/artifacts" --jq ".artifacts[] | select(.name == `"$ArtifactName`")"
|
||||
|
||||
if ($artifactsJson) {
|
||||
$artifact = $artifactsJson | ConvertFrom-Json
|
||||
if ($artifact.id) {
|
||||
# Construct browser-accessible GitHub Actions artifact download URL
|
||||
# Format: https://github.com/owner/repo/actions/runs/{run_id}/artifacts/{artifact_id}
|
||||
return "https://github.com/$Repository/actions/runs/$RunId/artifacts/$($artifact.id)"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Attempt $($i + 1) failed to get artifact URL for $ArtifactName : $_"
|
||||
}
|
||||
|
||||
if ($i -lt ($MaxRetries - 1)) {
|
||||
Start-Sleep -Seconds $DelaySeconds
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user