Skip to content

Commit a6a9867

Browse files
committed
Link workflow summary metadata
1 parent 6946bc7 commit a6a9867

2 files changed

Lines changed: 83 additions & 8 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,55 @@ jobs:
5050
- name: Summary - CodeQL analysis started
5151
shell: pwsh
5252
run: |
53+
$refName = "${{ github.ref_name }}"
54+
$headRef = "${{ github.head_ref }}"
55+
$eventName = "${{ github.event_name }}"
56+
$prNumber = $null
57+
$actualBranchName = $refName
58+
$branchLink = "https://github.com/${{ github.repository }}/tree/$refName"
59+
$prLink = ""
60+
$workflowLink = "https://github.com/${{ github.repository }}/blob/${{ github.sha }}/.github/workflows/codeql.yml"
61+
$runLink = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
62+
63+
if ($refName -match '^(\d+)/(merge|head)$') {
64+
$prNumber = $Matches[1]
65+
# Use head_ref for the actual branch name if available
66+
if ($headRef) {
67+
$actualBranchName = $headRef
68+
}
69+
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
70+
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
71+
} elseif ($eventName -eq "pull_request") {
72+
# This is a pull request event
73+
$prNumber = "${{ github.event.pull_request.number }}"
74+
if ($headRef) {
75+
$actualBranchName = $headRef
76+
}
77+
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
78+
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
79+
}
80+
5381
$summary = @"
5482
## 🔒 CodeQL Security Analysis - Workflow Summary
5583
5684
### Analysis Configuration
5785
5886
| Property | Value |
5987
| --- | --- |
60-
| Repository | ``${{ github.repository }}`` |
61-
| Branch | ``${{ github.ref_name }}`` |
62-
| Language | ``${{ matrix.language }}`` |
63-
| Commit | ``${{ github.sha }}`` |
88+
| Repository | [``${{ github.repository }}``](https://github.com/${{ github.repository }}) |
89+
| Source Branch | [``$actualBranchName``]($branchLink) |
90+
"@
91+
92+
if ($prNumber) {
93+
$summary += "| Pull Request | [#$prNumber]($prLink) |`n"
94+
}
95+
96+
$summary += @"
97+
| Commit | [``${{ github.sha }}``](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |
98+
| Workflow | [``${{ github.workflow }}``]($workflowLink) |
99+
| Run | [``${{ github.run_id }}``]($runLink) |
100+
| Language | [``${{ matrix.language }}``](https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/#languages-and-compilers) |
101+
| Event | ``$eventName`` |
64102
"@
65103
66104
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8

.github/workflows/tests.yml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,56 @@ jobs:
4949
. scripts/utils.ps1
5050
$cmderVersion = Get-VersionStr
5151
52+
$refName = "${{ github.ref_name }}"
53+
$headRef = "${{ github.head_ref }}"
54+
$eventName = "${{ github.event_name }}"
55+
$prNumber = $null
56+
$actualBranchName = $refName
57+
$branchLink = "https://github.com/${{ github.repository }}/tree/$refName"
58+
$prLink = ""
59+
$workflowLink = "https://github.com/${{ github.repository }}/blob/${{ github.sha }}/.github/workflows/tests.yml"
60+
$runLink = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
61+
62+
if ($refName -match '^(\d+)/(merge|head)$') {
63+
$prNumber = $Matches[1]
64+
# Use head_ref for the actual branch name if available
65+
if ($headRef) {
66+
$actualBranchName = $headRef
67+
}
68+
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
69+
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
70+
} elseif ($eventName -eq "pull_request") {
71+
# This is a pull request event
72+
$prNumber = "${{ github.event.pull_request.number }}"
73+
if ($headRef) {
74+
$actualBranchName = $headRef
75+
}
76+
$branchLink = "https://github.com/${{ github.repository }}/tree/$actualBranchName"
77+
$prLink = "https://github.com/${{ github.repository }}/pull/$prNumber"
78+
}
79+
5280
$summary = @"
5381
## ✅ Run Tests - Workflow Summary
5482
5583
### Test Environment
5684
| Property | Value |
5785
| --- | --- |
58-
| Repository | ``${{ github.repository }}`` |
59-
| Branch | ``${{ github.ref_name }}`` |
60-
| Commit | ``${{ github.sha }}`` |
86+
| Repository | [``${{ github.repository }}``](https://github.com/${{ github.repository }}) |
87+
| Source Branch | [``$actualBranchName``]($branchLink) |
88+
"@
89+
90+
if ($prNumber) {
91+
$summary += "| Pull Request | [#$prNumber]($prLink) |`n"
92+
}
93+
94+
$summary += @"
95+
| Commit | [``${{ github.sha }}``](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |
96+
| Workflow | [``${{ github.workflow }}``]($workflowLink) |
97+
| Run | [``${{ github.run_id }}``]($runLink) |
6198
| Runner OS | ``${{ runner.os }}`` |
6299
| Cmder Version | **$cmderVersion** |
63100
| PowerShell Version | **$($PSVersionTable.PSVersion)** |
64-
| Event | ``${{ github.event_name }}`` |
101+
| Event | ``$eventName`` |
65102
"@
66103
67104
$summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8

0 commit comments

Comments
 (0)