KEMBAR78
Fix job log resolution to skip legacy logs in favour of normal/new ones by babakks · Pull Request #10769 · cli/cli · GitHub
Skip to content

Conversation

@babakks
Copy link
Member

@babakks babakks commented Apr 11, 2025

Description

Fixes #10768

This PR changes the job log resolution to skip legacy logs in favour of normal/new ones, if both of them exist in the downloaded ZIP archive. A test case is added to the unit tests (i.e., Test_attachRunLog) to verify the expected behaviour.

However, since the whole situation is not a common thing (at least I couldn't find a real ZIP archive with both new and legacy files and no step logs), I didn't add a test case to the overall command behaviour tests (i.e., TestViewRun).

Acceptance Criteria

1. Both new and legacy job run log files in the archive

Given I have a job run whose logs include both new and legacy job run logs
When I run gh run view --logs <JOB-ID>
Then the content of the new job run log file is displayed

Verification

This A/C is a bit tricky to verify, because I couldn't find such a ZIP archive that doesn't have the step logs. Note that when step logs are present, the CLI uses them to compile the log trail so we cannot see what was resolved for the job run log. Here, to quickly get around this we can modify the ZIP file and remove the steps.

Run 14140827421 is an example, with the following ZIP archive content:

$ unzip -l ~/.cache/gh/run-log-14140827421-1743212015.zip
Archive:  run-log-14140827421-1743212015.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      795  2025-04-01 23:20   issue-auto/2_label incoming issue.txt
      510  2025-04-01 23:20   -2147483648_issue-auto.txt
     1289  2025-04-01 23:20   issue-auto/1_Set up job.txt
        0  2025-04-01 23:20   issue-auto/
     2567  2025-04-01 23:20   0_issue-auto.txt
       58  2025-04-01 23:20   issue-auto/3_Complete job.txt
---------                     -------
     5219                     6 files

To remove the step logs, we should download the logs by a dummy gh run view --log call:

gh run view -R cli/cli --log 14140827421 > /dev/null
zip ~/.cache/gh/run-log-14140827421-1743212015.zip -d 'issue-auto/*'

The ZIP file should look like this:

unzip -l ~/.cache/gh/run-log-14140827421-1743212015.zip
Archive:  run-log-14140827421-1743212015.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      510  2025-04-01 23:20   -2147483648_issue-auto.txt
     2567  2025-04-01 23:20   0_issue-auto.txt
---------                     -------
     3077                     2 files

Now we can verify the implementation (should echo "PASS"):

gh run view -R cli/cli --job=39621793744 --log | cut -f3- -d$'\t' > got.txt
unzip -p ~/.cache/gh/run-log-14140827421-1743212015.zip 0_issue-auto.txt > want.txt
diff got.txt want.txt && echo PASS || echo FAIL

2. Only new job run log files in the archive

Given I have a job run whose logs include only the new job run logs
When I run gh run view --logs <JOB-ID>
Then the content of the new job run log file is displayed

Verification

Run 14286831526 is an example, with the following ZIP archive content:

$ unzip -l ~/.cache/gh/run-log-14286831526-1743896132.zip
Archive:  run-log-14286831526-1743896132.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     2150  1980-00-00 00:00   0_issue-auto.txt
      411  1980-00-00 00:00   issue-auto/system.txt
---------                     -------
     2561                     2 files

To verify (should echo "PASS"):

gh run view -R cli/cli --job=40042868503 --log | cut -f3- -d$'\t' > got.txt
unzip -p ~/.cache/gh/run-log-14286831526-1743896132.zip 0_issue-auto.txt > want.txt
diff got.txt want.txt && echo PASS || echo FAIL

3. Only legacy job run log files in the archive

Given I have a job run whose logs include only the legacy job run logs
When I run gh run view --logs <JOB-ID>
Then the content of the legacy job run log file is displayed

Verification

Run 14129890654 is an example, with the following ZIP archive content:

$ unzip -l ~/.cache/gh/run-log-14129890654-1743168077.zip
Archive:  run-log-14129890654-1743168077.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      300  2025-04-01 23:18   -2147483648_issue.txt
        0  2025-04-01 23:18   issue/
      314  2025-04-01 23:18   -2139095040_pull_request.txt
        0  2025-04-01 23:18   pull_request/
---------                     -------
      614                     4 files

To verify (should echo "PASS"):

gh run view -R cli/cli --job=39587315425 --log | cut -f3- -d$'\t' > got.txt
unzip -p ~/.cache/gh/run-log-14129890654-1743168077.zip -2147483648_issue.txt > want.txt
diff got.txt want.txt && echo PASS || echo FAIL

babakks added 3 commits April 11, 2025 12:39
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>

This is to make sure we do not pick up the wrong file if there is a
`.txt` sequence in the middle of a job name.
@babakks babakks requested a review from a team as a code owner April 11, 2025 12:52
@babakks babakks linked an issue Apr 11, 2025 that may be closed by this pull request
@babakks babakks requested a review from BagToad April 11, 2025 12:52
@babakks babakks temporarily deployed to cli-automation April 11, 2025 12:52 — with GitHub Actions Inactive
@williammartin williammartin self-requested a review April 11, 2025 13:01
@williammartin
Copy link
Member

williammartin commented Apr 11, 2025

However, since the whole situation is not a common thing (at least I couldn't find a real ZIP archive with both new and legacy files and no step logs), I didn't add a test case to the overall command behaviour tests (i.e., TestViewRun).

If you couldn't find a real zip archive, how did you discover this case? Do you mean, you found one at one point but no longer can?

Copy link
Member

@williammartin williammartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clear to me. Thanks for the nice acceptance. One question to be addressed to make sure it's clear how you came across this case.

Comment on lines +674 to +678
jobLog := matchFileInZIPArchive(rlz, jobLogFilenameRegexp(job))
if jobLog == nil {
jobLog = matchFileInZIPArchive(rlz, legacyJobLogFilenameRegexp(job))
}
jobs[i].Log = jobLog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR but when jobLog == nil after both attempts, this really feels like we should try to do:

#7643

Very annoying that things are silently not there.

@babakks
Copy link
Member Author

babakks commented Apr 11, 2025

If you couldn't find a real zip archive, how did you discover this case? Do you mean, you found one at one point but no longer can?

Actually I found a no-so-perfect case for this (the one in the issue description), but since that case also contains the step logs (and step logs are the preferred source of logs for CLI), the problem wouldn't surface to the user. So, a perfect case for this issue to surface would be a ZIP like the following but I couldn't find such a case:

ZIP/
├── 0_jobname.txt
└── -9999999999_jobname.txt

Signed-off-by: Babak K. Shandiz <babakks@github.com>
@williammartin williammartin merged commit 408e21e into trunk Apr 11, 2025
16 checks passed
@williammartin williammartin deleted the babakks/fix-job-log-resolution branch April 11, 2025 14:16
Copy link

@alstonaaron1952 alstonaaron1952 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reruns

Copy link

@alstonaaron1952 alstonaaron1952 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files check

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 10, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.69.0` -> `v2.72.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.72.0`](https://github.com/cli/cli/releases/tag/v2.72.0): GitHub CLI 2.72.0

[Compare Source](cli/cli@v2.71.2...v2.72.0)

#### :accessibility: Accessibility public preview

This release marks the public preview of several accessibility improvements to the GitHub CLI that have been under development over the past year in partnership with our friends at [Charm](https://github.com/charmbracelet) including:

-   customizable and contrasting colors
-   non-interactive user input prompting
-   text-based spinners

These new experiences are captured in a new `gh a11y` help topic command, which goes into greater detail into the motivation behind each of them as well as opt-in configuration settings / environment variables.

We would like you to share your feedback and join us on this journey through one of [GitHub Accessibility feedback channels](https://accessibility.github.com/feedback)! 🙌

#### What's Changed

##### ✨ Features

-   Introduce `gh accessibility` help topic highlighting GitHub CLI accessibility experiences by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10890
-   \[gh pr view] Support `closingIssuesReferences` JSON field by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10544

##### 🐛 Fixes

-   Fix expected error output of `TestRepo/repo-set-default` by [@&#8203;aconsuegra](https://github.com/aconsuegra) in cli/cli#10884
-   Ensure accessible password and auth token prompters disable echo mode by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10885
-   Fix: Accessible multiselect prompt respects default selections by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10901

#### New Contributors

-   [@&#8203;aconsuegra](https://github.com/aconsuegra) made their first contribution in cli/cli#10884

**Full Changelog**: cli/cli@v2.71.2...v2.72.0

### [`v2.71.2`](https://github.com/cli/cli/releases/tag/v2.71.2): GitHub CLI 2.71.2

[Compare Source](cli/cli@v2.71.1...v2.71.2)

#### What's Changed

-   Fix pr create when push.default tracking and no merge ref by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10863

**Full Changelog**: cli/cli@v2.71.1...v2.71.2

### [`v2.71.1`](https://github.com/cli/cli/releases/tag/v2.71.1): GitHub CLI 2.71.1

[Compare Source](cli/cli@v2.71.0...v2.71.1)

#### What's Changed

-   Fix pr create when branch name contains slashes by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10859

**Full Changelog**: cli/cli@v2.71.0...v2.71.1

### [`v2.71.0`](https://github.com/cli/cli/releases/tag/v2.71.0): GitHub CLI 2.71.0

[Compare Source](cli/cli@v2.70.0...v2.71.0)

#### What's Changed

##### ✨ Features

-   `gh pr create`: Support Git's `@{push}` revision syntax for determining head ref by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10513
-   Introduce option to opt-out of spinners by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10773
-   Update configuration support for accessible colors by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10820
-   `gh config`: add config settings for accessible prompter and disabling spinner by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10846

##### 🐛 Fixes

-   Fix multi pages search for gh search by [@&#8203;leudz](https://github.com/leudz) in cli/cli#10767
-   Fix: `project` commands use shared progress indicator by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10817
-   Issue commands should parse args early by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10811
-   Feature detect v1 projects on `issue view` by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10813
-   Feature detect v1 projects on non web-mode `issue create` by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10815
-   Feature detect v1 projects on web mode issue create by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10818
-   Feature detect v1 projects on issue edit by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10819

##### 📚 Docs & Chores

-   Refactor Sigstore verifier logic by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10750

##### :dependabot: Dependencies

-   chore(deps): bump github.com/sigstore/sigstore-go from 0.7.1 to 0.7.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10787
-   Bump google.golang.org/grpc from 1.71.0 to 1.71.1 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10758

#### New Contributors

-   [@&#8203;leudz](https://github.com/leudz) made their first contribution in cli/cli#10767

**Full Changelog**: cli/cli@v2.70.0...v2.71.0

### [`v2.70.0`](https://github.com/cli/cli/releases/tag/v2.70.0): GitHub CLI 2.70.0

[Compare Source](cli/cli@v2.69.0...v2.70.0)

#### Accessibility

This release contains dark shipped changes that are part of a larger GitHub CLI accessibility preview still under development.  More information about these will be announced later this month including various channels to work with GitHub and GitHub CLI maintainers on shaping these experiences.

##### Ensure table headers are thematically contrasting

[#&#8203;8292](cli/cli#8292) is a long time issue where table headers were difficult to see in terminals with light background.  Ahead of the aforementioned preview, `v2.70.0` has shipped changes that improve the out-of-the-box experience based on terminal background detection.

The following screenshots demonstrate the Mac Terminal using the Basic profile, which responds to user's appearance preferences:

<img width="1512" alt="Screenshot of gh repo list in light background terminal" src="https://github.com/user-attachments/assets/87413dde-eec8-43eb-9c16-dc84f8249ddf" />

<img width="1512" alt="Screenshot of gh repo list in dark background terminal" src="https://github.com/user-attachments/assets/7430b42c-7267-402b-b565-a296beb4d5ea" />

For more information including demos from various official distributions, see [#&#8203;10649](cli/cli#10649).

#### What's Changed

##### ✨ Features

-   Update go-gh and document available sprig funcs by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10680
-   Introducing experimental support for rendering markdown with customizable, accessible colors by [@&#8203;andyfeller](https://github.com/andyfeller) [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#10680
-   Ensure table datetime columns have thematic, customizable muted text by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10709
-   Ensure table headers are thematically contrasting by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10649
-   Introduce configuration setting for displaying issue and pull request labels in rich truecolor by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10720
-   Ensure muted text is thematic and customizable by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10737
-   \[gh repo create] Show host name in repo creation prompts by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10516
-   Introduce accessible prompter for screen readers (preview) by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10710

##### 🐛 Fixes

-   `run list`: do not fail on organization/enterprise ruleset imposed workflows by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10660
-   Implement safeguard for `gh alias delete` test, prevent wiping out GitHub CLI configuration by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#10683
-   Pin third party actions to commit sha by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10731
-   Fallback to job run logs when step logs are missing by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10740
-   \[gh ext] Fix `GitKind` extension directory path by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10609
-   Fix job log resolution to skip legacy logs in favour of normal/new ones by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10769

##### 📚 Docs & Chores

-   `./script/sign` cleanup by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10599
-   Fix typos in CONTRIBUTING.md by [@&#8203;rylwin](https://github.com/rylwin) in cli/cli#10657
-   Improve `gh at verify --help`, document json output by [@&#8203;phillmv](https://github.com/phillmv) in cli/cli#10685
-   Acceptance test issue/pr create/edit with project by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10707
-   Escape dots in regexp pattern in `README.md` by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10742
-   Simplify cosign verification example by not using a regex. by [@&#8203;kommendorkapten](https://github.com/kommendorkapten) in cli/cli#10759
-   Document UNKNOWN STEP in run view by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10770

##### :dependabot: Dependencies

-   Update github.com/sigstore/sigstore-go to 0.7.1 and fix breaking function change by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10749

#### New Contributors

-   [@&#8203;rylwin](https://github.com/rylwin) made their first contribution in cli/cli#10657

**Full Changelog**: cli/cli@v2.69.0...v2.70.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yNTkuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI2NC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve to new job run log when both old and new logs are present

4 participants