Repository navigation
Deploy the site in a job of its own, and fix the weekly tool version and OSV checks #261
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| import os | ||
| import pathlib | ||
| import re | ||
| import shlex | ||
| import sys | ||
| import time | ||
| import urllib.request | ||
|
|
@@ -224,20 +225,62 @@ def renderer(now): | |
| return [(RENDERER_PROJECT, pinned) + due(pinned, released, now)] | ||
|
|
||
|
|
||
| def npm_packages(texts, now): | ||
| """`npm install package@version` - asked of the npm registry.""" | ||
| # An npm install that names no version is a failure, not a line skipped: | ||
| # without this a pin taken off the command would take the package off this | ||
| # check with it, and the run would stay green (review of #205). | ||
| # The options of npm install the workflows pass a value to, so the word after | ||
| # one is that value and not a package. | ||
| NPM_VALUE_OPTIONS = {"--prefix", "--registry", "--tag", "--cache", "-C"} | ||
|
|
||
| # What starts an argument that names files of this run rather than a package of | ||
| # the registry: a path, or a shell variable holding one. | ||
| LOCAL_ARGUMENT = (".", "/", "~", "$") | ||
|
|
||
|
|
||
| def npm_pins(texts): | ||
| """Every registry package an `npm install` in the workflows names, with its pin. | ||
|
|
||
| Only a command counts: a line, or a part of one after &&, ||, ; or |, whose | ||
| first two words are `npm install`. A sentence that mentions npm install is | ||
| not one. `echo "... make npm install give people an older tfg"` in npm.yml | ||
| stopped this whole check on 2026-11-16 and 2026-11-23 before it read a pin. | ||
|
|
||
| An argument that is a path or a variable installs files this run built, so | ||
| there is no registry to ask about it. A registry package that names no | ||
| version is a failure, not a line skipped: without this a pin taken off the | ||
| command would take the package off this check with it, and the run would | ||
| stay green (review of #205). | ||
| """ | ||
| found = {} | ||
| for name, text in texts.items(): | ||
| for line in text.splitlines(): | ||
| if "npm install" not in line or line.lstrip().startswith("#"): | ||
| command = re.sub(r"^(-\s*)?run:\s*", "", line.strip()) | ||
| if command.startswith("#"): | ||
| continue | ||
| m = re.search(r"\s([@\w./-]+)@(\d[\w.+-]*)\s*$", line) | ||
| if not m: | ||
| raise RuntimeError(f"{name} runs an npm install that pins no version: {line.strip()}") | ||
| found[m.group(1)] = m.group(2) | ||
| for part in re.split(r"&&|\|\||;|\|", command): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not split operators inside quoted arguments. For Use quote-aware tokenization before separating commands. Preserve operators inside quoted arguments, and add this case to the parser test.
|
||
| if part.split()[:2] != ["npm", "install"]: | ||
| continue | ||
| try: | ||
| words = shlex.split(part)[2:] | ||
| except ValueError as exc: | ||
| raise RuntimeError(f"{name} runs an npm install this cannot read ({exc}): {line.strip()}") from exc | ||
| value_next = False | ||
| for word in words: | ||
| if value_next: | ||
| value_next = False | ||
| continue | ||
| if word in NPM_VALUE_OPTIONS: | ||
| value_next = True | ||
| continue | ||
| if word.startswith("-") or word.startswith(LOCAL_ARGUMENT): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recognize local tarballs without a dot prefix. For Recognize local tarball suffixes before checking registry versions. Add a test that retains the
|
||
| continue | ||
| m = re.fullmatch(r"(@?[\w./-]+)@(\d[\w.+-]*)", word) | ||
| if not m: | ||
| raise RuntimeError(f"{name} runs an npm install that pins no version for {word}: {line.strip()}") | ||
| found[m.group(1)] = m.group(2) | ||
| return found | ||
|
|
||
|
|
||
| def npm_packages(texts, now): | ||
| """`npm install package@version` - asked of the npm registry.""" | ||
| found = npm_pins(texts) | ||
| rows = [] | ||
| for package, pinned in sorted(found.items()): | ||
| times = ask(f"https://registry.npmjs.org/{package}")["time"] | ||
|
|
@@ -276,22 +319,31 @@ def main(): | |
| now = datetime.datetime.now(datetime.timezone.utc) | ||
| texts = workflow_text() | ||
| rows = [] | ||
| failed = 0 | ||
| # Every check runs even after one fails. A failure that ended the run left | ||
| # every pin after it unread, and on 2026-11-16 and 2026-11-23 that was all | ||
| # of them while the job said only what the first failure was. | ||
| for check in (lambda: go_tools(texts, now), lambda: go_toolchain(texts), lambda: renderer(now), | ||
| lambda: npm_packages(texts, now), lambda: held(texts)): | ||
| try: | ||
| rows.extend(check()) | ||
| except Exception as exc: # noqa: BLE001 - any failure here has to be loud | ||
| failed += 1 | ||
| print(f"FAIL: {exc}") | ||
| print("Run the workflow again. If it fails the same way, the registry or the pin") | ||
| print("named above has changed shape, and this script has to follow it.") | ||
| return 1 | ||
|
|
||
| for name, pinned, state, _ in rows: | ||
| print(f" {name:<42} {pinned:<10} {state}") | ||
| behind = [(name, pinned, to) for name, pinned, _, to in rows if to] | ||
|
|
||
| print() | ||
| if failed: | ||
| print(f"{failed} check(s) failed, and the pins they read are not in the list above.") | ||
| print("Run the workflow again. If it fails the same way, the registry or the pin") | ||
| print("named above has changed shape, and this script has to follow it.") | ||
| print() | ||
| if not behind: | ||
| if failed: | ||
| return 1 | ||
| print(f"all {len(rows)} pin(s) are current or held on purpose") | ||
| return 0 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package guard | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/goccy/go-yaml" | ||
| ) | ||
|
|
||
| // pagesStep is the part of a workflow step this guard reads. | ||
| type pagesStep struct { | ||
| ID string `yaml:"id"` | ||
| Uses string `yaml:"uses"` | ||
| ContinueOnError bool `yaml:"continue-on-error"` | ||
| } | ||
|
|
||
| // pagesJob is the part of a workflow job this guard reads. | ||
| type pagesJob struct { | ||
| Needs any `yaml:"needs"` | ||
| Steps []pagesStep `yaml:"steps"` | ||
| } | ||
|
|
||
| // pagesDeployProblems is what is wrong with how a workflow uploads and deploys | ||
| // the site: nothing when the deployment runs in a job of its own, after the | ||
| // job that uploads, and asks for the artifact more than once. | ||
| func pagesDeployProblems(body []byte) []string { | ||
| var workflow struct { | ||
| Jobs map[string]pagesJob `yaml:"jobs"` | ||
| } | ||
| if err := yaml.Unmarshal(body, &workflow); err != nil { | ||
| return []string{"the workflow does not parse: " + err.Error()} | ||
| } | ||
| uploads, deploys := map[string]bool{}, map[string][]pagesStep{} | ||
| for name, job := range workflow.Jobs { | ||
| for _, s := range job.Steps { | ||
| switch { | ||
| case strings.HasPrefix(s.Uses, "actions/upload-pages-artifact@"): | ||
| uploads[name] = true | ||
| case strings.HasPrefix(s.Uses, "actions/deploy-pages@"): | ||
| deploys[name] = append(deploys[name], s) | ||
| } | ||
| } | ||
| } | ||
| if len(uploads) == 0 || len(deploys) == 0 { | ||
| return []string{"no job uploads the site or none deploys it, so there is nothing here to check"} | ||
| } | ||
| var problems []string | ||
| for name, steps := range deploys { | ||
| if uploads[name] { | ||
| problems = append(problems, "the job "+name+" uploads the site and deploys it, and in one job the "+ | ||
| "lookup by name misses the artifact uploaded a moment before") | ||
| } | ||
| needs := map[string]bool{} | ||
| switch n := workflow.Jobs[name].Needs.(type) { | ||
| case string: | ||
| needs[n] = true | ||
| case []any: | ||
| for _, v := range n { | ||
| if s, ok := v.(string); ok { | ||
| needs[s] = true | ||
| } | ||
| } | ||
| } | ||
| for up := range uploads { | ||
| if !needs[up] { | ||
| problems = append(problems, "the job "+name+" does not wait for "+up+", which uploads what it deploys") | ||
| } | ||
| } | ||
| if len(steps) < 2 { | ||
| problems = append(problems, "the job "+name+" asks for the artifact once, and a lookup that misses it fails the whole run") | ||
|
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check whether the retry conditions permit retries. Replace Read and validate the retry conditions. Add a canary with this substitution that must report a problem. As per path instructions, “A new test that would still pass with the behavior removed is a finding.”
|
||
| continue | ||
| } | ||
| for _, s := range steps[:len(steps)-1] { | ||
| if !s.ContinueOnError { | ||
| problems = append(problems, "try "+s.ID+" of "+name+" ends the job when it fails, so the tries after it never run") | ||
| } | ||
| } | ||
| if steps[len(steps)-1].ContinueOnError { | ||
| problems = append(problems, "the last try of "+name+" may fail without failing the job, so a site that never went out would look published") | ||
| } | ||
| } | ||
| return problems | ||
| } | ||
|
|
||
| // The site is deployed in a job of its own, after the upload, with more than | ||
| // one try. | ||
| // | ||
| // Measured on 2026-11-24: two runs in a row on main failed at deploy-pages | ||
| // with every file ready. It listed the sample-files artifact of the earlier | ||
| // job and not the github-pages one the same job had uploaded a moment before | ||
| // (actions/deploy-pages#451). Re-running the failed job cannot recover it, | ||
| // because the re-run uploads a second github-pages artifact. | ||
| // | ||
| // Its own canary: the job as it stood on main that day, uploading and | ||
| // deploying once in the same job, has to be reported. | ||
| func TestTheSiteIsDeployedInAJobAfterTheUploadWithMoreThanOneTry(t *testing.T) { | ||
| canary := []byte(`jobs: | ||
| publish: | ||
| steps: | ||
| - uses: actions/upload-pages-artifact@abc | ||
| - id: deployment | ||
| uses: actions/deploy-pages@abc | ||
| `) | ||
| got := pagesDeployProblems(canary) | ||
| if len(got) < 2 { | ||
| t.Fatalf("the canary, one job that uploads and deploys once, gave %d problem(s) and has two: %v", len(got), got) | ||
| } | ||
|
|
||
| path := filepath.Join(repoRoot(t), ".github", "workflows", "pages.yml") | ||
| body, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Skipf("the publishing workflow is not here: %v", err) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail when the publishing workflow cannot be read. If Use As per path instructions, flag “a skip that hides a failure.”
|
||
| } | ||
| for _, p := range pagesDeployProblems(body) { | ||
| t.Error(p) | ||
| } | ||
| } | ||
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.
Script executed:
Repository: donislawdev/TestingFilesGenerator
Length of output: 4895
Add a test that fails when either new OSV ignore changes.
The two new
[[IgnoredVulns]]entries forGHSA-qx49-fqc8-xw99andGHSA-53pm-wgxf-c6qfhave no test coverage. No test underinternal/guardreferences them or theirignoreUntildates. If either entry is removed, the scan reports the advisory again. IfignoreUntilis removed, the exception never expires. CI does not detect either regression.Add a guard test that asserts both IDs remain in
.github/osv-scanner.tomlwithignoreUntil = 2026-12-14. The project requires each behavior change to have a test that fails when the change is undone.Source: Path instructions