| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -37,6 +37,10 @@ inputs: | |
| description: "Enable caching of project dependencies" | ||
| required: false | ||
| default: "false" | ||
| task-cache: | ||
| description: "Enable task caching via GitHub Actions" | ||
| required: false | ||
| default: "false" | ||
|
Comment thread
Comment on lines
+40
to
+43
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
The new input and output are absent from the public interface documentation: the Inputs table at README.md:329-344, Outputs table at README.md:350-355, and Caching section at README.md:357-375 still describe only dependency caching. Since the repository's marketplace README is how users discover and configure this action, the feature is effectively hidden and users cannot learn its cache path/key behavior or consume task-cache-hit; add the new input, output, and usage details there. Useful? React with 👍 / 👎.
Sorry, something went wrong.
All reactions
|
||
| cache-dependency-path: | ||
| description: "Path to lock file for cache key generation. Auto-detected if not specified." | ||
| required: false | ||
| Expand All | @@ -52,6 +56,8 @@ outputs: | |
| description: "The installed version of Vite+" | ||
| cache-hit: | ||
| description: "Boolean indicating if cache was restored" | ||
| task-cache-hit: | ||
| description: "Boolean indicating if task cache was restored" | ||
|
|
||
| runs: | ||
| using: node24 | ||
| Expand Down | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import { describe, it, expect, beforeEach, afterEach, vi } from "vite-plus/test"; | ||
|
|
||
| // Mock external dependencies before importing the module | ||
| vi.mock("@actions/cache", () => ({ | ||
| restoreCache: vi.fn(), | ||
| })); | ||
| vi.mock("@actions/core", () => ({ | ||
| warning: vi.fn(), | ||
| info: vi.fn(), | ||
| debug: vi.fn(), | ||
| saveState: vi.fn(), | ||
| setOutput: vi.fn(), | ||
| })); | ||
| vi.mock("./utils.js", () => ({ | ||
| getConfiguredProjectDir: vi.fn(() => "/workspace"), | ||
| })); | ||
|
|
||
| import { restoreCache as restoreCacheAction } from "@actions/cache"; | ||
| import { warning, info, saveState, setOutput } from "@actions/core"; | ||
| import { restoreTaskCache } from "./task-cache-restore.js"; | ||
| import { State, Outputs } from "./types.js"; | ||
| import type { Inputs } from "./types.js"; | ||
|
|
||
| const mockedRestoreCacheAction = vi.mocked(restoreCacheAction); | ||
| const mockedWarning = vi.mocked(warning); | ||
| const mockedInfo = vi.mocked(info); | ||
| const mockedSaveState = vi.mocked(saveState); | ||
| const mockedSetOutput = vi.mocked(setOutput); | ||
|
|
||
| const baseInputs: Inputs = { | ||
| version: "latest", | ||
| nodeVersion: undefined, | ||
| nodeVersionFile: undefined, | ||
| workingDirectory: undefined, | ||
| runInstall: [], | ||
| sfw: false, | ||
| cache: false, | ||
| cacheDependencyPath: undefined, | ||
| taskCache: true, | ||
| registryUrl: undefined, | ||
| scope: undefined, | ||
| }; | ||
|
|
||
| describe("restoreTaskCache", () => { | ||
| const originalEnv = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| process.env = { ...originalEnv }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| }); | ||
|
|
||
| it("restores task cache with correct key pattern", async () => { | ||
| process.env.RUNNER_OS = "Linux"; | ||
| process.env.GITHUB_RUN_ID = "12345"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "1"; | ||
|
|
||
| mockedRestoreCacheAction.mockResolvedValue("vite-task-Linux-x64-12345-1"); | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedRestoreCacheAction).toHaveBeenCalledWith( | ||
| expect.arrayContaining([expect.stringContaining("node_modules")]), | ||
| "vite-task-Linux-x64-12345-1", | ||
| ["vite-task-Linux-x64-"], | ||
| ); | ||
|
|
||
| expect(mockedSaveState).toHaveBeenCalledWith( | ||
| State.TaskCachePrimaryKey, | ||
| "vite-task-Linux-x64-12345-1", | ||
| ); | ||
| expect(mockedSaveState).toHaveBeenCalledWith( | ||
| State.TaskCacheMatchedKey, | ||
| "vite-task-Linux-x64-12345-1", | ||
| ); | ||
| expect(mockedSetOutput).toHaveBeenCalledWith(Outputs.TaskCacheHit, true); | ||
| expect(mockedInfo).toHaveBeenCalledWith(expect.stringContaining("Task cache restored")); | ||
| }); | ||
|
|
||
| it("sets cache-hit to false when cache is not found", async () => { | ||
| process.env.RUNNER_OS = "Linux"; | ||
| process.env.GITHUB_RUN_ID = "12345"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "1"; | ||
|
|
||
| mockedRestoreCacheAction.mockResolvedValue(undefined); | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedSetOutput).toHaveBeenCalledWith(Outputs.TaskCacheHit, false); | ||
| expect(mockedInfo).toHaveBeenCalledWith("Task cache not found"); | ||
| }); | ||
|
|
||
| it("warns and skips when GITHUB_RUN_ID is missing", async () => { | ||
| process.env.RUNNER_OS = "Linux"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "1"; | ||
| delete process.env.GITHUB_RUN_ID; | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedWarning).toHaveBeenCalledWith( | ||
| expect.stringContaining("GitHub run ID or attempt not found"), | ||
| ); | ||
| expect(mockedSetOutput).toHaveBeenCalledWith(Outputs.TaskCacheHit, false); | ||
| expect(mockedRestoreCacheAction).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("warns and skips when GITHUB_RUN_ATTEMPT is missing", async () => { | ||
| process.env.RUNNER_OS = "Linux"; | ||
| process.env.GITHUB_RUN_ID = "12345"; | ||
| delete process.env.GITHUB_RUN_ATTEMPT; | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedWarning).toHaveBeenCalledWith( | ||
| expect.stringContaining("GitHub run ID or attempt not found"), | ||
| ); | ||
| expect(mockedSetOutput).toHaveBeenCalledWith(Outputs.TaskCacheHit, false); | ||
| expect(mockedRestoreCacheAction).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("uses correct cache path relative to project directory", async () => { | ||
| process.env.RUNNER_OS = "Windows"; | ||
| process.env.GITHUB_RUN_ID = "67890"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "2"; | ||
|
|
||
| mockedRestoreCacheAction.mockResolvedValue(undefined); | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| const cachePathsCall = mockedSaveState.mock.calls.find(([key]) => key === State.TaskCachePaths); | ||
| expect(cachePathsCall).toBeDefined(); | ||
| if (cachePathsCall) { | ||
| const paths = JSON.parse(cachePathsCall[1] as string); | ||
| expect(paths[0]).toMatch(/node_modules/); | ||
| expect(paths[0]).toMatch(/task-cache/); | ||
| } | ||
| }); | ||
|
|
||
| it("handles different OS and architecture combinations", async () => { | ||
| process.env.RUNNER_OS = "macOS"; | ||
| process.env.GITHUB_RUN_ID = "11111"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "3"; | ||
|
|
||
| // Mock process.arch | ||
| const originalArch = process.arch; | ||
| Object.defineProperty(process, "arch", { | ||
| value: "arm64", | ||
| configurable: true, | ||
| }); | ||
|
|
||
| mockedRestoreCacheAction.mockResolvedValue(undefined); | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedSaveState).toHaveBeenCalledWith( | ||
| State.TaskCachePrimaryKey, | ||
| "vite-task-macOS-arm64-11111-3", | ||
| ); | ||
|
|
||
| // Restore original arch | ||
| Object.defineProperty(process, "arch", { | ||
| value: originalArch, | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("saves cache paths as JSON string", async () => { | ||
| process.env.RUNNER_OS = "Linux"; | ||
| process.env.GITHUB_RUN_ID = "12345"; | ||
| process.env.GITHUB_RUN_ATTEMPT = "1"; | ||
|
|
||
| mockedRestoreCacheAction.mockResolvedValue(undefined); | ||
|
|
||
| await restoreTaskCache(baseInputs); | ||
|
|
||
| expect(mockedSaveState).toHaveBeenCalledWith( | ||
| State.TaskCachePaths, | ||
| expect.stringMatching(/^\[.*\]$/), | ||
| ); | ||
|
|
||
| const cachePathsCall = mockedSaveState.mock.calls.find(([key]) => key === State.TaskCachePaths); | ||
| if (cachePathsCall) { | ||
| const paths = JSON.parse(cachePathsCall[1] as string); | ||
| expect(Array.isArray(paths)).toBe(true); | ||
| expect(paths.length).toBeGreaterThan(0); | ||
| } | ||
| }); | ||
| }); |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@KTrain5169 can you add a new test job for this new feature at https://github.com/voidzero-dev/setup-vp/blob/main/.github/workflows/test.yml ?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI'm not sure what I'm supposed to test here, is it just trying to save and restore using the setup-vp action vs the regualr cache action?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.