Repository navigation
Add toolcache.ts script for bundle(-from)-toolcache checks
#4255
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 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
297dec9
Add `toolcache.ts` script for `bundle-toolcache.yml`
mbg 24408cc
Use `toolcache.ts` in `bundle-from-toolcache.yml`
mbg 57804e9
Add `@actions/tool-cache` as an explicit dependency
mbg d0ab717
Replace `rmdir` with `rmSync`
mbg 596ae5c
Make comparison strict
mbg 34f75b5
Rename argument
mbg 6b34430
Log versions if there are some
mbg 0a00d0c
Rename `noCodeQLInToolcache`
mbg 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,94 @@ | ||
| #!/usr/bin/env npx tsx | ||
|
|
||
| /** | ||
| * Provides utility commands for working with the Actions toolcache in PR checks. | ||
| */ | ||
|
|
||
| import fs from "fs"; | ||
| import { parseArgs } from "node:util"; | ||
| import path from "path"; | ||
|
|
||
| import * as core from "@actions/core"; | ||
| import * as toolcache from "@actions/tool-cache"; | ||
|
|
||
| function removeCodeQLFromToolcache() { | ||
| const toolcachePath = process.env["RUNNER_TOOL_CACHE"]; | ||
|
|
||
| if (toolcachePath === undefined) { | ||
| throw new Error("Expected RUNNER_TOOL_CACHE to be defined"); | ||
| } | ||
|
|
||
| const codeqlPath = path.join(toolcachePath, "CodeQL"); | ||
| fs.rmSync(codeqlPath, { recursive: true }); | ||
|
|
||
| core.info(`Removed '${codeqlPath}' from the toolcache.`); | ||
| } | ||
|
|
||
| function findCodeQL() { | ||
| return toolcache.findAllVersions("CodeQL"); | ||
| } | ||
|
|
||
| function noCodeQLInToolcache() { | ||
| const allCodeqlVersions = findCodeQL(); | ||
| if (allCodeqlVersions.length !== 0) { | ||
| throw new Error( | ||
| `CodeQL should not be found in the toolcache, but found ${allCodeqlVersions}`, | ||
| ); | ||
| } | ||
| core.info("No versions of CodeQL found in the toolcache"); | ||
| } | ||
|
|
||
| function hasCodeQLInToolcache(expectedNumber?: string) { | ||
| const expected = | ||
| expectedNumber !== undefined | ||
| ? Number.parseInt(expectedNumber, 10) | ||
| : undefined; | ||
|
|
||
| const allCodeqlVersions = findCodeQL(); | ||
| core.info(`Found CodeQL versions: ${allCodeqlVersions}`); | ||
|
mbg marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (allCodeqlVersions.length === 0) { | ||
| throw new Error("CodeQL not found in toolcache"); | ||
| } | ||
| if (expected !== undefined && allCodeqlVersions.length !== expected) { | ||
| throw new Error( | ||
| `Expected ${expected} versions of CodeQL in the toolcache, but found ${allCodeqlVersions.length}`, | ||
| ); | ||
| } | ||
|
mbg marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| function main() { | ||
| const { positionals, values } = parseArgs({ | ||
| options: { | ||
| // The *number* of expected versions in the toolcache. | ||
| expectedVersions: { type: "string", short: "n" }, | ||
|
mbg marked this conversation as resolved.
Resolved
|
||
| }, | ||
| allowPositionals: true, | ||
| }); | ||
|
|
||
| if (positionals.length < 1) { | ||
| throw new Error("Command not specified."); | ||
| } | ||
|
|
||
| const cmd = positionals[0]; | ||
|
|
||
| switch (cmd.trim().toLowerCase()) { | ||
| case "clear": | ||
| removeCodeQLFromToolcache(); | ||
| return; | ||
| case "absent": | ||
| noCodeQLInToolcache(); | ||
| return; | ||
| case "installed": | ||
| hasCodeQLInToolcache(values.expectedVersions); | ||
| return; | ||
| default: | ||
| throw new Error(`Unknown command '${cmd}'.`); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| main(); | ||
| } catch (err) { | ||
| core.setFailed(err instanceof Error ? err.message : String(err)); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.