From 22b5f8bdf3746274539272db4ea89e553681d7b2 Mon Sep 17 00:00:00 2001 From: BluePhoenixGame <38372706+BluePhoenixGame@users.noreply.github.com> Date: Fri, 24 Jul 2020 23:33:48 +0200 Subject: [PATCH] Use RELATIVE_PROJECT_PATH in export (#28) * Change executablePath from buildDir This assumes presets.export_path is relative to RELATIVE_PROJECT_PATH. * Remove path.basename call This means we use the whole path relative to RELATIVE_PROJECT_PATH rather than just filename. * Revert my previous changes As preparation for a new approach * Add USE_PRESET_EXPORT_PATH input and constant * Update moveBuilds.. to use USE_PRESET_EXPORT_PATH Update moveBuildsToExportDirectory to use new USE_PRESET_EXPORT_PATH constant * Update main to move builds if USE_PRESET... is true Update main file to call moveBuildsToExportDirectory if USE_PRESET_EXPORT_PATH is true * Add use_preset_export_path * Remove trailing filename from path using dirname() * Export USE_PRESET_EXPORT_PATH * Fix linting problems * Add index.js generated by ncc * Document bias towards `use_preset_export_path` * Add new field to action.yml * Correctly type use_preset_export_path * New build * Fix spammy message Includes build --- README.md | 2 ++ action.yml | 4 ++++ dist/index.js | 9 +++++---- src/constants.ts | 2 ++ src/file.ts | 14 ++++++++------ src/main.ts | 9 +++++++-- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3c728308..1aa4db7c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ Since this action creates releases and uploads the zip file assets, you will nee - If release notes should be automatically generated based on commit history. The generated notes will be added as the body of the release. - **Note**: This input is only used when `create_release` is `true`. - **Note**: When using the GitHub checkout action, ensure you are fetching the entire project history by including `fetch-depth: 0`. See the example workflow configuration for more context. +- `use_preset_export_path` default `false` + - If set to true, exports will be moved to directory defined in `export_presets.cfg` relative to the root of the Git repository. Prioritized over `relative_export_path`. - `relative_export_path` default `''` - If provided, exports will be moved to this directory relative to the root of the Git repository. - `update_windows_icons` default `false` diff --git a/action.yml b/action.yml index 589820ff..7f09d355 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,10 @@ inputs: description: If release notes should be automatically generated based on commit history. default: false required: false + use_preset_export_path: + description: If set to true, exports will be moved to directory defined in "export_presets.cfg" relative to the root of the Git repository. Prioritized over "relative_export_path". + default: false + required: false relative_export_path: description: If provided, exports will be moved to this directory relative to the root of the Git repository. default: '' diff --git a/dist/index.js b/dist/index.js index 1250a9af..3c804f9a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11921,6 +11921,7 @@ const RELATIVE_EXPORT_PATH = Object(core.getInput)('relative_export_path'); const RELATIVE_PROJECT_PATH = Object(core.getInput)('relative_project_path'); const SHOULD_CREATE_RELEASE = Object(core.getInput)('create_release') === 'true'; const UPDATE_WINDOWS_ICONS = Object(core.getInput)('update_windows_icons') === 'true'; +const USE_PRESET_EXPORT_PATH = Object(core.getInput)('use_preset_export_path') === 'true'; const GODOT_WORKING_PATH = external_path_default().resolve(external_path_default().join(Object(external_os_.homedir)(), '/.local/share/godot')); const GODOT_CONFIG_PATH = external_path_default().resolve(external_path_default().join(Object(external_os_.homedir)(), '/.config/godot')); @@ -12247,11 +12248,11 @@ function zipBuildResult(buildResult) { } function moveBuildsToExportDirectory(buildResults, moveArchived) { return file_awaiter(this, void 0, void 0, function* () { - const fullExportPath = external_path_default().resolve(RELATIVE_EXPORT_PATH); - Object(core.startGroup)(`Moving exports to ${fullExportPath}`); - yield Object(io.mkdirP)(fullExportPath); + Object(core.startGroup)(`Moving exports`); const promises = []; for (const buildResult of buildResults) { + const fullExportPath = external_path_default().resolve(USE_PRESET_EXPORT_PATH ? external_path_default().dirname(buildResult.preset.export_path) : RELATIVE_EXPORT_PATH); + yield Object(io.mkdirP)(fullExportPath); let promise; if (moveArchived) { if (!buildResult.archivePath) { @@ -12455,7 +12456,7 @@ function main() { if (ARCHIVE_EXPORT_OUTPUT) { yield zipBuildResults(buildResults); } - if (RELATIVE_EXPORT_PATH) { + if (RELATIVE_EXPORT_PATH || USE_PRESET_EXPORT_PATH) { yield moveBuildsToExportDirectory(buildResults, ARCHIVE_EXPORT_OUTPUT); } if (SHOULD_CREATE_RELEASE) { diff --git a/src/constants.ts b/src/constants.ts index 4f6f78a5..db5346a7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -12,6 +12,7 @@ const RELATIVE_EXPORT_PATH = core.getInput('relative_export_path'); const RELATIVE_PROJECT_PATH = core.getInput('relative_project_path'); const SHOULD_CREATE_RELEASE = core.getInput('create_release') === 'true'; const UPDATE_WINDOWS_ICONS = core.getInput('update_windows_icons') === 'true'; +const USE_PRESET_EXPORT_PATH = core.getInput('use_preset_export_path') === 'true'; const GODOT_WORKING_PATH = path.resolve(path.join(os.homedir(), '/.local/share/godot')); const GODOT_CONFIG_PATH = path.resolve(path.join(os.homedir(), '/.config/godot')); @@ -29,4 +30,5 @@ export { RELATIVE_PROJECT_PATH, SHOULD_CREATE_RELEASE, UPDATE_WINDOWS_ICONS, + USE_PRESET_EXPORT_PATH, }; diff --git a/src/file.ts b/src/file.ts index 98a75453..d669172d 100644 --- a/src/file.ts +++ b/src/file.ts @@ -3,7 +3,7 @@ import path from 'path'; import * as io from '@actions/io'; import { exec } from '@actions/exec'; import * as fs from 'fs'; -import { GODOT_WORKING_PATH, RELATIVE_EXPORT_PATH } from './constants'; +import { GODOT_WORKING_PATH, RELATIVE_EXPORT_PATH, USE_PRESET_EXPORT_PATH } from './constants'; import * as core from '@actions/core'; async function zipBuildResults(buildResults: BuildResult[]): Promise { @@ -35,13 +35,15 @@ async function zipBuildResult(buildResult: BuildResult): Promise { } async function moveBuildsToExportDirectory(buildResults: BuildResult[], moveArchived?: boolean): Promise { - const fullExportPath = path.resolve(RELATIVE_EXPORT_PATH); - core.startGroup(`Moving exports to ${fullExportPath}`); - - await io.mkdirP(fullExportPath); - + core.startGroup(`Moving exports`); const promises: Promise[] = []; for (const buildResult of buildResults) { + const fullExportPath = path.resolve( + USE_PRESET_EXPORT_PATH ? path.dirname(buildResult.preset.export_path) : RELATIVE_EXPORT_PATH, + ); + + await io.mkdirP(fullExportPath); + let promise: Promise; if (moveArchived) { if (!buildResult.archivePath) { diff --git a/src/main.ts b/src/main.ts index 7dfc45d8..f7844407 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,12 @@ import * as core from '@actions/core'; import { exportBuilds } from './godot'; import { createRelease } from './release'; -import { SHOULD_CREATE_RELEASE, ARCHIVE_EXPORT_OUTPUT, RELATIVE_EXPORT_PATH } from './constants'; +import { + SHOULD_CREATE_RELEASE, + ARCHIVE_EXPORT_OUTPUT, + RELATIVE_EXPORT_PATH, + USE_PRESET_EXPORT_PATH, +} from './constants'; import { zipBuildResults, moveBuildsToExportDirectory } from './file'; async function main(): Promise { @@ -15,7 +20,7 @@ async function main(): Promise { await zipBuildResults(buildResults); } - if (RELATIVE_EXPORT_PATH) { + if (RELATIVE_EXPORT_PATH || USE_PRESET_EXPORT_PATH) { await moveBuildsToExportDirectory(buildResults, ARCHIVE_EXPORT_OUTPUT); }