Files
DcsMissionScriptingTools/github-actions/install-lua-addon/src/index.ts
T
dutchie031 12d3ad3341
publish-vs-code-extensions.yml / Publish VS Code Extension (push) Successful in 5s
Added test for publish bundle pipeline
2026-09-10 18:20:23 +02:00

73 lines
2.6 KiB
TypeScript

import * as core from '@actions/core';
import * as fs from 'fs/promises';
import * as path from 'path';
import { existsSync } from 'fs';
async function copyDirectory(src: string, dest: string): Promise<void> {
await fs.mkdir(dest, { recursive: true });
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
await copyDirectory(srcPath, destPath);
} else {
await fs.copyFile(srcPath, destPath);
}
}
}
async function run() {
try {
const destinationPath = core.getInput('destination-path');
if (!destinationPath) {
core.setFailed('Destination path is required.');
return;
}
// Reference lua-addons bundled in dist directory
// __dirname is dist/, lua-addons is bundled alongside
const bundledAddonsDir = path.resolve(__dirname, './lua-addons');
// Verify bundled addons directory exists
if (!existsSync(bundledAddonsDir)) {
core.setFailed(`Lua-addons directory not found at: ${bundledAddonsDir}`);
return;
}
// Get the workspace root and resolve destination path
const workspaceRoot = process.env.GITHUB_WORKSPACE || process.cwd();
const absoluteDestinationPath = path.join(workspaceRoot, destinationPath);
core.info(`Copying lua-addons to: ${absoluteDestinationPath}`);
// Create destination directory if it doesn't exist
await fs.mkdir(absoluteDestinationPath, { recursive: true });
// Copy all bundled addons to the destination
const addons = await fs.readdir(bundledAddonsDir, { withFileTypes: true });
for (const addon of addons) {
if (addon.isDirectory()) {
const sourceAddonDir = path.join(bundledAddonsDir, addon.name);
const destAddonDir = path.join(absoluteDestinationPath, addon.name);
core.info(`Installing addon: ${addon.name}`);
await copyDirectory(sourceAddonDir, destAddonDir);
core.info(`✓ ${addon.name} installed`);
}
}
core.info('Lua addons installation completed successfully.');
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
} else {
core.setFailed('An unknown error occurred');
}
}
}
run();