Skip to content
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

Added the caching implementation #113

Merged
merged 8 commits into from
Jun 26, 2023
Prev Previous commit
Next Next commit
Added caching with @actions/cache
Marko19907 committed Jun 15, 2023

Verified

This commit was signed with the committer’s verified signature.
commit 782f9a57608ee25db45d866e2c46affde3bbaf16
31 changes: 23 additions & 8 deletions src/godot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { exec, ExecOptions } from '@actions/exec';
import * as core from '@actions/core';
import * as cache from '@actions/cache';
import * as io from '@actions/io';
import * as path from 'path';
import * as fs from 'fs';
@@ -86,17 +87,31 @@ async function setupWorkingPath(): Promise<void> {
}

async function downloadTemplates(): Promise<void> {
core.info(`Downloading Godot export templates from ${GODOT_TEMPLATES_DOWNLOAD_URL}`);

const file = path.join(GODOT_WORKING_PATH, GODOT_TEMPLATES_FILENAME);
await exec('wget', ['-nv', GODOT_TEMPLATES_DOWNLOAD_URL, '-O', file]);
const templatesPath = path.join(GODOT_WORKING_PATH, GODOT_TEMPLATES_FILENAME);
const cacheKey = `godot-templates-${GODOT_TEMPLATES_DOWNLOAD_URL}`;
const restoreKey = `godot-templates-`;
const cacheHit = await cache.restoreCache([templatesPath], cacheKey, [restoreKey]);
if (!cacheHit) {
core.info(`Downloading Godot export templates from ${GODOT_TEMPLATES_DOWNLOAD_URL}`);
await exec('wget', ['-nv', GODOT_TEMPLATES_DOWNLOAD_URL, '-O', templatesPath]);
await cache.saveCache([templatesPath], cacheKey);
} else {
core.info(`Restored cached Godot export templates from ${cacheHit}`);
}
}

async function downloadExecutable(): Promise<void> {
core.info(`Downloading Godot executable from ${GODOT_DOWNLOAD_URL}`);

const file = path.join(GODOT_WORKING_PATH, GODOT_ZIP);
await exec('wget', ['-nv', GODOT_DOWNLOAD_URL, '-O', file]);
const executablePath = path.join(GODOT_WORKING_PATH, GODOT_ZIP);
const cacheKey = `godot-executable-${GODOT_DOWNLOAD_URL}`;
const restoreKey = `godot-executable-`;
const cacheHit = await cache.restoreCache([executablePath], cacheKey, [restoreKey]);
if (!cacheHit) {
core.info(`Downloading Godot executable from ${GODOT_DOWNLOAD_URL}`);
await exec('wget', ['-nv', GODOT_DOWNLOAD_URL, '-O', executablePath]);
await cache.saveCache([executablePath], cacheKey);
} else {
core.info(`Restored cached Godot executable from ${cacheHit}`);
}
}

async function prepareExecutable(): Promise<void> {