Skip to content

Commit

Permalink
fix: BUILD_URI includes GitHub run attempt (#320)
Browse files Browse the repository at this point in the history
As you can retry github action run, the link needs to include it,
otherwise chalk report always links to the latest run, even if
that is not the job attempt which generated the report.
  • Loading branch information
miki725 authored Jun 6, 2024
1 parent 27f28d7 commit 12b170b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## On the `main` branch

### Fixes

- `BUILD_URI` for GitHub actions now includes run attempt
in the URI. Previously `BUILD_URI` always linked to
latest attempt.
([#320](https://github.com/crashappsec/chalk/pull/320))

## 0.4.2

**June 5, 2024**
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/ciGithub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ proc githubGetChalkTimeHostInfo(self: Plugin): ChalkDict {.cdecl.} =
GITHUB_REPOSITORY_ID = getEnv("GITHUB_REPOSITORY_ID")
GITHUB_REPOSITORY_OWNER_ID = getEnv("GITHUB_REPOSITORY_OWNER_ID")
GITHUB_RUN_ID = getEnv("GITHUB_RUN_ID")
GITHUB_RUN_ATTEMPT = getEnv("GITHUB_RUN_ATTEMPT")
GITHUB_API_URL = getEnv("GITHUB_API_URL")
GITHUB_ACTOR = getEnv("GITHUB_ACTOR")
GITHUB_EVENT_NAME = getEnv("GITHUB_EVENT_NAME")
Expand All @@ -60,11 +61,14 @@ proc githubGetChalkTimeHostInfo(self: Plugin): ChalkDict {.cdecl.} =

if (GITHUB_SERVER_URL != "" and GITHUB_REPOSITORY != "" and
GITHUB_RUN_ID != ""):
result.setIfNeeded("BUILD_URI", (
var uri = (
GITHUB_SERVER_URL.strip(leading = false, chars = {'/'}) & "/" &
GITHUB_REPOSITORY.strip(chars = {'/'}) & "/actions/runs/" &
GITHUB_RUN_ID
))
)
if GITHUB_RUN_ATTEMPT != "":
uri = uri.strip(chars = {'/'}) & "/attempts/" & GITHUB_RUN_ATTEMPT
result.setIfNeeded("BUILD_URI", uri)

if GITHUB_API_URL != "" and (
isSubscribedKey("BUILD_ORIGIN_KEY") or
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_github(copy_files: list[Path], chalk: Chalk, server_imds: str):
"BUILD_ID": "1658821493",
"BUILD_TRIGGER": "tag",
"BUILD_CONTACT": ["octocat"],
"BUILD_URI": "https://github.com/octocat/Hello-World/actions/runs/1658821493",
"BUILD_URI": "https://github.com/octocat/Hello-World/actions/runs/1658821493/attempts/5",
"BUILD_API_URI": server_imds,
"BUILD_ORIGIN_ID": "123",
"BUILD_ORIGIN_KEY": "abc",
Expand All @@ -80,6 +80,7 @@ def test_github(copy_files: list[Path], chalk: Chalk, server_imds: str):
"GITHUB_SERVER_URL": "https://github.com",
"GITHUB_REPOSITORY": "octocat/Hello-World",
"GITHUB_RUN_ID": "1658821493",
"GITHUB_RUN_ATTEMPT": "5",
"GITHUB_API_URL": server_imds,
"GITHUB_ACTOR": "octocat",
"GITHUB_REPOSITORY_ID": "123",
Expand Down

0 comments on commit 12b170b

Please sign in to comment.