Skip to content

Commit

Permalink
trying a bash script on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline committed Aug 29, 2024
1 parent 6076c77 commit 785b281
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
const core = require("@actions/core");
const exec = require("@actions/exec");
const fs = require("fs").promises;
const path = require("path");

async function run() {
try {
const pizzaArgs = core.getInput("pizza-args");
const args = pizzaArgs.split(/\s+/).filter((arg) => arg.length > 0);

console.log("Running Pizza CLI with args:", args);
await exec.exec("pizza", args);

// Create a temporary bash script
const scriptContent = `#!/bin/bash
set -e
pizza ${args.map((arg) => `"${arg}"`).join(" ")}
`;

const scriptPath = path.join(process.cwd(), "run_pizza.sh");
console.log("Script content:", scriptContent);
console.log("Script path:", scriptPath);

await fs.writeFile(scriptPath, scriptContent);
await fs.chmod(scriptPath, "0755"); // Make the script executable

// Execute the bash script
await exec.exec(`bash ${scriptPath}`);

// Remove the temporary script
await fs.unlink(scriptPath);

// Add and commit changes
await exec.exec("git config --global user.name github-actions");
Expand All @@ -16,6 +36,7 @@ async function run() {
await exec.exec('git commit -m "Auto-commit from OpenSauced Pizza Action"');
await exec.exec("git push");
} catch (error) {
console.error("Error:", error);
core.setFailed(error.message);
}
}
Expand Down

0 comments on commit 785b281

Please sign in to comment.