-
Notifications
You must be signed in to change notification settings - Fork 27
Annotate hash mismatches when Determinate features are enabled #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e528e29
beep boop
grahamc 5454c6b
bep
grahamc a41118a
?
grahamc 560caa9
?
grahamc 66d8ccf
Render hash mismatches as feedback
gustavderdrache f46552d
Escape all the metacharacters
gustavderdrache dca7cc6
Cleanup child processes
gustavderdrache ad5d306
Use NUL-terminated ls-files output
gustavderdrache 8503756
Downgrade warning to info
gustavderdrache 99e2bd0
Update messaging
gustavderdrache 300c83d
Update dist
gustavderdrache 6c9a2e8
Don't leak file handles
gustavderdrache da6d450
Remove superfluous punctuation
gustavderdrache 9cd39de
Make extra sure we can hit curl with a SIGTERM
gustavderdrache c256f70
Be more selective about event ingestion
gustavderdrache 85da126
Use determinate-nixd's hash fix feature
gustavderdrache f09b111
Feature gate annotations
gustavderdrache 4ce71dd
Add annotation telemetry
gustavderdrache 5947325
build
gustavderdrache 00365ee
Change annotateMismatches() call order
gustavderdrache 06d97ff
Fix property name
gustavderdrache 030ef1f
Remove markdown
gustavderdrache 7f64b08
Add more logging & telemetry
gustavderdrache b8a2731
pnpm run all
gustavderdrache 2650528
missed a spot
gustavderdrache 0a7860e
Remove .drv when rendering pretty derivation names
gustavderdrache f4819c9
Don't log determinate-nixd output when fixing hashes
gustavderdrache File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import * as core from "@actions/core"; | ||
|
|
||
| import type { Fix, FixHashesOutputV1, Mismatch } from "./fixHashes.js"; | ||
|
|
||
| function prettyDerivation(derivation: string): string { | ||
| return derivation.replace(/\/nix\/store\/\w+-/, "").replace(/.drv$/, ""); | ||
| } | ||
|
|
||
| function annotateSingle( | ||
| file: string, | ||
| line: number, | ||
| { derivation, replacement }: Mismatch, | ||
| ): void { | ||
| const pretty = prettyDerivation(derivation); | ||
| core.error(`To correct the hash mismatch for ${pretty}, use ${replacement}`, { | ||
| file, | ||
| startLine: line, | ||
| }); | ||
| } | ||
|
|
||
| function annotateMultiple( | ||
| file: string, | ||
| { line, found, mismatches }: Fix, | ||
| ): void { | ||
| const matches = mismatches | ||
| .map(({ derivation, replacement }) => { | ||
| const pretty = prettyDerivation(derivation); | ||
| return `* For the derivation ${pretty}, use ${replacement}`; | ||
| }) | ||
| .join("\n"); | ||
|
|
||
| core.error( | ||
| `There are multiple replacements for the expression ${found}:\n${matches}`, | ||
| { | ||
| file, | ||
| startLine: line, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| function annotate(file: string, fix: Fix): void { | ||
| if (fix.mismatches.length === 1) { | ||
| annotateSingle(file, fix.line, fix.mismatches[0]); | ||
| } else { | ||
| annotateMultiple(file, fix); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Annotates fixed-output derivation hash mismatches using GitHub Actions' | ||
| * | ||
| * @param output The output of `determinate-nixd fix hashes --json` | ||
| * @returns The number of annotations reported to the user | ||
| */ | ||
| export function annotateMismatches(output: FixHashesOutputV1): number { | ||
| let count = 0; | ||
|
|
||
| for (const { file, fixes } of output.files) { | ||
| for (const fix of fixes) { | ||
| annotate(file, fix); | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { getExecOutput } from "@actions/exec"; | ||
|
|
||
| export interface Mismatch { | ||
| readonly derivation: string; | ||
| readonly replacement: string; | ||
| } | ||
|
|
||
| export interface Fix { | ||
| readonly line: number; | ||
| readonly found: string; | ||
| readonly mismatches: readonly Mismatch[]; | ||
| } | ||
|
|
||
| export interface FileFix { | ||
| readonly file: string; | ||
| readonly fixes: readonly Fix[]; | ||
| } | ||
|
|
||
| export interface FixHashesOutputV1 { | ||
| readonly version: "v1"; | ||
| readonly files: readonly FileFix[]; | ||
| } | ||
|
|
||
| export async function getFixHashes(): Promise<FixHashesOutputV1> { | ||
| const output = await getExecOutput("determinate-nixd", [ | ||
| "fix", | ||
| "hashes", | ||
| "--json", | ||
| ]); | ||
|
|
||
| if (output.exitCode !== 0) { | ||
| throw new Error( | ||
| `determinate-nixd fix hashes returned non-zero exit code ${output.exitCode} with the following error output:\n${output.stderr}`, | ||
| ); | ||
| } | ||
|
|
||
| return JSON.parse(output.stdout); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without silent: true the log gets littered with ugly output: