generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from Vitorgus/dev
Godot mono support
- Loading branch information
Showing
12 changed files
with
467 additions
and
157 deletions.
There are no files selected for viewing
This file contains 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 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 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,153 @@ | ||
import * as tc from "@actions/tool-cache"; | ||
import * as io from "@actions/io"; | ||
|
||
import { getGodot, getTemplates } from "../src/get-tools"; | ||
|
||
jest.mock("@actions/core"); | ||
jest.mock("@actions/tool-cache"); | ||
jest.mock("@actions/io"); | ||
|
||
type MockedTcFind = jest.MockedFunction<typeof tc.find>; | ||
type MockedTcDownloadTool = jest.MockedFunction<typeof tc.downloadTool>; | ||
type MockedTcExtractZip = jest.MockedFunction<typeof tc.extractZip>; | ||
type MockedTcCacheFile = jest.MockedFunction<typeof tc.cacheFile>; | ||
type MockedTcCacheDir = jest.MockedFunction<typeof tc.cacheDir>; | ||
|
||
type MockedIoMv = jest.MockedFunction<typeof io.mv>; | ||
type MockedIoRmRF = jest.MockedFunction<typeof io.rmRF>; | ||
type MockedIoCp = jest.MockedFunction<typeof io.cp>; | ||
|
||
let mockTcFind: MockedTcFind; | ||
let mockTcDownloadTool: MockedTcDownloadTool; | ||
let mockTcExtrackZip: MockedTcExtractZip; | ||
let mockTcCacheFile: MockedTcCacheFile; | ||
let mockTcCacheDir: MockedTcCacheDir; | ||
|
||
let mockIoMv: MockedIoMv; | ||
let mockIoRmRF: MockedIoRmRF; | ||
let mockIoCp: MockedIoCp; | ||
|
||
beforeAll(() => { | ||
// process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||
|
||
mockTcFind = tc.find as MockedTcFind; | ||
mockTcDownloadTool = tc.downloadTool as MockedTcDownloadTool; | ||
mockTcExtrackZip = tc.extractZip as MockedTcExtractZip; | ||
mockTcCacheFile = tc.cacheFile as MockedTcCacheFile; | ||
mockTcCacheDir = tc.cacheDir as MockedTcCacheDir; | ||
mockIoMv = io.mv as MockedIoMv; | ||
mockIoRmRF = io.rmRF as MockedIoRmRF; | ||
mockIoCp = io.cp as MockedIoCp; | ||
}); | ||
|
||
describe("getGodot tests", () => { | ||
test("Cache test standard", async () => { | ||
mockTcFind.mockReturnValue("/path/to/existing/cached/godot"); | ||
|
||
const result = await getGodot("3.3.2", false); | ||
|
||
expect(mockTcFind).toHaveBeenCalledWith("godot", "3.3.2", "linux"); | ||
expect(result).toBe("/path/to/existing/cached/godot"); | ||
}); | ||
|
||
test("Download test standard", async () => { | ||
mockTcFind.mockReturnValue(""); | ||
mockTcDownloadTool.mockResolvedValue("/path/to/downloaded/godot"); | ||
mockTcExtrackZip.mockResolvedValue("/path/to/extracted/godot"); | ||
mockTcCacheFile.mockResolvedValue("/path/to/cached/godot"); | ||
|
||
const result = await getGodot("3.1.1", false); | ||
|
||
expect(mockTcDownloadTool).toHaveBeenCalledWith("https://downloads.tuxfamily.org/godotengine/3.1.1/Godot_v3.1.1-stable_linux_headless.64.zip"); | ||
// expect(mockTcExtrackZip).toHaveBeenCalledWith("/path/to/downloaded/godot", undefined); | ||
expect(mockTcCacheFile).toHaveBeenCalledWith("/path/to/extracted/godot/Godot_v3.1.1-stable_linux_headless.64", "godot", "godot", "3.1.1", "linux"); | ||
expect(result).toBe("/path/to/cached/godot"); | ||
}); | ||
|
||
test("Cache test mono", async () => { | ||
mockTcFind.mockReturnValue("/path/to/existing/cached/godot-mono"); | ||
|
||
const result = await getGodot("3.2.3", true); | ||
|
||
expect(mockTcFind).toHaveBeenCalledWith("godot", "3.2.3-mono", "linux"); | ||
expect(result).toBe("/path/to/existing/cached/godot-mono"); | ||
}); | ||
|
||
test("Download test mono", async () => { | ||
mockTcFind.mockReturnValue(""); | ||
mockTcDownloadTool.mockResolvedValue("/path/to/downloaded/godot-mono"); | ||
mockTcExtrackZip.mockResolvedValue("/path/to/extracted/godot-mono"); | ||
mockTcCacheDir.mockResolvedValue("/path/to/cached/godot-mono"); | ||
|
||
const result = await getGodot("3.3.3", true); | ||
|
||
expect(mockTcDownloadTool).toHaveBeenCalledWith("https://downloads.tuxfamily.org/godotengine/3.3.3/mono/Godot_v3.3.3-stable_mono_linux_headless_64.zip"); | ||
// expect(mockTcExtrackZip).toHaveBeenCalledWith("/path/to/downloaded/godot-mono", undefined); | ||
expect(mockIoMv).toHaveBeenCalledWith( | ||
"/path/to/extracted/godot-mono/Godot_v3.3.3-stable_mono_linux_headless_64/Godot_v3.3.3-stable_mono_linux_headless.64", | ||
"/path/to/extracted/godot-mono/Godot_v3.3.3-stable_mono_linux_headless_64/godot" | ||
); | ||
expect(mockTcCacheDir).toHaveBeenCalledWith("/path/to/extracted/godot-mono/Godot_v3.3.3-stable_mono_linux_headless_64", "godot", "3.3.3-mono", "linux"); | ||
expect(result).toBe("/path/to/cached/godot-mono"); | ||
}); | ||
}); | ||
|
||
describe("getTemplates tests", () => { | ||
test("Cache test standard", async () => { | ||
mockTcFind.mockReturnValue("/path/to/existing/cached/godot-templates"); | ||
|
||
await getTemplates("3.3.2", false); | ||
|
||
expect(mockTcFind).toHaveBeenCalledWith("godot-export-templates", "3.3.2", "linux"); | ||
expect(mockIoRmRF).toHaveBeenCalledWith("/home/runner/.local/share/godot/templates/3.3.2.stable"); | ||
const cpOptions = { recursive: true }; | ||
expect(mockIoCp).toHaveBeenCalledWith("/path/to/existing/cached/godot-templates", "/home/runner/.local/share/godot/templates/3.3.2.stable", cpOptions); | ||
}); | ||
|
||
test("Download test standard", async () => { | ||
mockTcFind.mockReturnValue(""); | ||
mockTcDownloadTool.mockResolvedValue("/path/to/downloaded/godot-templates"); | ||
mockTcExtrackZip.mockResolvedValue("/path/to/extracted/godot-templates"); | ||
mockTcCacheDir.mockResolvedValue("/path/to/cached/godot-templates"); | ||
|
||
await getTemplates("3.1.1", false); | ||
|
||
expect(mockTcDownloadTool).toHaveBeenCalledWith("https://downloads.tuxfamily.org/godotengine/3.1.1/Godot_v3.1.1-stable_export_templates.tpz"); | ||
// expect(mockTcExtrackZip).toHaveBeenCalledWith("/path/to/downloaded/godot-templates", undefined); | ||
expect(mockTcCacheDir).toHaveBeenCalledWith("/path/to/extracted/godot-templates/templates", "godot-export-templates", "3.1.1", "linux"); | ||
expect(mockIoRmRF).toHaveBeenCalledWith("/home/runner/.local/share/godot/templates/3.1.1.stable"); | ||
const cpOptions = { recursive: true }; | ||
expect(mockIoCp).toHaveBeenCalledWith("/path/to/cached/godot-templates", "/home/runner/.local/share/godot/templates/3.1.1.stable", cpOptions); | ||
}); | ||
|
||
test("Cache test mono", async () => { | ||
mockTcFind.mockReturnValue("/path/to/existing/cached/godot-mono-templates"); | ||
|
||
await getTemplates("3.2.3", true); | ||
|
||
expect(mockTcFind).toHaveBeenCalledWith("godot-export-templates", "3.2.3-mono", "linux"); | ||
expect(mockIoRmRF).toHaveBeenCalledWith("/home/runner/.local/share/godot/templates/3.2.3.stable.mono"); | ||
const cpOptions = { recursive: true }; | ||
expect(mockIoCp).toHaveBeenCalledWith( | ||
"/path/to/existing/cached/godot-mono-templates", | ||
"/home/runner/.local/share/godot/templates/3.2.3.stable.mono", | ||
cpOptions | ||
); | ||
}); | ||
|
||
test("Download test mono", async () => { | ||
mockTcFind.mockReturnValue(""); | ||
mockTcDownloadTool.mockResolvedValue("/path/to/downloaded/godot-mono-templates"); | ||
mockTcExtrackZip.mockResolvedValue("/path/to/extracted/godot-mono-templates"); | ||
mockTcCacheDir.mockResolvedValue("/path/to/cached/godot-mono-templates"); | ||
|
||
await getTemplates("3.3.3", true); | ||
|
||
expect(mockTcDownloadTool).toHaveBeenCalledWith("https://downloads.tuxfamily.org/godotengine/3.3.3/mono/Godot_v3.3.3-stable_mono_export_templates.tpz"); | ||
// expect(mockTcExtrackZip).toHaveBeenCalledWith("/path/to/downloaded/godot-mono-templates", undefined); | ||
expect(mockTcCacheDir).toHaveBeenCalledWith("/path/to/extracted/godot-mono-templates/templates", "godot-export-templates", "3.3.3-mono", "linux"); | ||
expect(mockIoRmRF).toHaveBeenCalledWith("/home/runner/.local/share/godot/templates/3.3.3.stable.mono"); | ||
const cpOptions = { recursive: true }; | ||
expect(mockIoCp).toHaveBeenCalledWith("/path/to/cached/godot-mono-templates", "/home/runner/.local/share/godot/templates/3.3.3.stable.mono", cpOptions); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,15 +1,114 @@ | ||
// import * as process from "process"; | ||
import * as cp from "child_process"; | ||
import * as path from "path"; | ||
import { expect, test } from "@jest/globals"; | ||
|
||
// shows how the runner will run a javascript action with env / stdout protocol | ||
test("test runs", () => { | ||
process.env["INPUT_MILLISECONDS"] = "500"; | ||
const np = process.execPath; | ||
const ip = path.join(__dirname, "..", "lib", "main.js"); | ||
const options: cp.ExecFileSyncOptions = { | ||
env: process.env | ||
}; | ||
// console.log(cp.execFileSync(np, [ip], options).toString()); | ||
import * as core from "@actions/core"; | ||
// import * as tc from "@actions/tool-cache"; | ||
// import * as io from "@actions/io"; | ||
|
||
import { getGodot, getTemplates } from "../src/get-tools"; | ||
import { run } from "../src/main"; | ||
|
||
jest.mock("@actions/core"); | ||
jest.mock("@actions/tool-cache"); | ||
jest.mock("@actions/io"); | ||
|
||
jest.mock("../src/get-tools"); | ||
|
||
interface InputsInterface { | ||
[name: string]: string | boolean; | ||
} | ||
|
||
type MockedCoreGetInput = jest.MockedFunction<typeof core.getInput>; | ||
type MockedCoreGetBooleanInput = jest.MockedFunction<typeof core.getBooleanInput>; | ||
type MockedCoreSetFailed = jest.MockedFunction<typeof core.setFailed>; | ||
|
||
type MockedGetGodot = jest.MockedFunction<typeof getGodot>; | ||
|
||
let input: InputsInterface; | ||
|
||
let mockCoreGetInput: MockedCoreGetInput; | ||
let mockCoreGetBooleanInput: MockedCoreGetBooleanInput; | ||
let mockedCoreSetFailed: MockedCoreSetFailed; | ||
|
||
let mockGetGodot: MockedGetGodot; | ||
|
||
beforeAll(() => { | ||
// process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||
|
||
mockCoreGetInput = core.getInput as MockedCoreGetInput; | ||
mockCoreGetInput.mockImplementation(name => input[name] as string); | ||
|
||
mockCoreGetBooleanInput = core.getBooleanInput as MockedCoreGetBooleanInput; | ||
mockCoreGetBooleanInput.mockImplementation(name => input[name] as boolean); | ||
|
||
mockedCoreSetFailed = core.setFailed as MockedCoreSetFailed; | ||
|
||
// prettier-ignore | ||
mockedCoreSetFailed.mockImplementation(e => { throw new Error(e as string) }); // eslint-disable-line @typescript-eslint/semi | ||
|
||
mockGetGodot = getGodot as MockedGetGodot; | ||
}); | ||
|
||
beforeEach(() => { | ||
input = {}; | ||
}); | ||
|
||
describe("main funciton tests", () => { | ||
test("invalid version value test", async () => { | ||
input["godot-version"] = "abc"; | ||
expect(async () => await run()).rejects.toThrow("INVALID VERSION"); | ||
}); | ||
|
||
test("normal run test", async () => { | ||
input["godot-version"] = "3.3.4"; | ||
input["mono"] = false; | ||
input["download-templates"] = true; | ||
mockGetGodot.mockResolvedValue("/path/to/godot"); | ||
|
||
await run(); | ||
|
||
expect(getGodot).toHaveBeenLastCalledWith("3.3.4", false); | ||
expect(core.addPath).toHaveBeenCalledWith("/path/to/godot"); | ||
expect(getTemplates).toHaveBeenCalledWith("3.3.4", false); | ||
expect(core.info).toHaveBeenLastCalledWith("Godot 3.3.4 is ready to use!"); | ||
}); | ||
|
||
test("skip templates test", async () => { | ||
input["godot-version"] = "3.3.3"; | ||
input["mono"] = false; | ||
input["download-templates"] = false; | ||
mockGetGodot.mockResolvedValue("/path/to/godot"); | ||
|
||
await run(); | ||
|
||
expect(getGodot).toHaveBeenLastCalledWith("3.3.3", false); | ||
expect(core.addPath).toHaveBeenCalledWith("/path/to/godot"); | ||
expect(getTemplates).toHaveBeenCalledTimes(0); | ||
expect(core.info).toHaveBeenLastCalledWith("Godot 3.3.3 is ready to use!"); | ||
}); | ||
|
||
test("mono test", async () => { | ||
input["godot-version"] = "3.3.4"; | ||
input["mono"] = true; | ||
input["download-templates"] = true; | ||
mockGetGodot.mockResolvedValue("/path/to/godot"); | ||
|
||
await run(); | ||
|
||
expect(getGodot).toHaveBeenLastCalledWith("3.3.4", true); | ||
expect(core.addPath).toHaveBeenCalledWith("/path/to/godot"); | ||
expect(getTemplates).toHaveBeenCalledWith("3.3.4", true); | ||
expect(core.info).toHaveBeenLastCalledWith("Godot 3.3.4 Mono is ready to use!"); | ||
}); | ||
|
||
test("skip mono templates test", async () => { | ||
input["godot-version"] = "3.3.3"; | ||
input["mono"] = true; | ||
input["download-templates"] = false; | ||
mockGetGodot.mockResolvedValue("/path/to/godot"); | ||
|
||
await run(); | ||
|
||
expect(getGodot).toHaveBeenLastCalledWith("3.3.3", true); | ||
expect(core.addPath).toHaveBeenCalledWith("/path/to/godot"); | ||
expect(getTemplates).toHaveBeenCalledTimes(0); | ||
expect(core.info).toHaveBeenLastCalledWith("Godot 3.3.3 Mono is ready to use!"); | ||
}); | ||
}); |
This file contains 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.