Skip to content

Commit

Permalink
refactor: applying chmod and moving files
Browse files Browse the repository at this point in the history
Signed-off-by: vados <[email protected]>
  • Loading branch information
t3hmrman committed Nov 25, 2024
1 parent 63d8c8c commit 74b63b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ jobs:
repo: bytecodealliance/weval
tag: ${{ matrix.version }}
extension: "\\.xz"
- run:
tree /opt/hostedtoolcache/bytecodealliance/latest/linux-x64
ls -la /opt/hostedtoolcache/bytecodealliance/latest/linux-x64
- run:
weval --version

44 changes: 29 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,26 +295,40 @@ async function run() {
core.info(`Automatically extracted release asset ${asset.name} to ${dest}`);

// Attempt to find an extracted binary
const bins = fs.readdirSync(finalBinLocation, { recursive: true, withFileTypes: true })
.filter(item => item.name.includes(assetName) && item.isFile())
.map(bin => bin.name);
if (bins.length === 0)
const binFiles = fs.readdirSync(finalBinLocation, { recursive: true, withFileTypes: true })
.filter(item => item.name.includes(assetName) && item.isFile());
if (binFiles.length === 0)
throw new Error(`No files found in ${finalBinLocation}`);
else if (bins.length > 1 && renameTo !== "") {
else if (binFiles.length > 1 && renameTo !== "") {
core.warning("rename-to parameter ignored when installing \
a release from an archive that contains multiple files.");
}

if (chmodTo !== "") {
bins.forEach(bin => {
const binPath = path.join(finalBinLocation, bin);
try {
fs.chmodSync(binPath, chmodTo);
core.info(`chmod'd ${binPath} to ${chmodTo}`)
} catch (chmodErr) {
core.setFailed(`Failed to chmod ${binPath} to ${chmodTo}: ${chmodErr}`);
}
});
// Ensure binaries that were found are in the dir that will be added to PATH
for (const { parentPath, name } of binFiles) {
const currentBinPath = path.resolve(path.join(parentPath, name));
const finalBinPath = path.resolve(path.join(finalBinLocation, name));

// If the binary is in a path *other* than the one that will be added to PATH
// copy it over
if (currentBinPath != finalBinPath) {
try {
core.debug(`detected binary not in folder on PATH, copying binary from [${currentBinPath}] to [${finalBinPath}]`);
fs.copyFileSync(currentBinPath, finalBinPath);
} catch (copyErr) {
core.setFailed(`Failed to copy binary to folder in PATH: ${copyErr}`);
}
}

// Apply chmod if configured
if (chmodTo !== "") {
try {
fs.chmodSync(binPath, chmodTo);
core.info(`chmod'd ${binPath} to ${chmodTo}`)
} catch (chmodErr) {
core.setFailed(`Failed to chmod ${binPath} to ${chmodTo}: ${chmodErr}`);
}
}
}
} else {
// As it wasn't an archive we've just downloaded it as a blob, this uses an auto-assigned name which will
Expand Down

0 comments on commit 74b63b8

Please sign in to comment.