Skip to content

Commit

Permalink
Merge pull request #113 from Vitorgus/dev
Browse files Browse the repository at this point in the history
Godot mono support
  • Loading branch information
Vitorgus authored Jun 18, 2022
2 parents 76138c7 + 8ae2c97 commit 02aa4c6
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 157 deletions.
12 changes: 7 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
"project": "./tsconfig.eslint.json"
},
"rules": {
"no-console": ["error", { "allow": ["log"] }],
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"camelcase": "off",
"i18n-text/no-en": "off",
"prefer-template": "off",
"sort-imports": "off",
"semi": "off",
"i18n-text/no-en": "off",
"import/no-namespace": "off",
"import/no-unresolved": "off",
"filenames/match-regex": ["error", "^[a-z0-9-]+((.d)?|(.test)?)$"],
"eslint-comments/no-use": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
Expand Down Expand Up @@ -45,7 +48,6 @@
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ jobs:
with:
godot-version: 3.3.3
- run: godot --test 'string'
- name: Mono test
uses: ./
with:
godot-version: 3.3.3
mono: true
- run: godot --test 'string'
153 changes: 153 additions & 0 deletions __tests__/get-tools.test.ts
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);
});
});
127 changes: 113 additions & 14 deletions __tests__/main.test.ts
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!");
});
});
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ inputs:
godot-version:
required: true
description: 'Godot version to download'
mono:
required: false
description: 'If set to true, will download de mono version of Godot'
default: false
download-templates:
required: false
description: 'If it should also download and cache the export templates'
description: 'If set to false, will skip the default export templates download'
default: true
runs:
using: 'node12'
Expand Down
Loading

0 comments on commit 02aa4c6

Please sign in to comment.