-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test deletion issue and infinite loop issue fixed * added formatter for shell scripting * Added test for dependencies * dependecy test removed from ci * redeloy removed from ci * Deletion test fixed * startup autodeploy added * condtion corrected * dependency issue solved
- Loading branch information
Showing
7 changed files
with
176 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,81 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
import { Resource } from '../app'; | ||
import { exec } from './exec'; | ||
|
||
const createInstallDependenciesScript = ( | ||
runner: string, | ||
path: string | ||
): string => { | ||
type Runner = 'python' | 'nodejs' | 'ruby' | 'csharp'; | ||
|
||
const targetFiles: Record<Runner, string> = { | ||
nodejs: 'package.json', | ||
python: 'requirements.txt', | ||
ruby: 'Gemfile', | ||
csharp: 'project.json' | ||
}; | ||
|
||
const isRunner = (runner: string): runner is Runner => { | ||
return ['nodejs', 'python', 'ruby', 'csharp'].includes(runner); | ||
}; | ||
|
||
const findDependencyFile = async ( | ||
dir: string, | ||
runner: Runner | ||
): Promise<string | null> => { | ||
const files = await fs.readdir(dir); | ||
|
||
for (const file of files) { | ||
const fullPath = path.join(dir, file); | ||
const stat = await fs.stat(fullPath); | ||
|
||
if (stat.isDirectory()) { | ||
const result = await findDependencyFile(fullPath, runner); | ||
if (result) return result; | ||
} else if (file === targetFiles[runner]) { | ||
return dir; | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
const createInstallDependenciesScript = async ( | ||
runner: Runner, | ||
basePath: string | ||
): Promise<string> => { | ||
const dependencyFilePath = await findDependencyFile(basePath, runner); | ||
|
||
if (!dependencyFilePath) { | ||
throw new Error(`No ${runner} dependencies file found`); | ||
} | ||
|
||
const installDependenciesScript: Record<string, string> = { | ||
python: `cd ${path} && metacall pip3 install -r requirements.txt`, | ||
nodejs: `cd ${path} && metacall npm i`, | ||
ruby: `cd ${path} && metacall bundle install`, | ||
csharp: `cd ${path} && metacall dotnet restore && metacall dotnet release` | ||
python: `cd ${dependencyFilePath} && metacall pip3 install -r requirements.txt`, | ||
nodejs: `cd ${dependencyFilePath} && metacall npm i`, | ||
ruby: `cd ${dependencyFilePath} && metacall bundle install`, | ||
csharp: `cd ${dependencyFilePath} && metacall dotnet restore && metacall dotnet release` | ||
}; | ||
return installDependenciesScript[runner]; | ||
}; | ||
|
||
// Todo: Async Error Handling | ||
export const installDependencies = async ( | ||
resource: Resource | ||
): Promise<void> => { | ||
if (!resource.runners) return; | ||
|
||
for (const runner of resource.runners) { | ||
if (runner == undefined) continue; | ||
else { | ||
await exec(createInstallDependenciesScript(runner, resource.path)); | ||
if (runner && isRunner(runner)) { | ||
try { | ||
const script = await createInstallDependenciesScript( | ||
runner, | ||
resource.path | ||
); | ||
await exec(script); | ||
} catch (err) { | ||
console.error( | ||
`Failed to install dependencies for runner ${runner}:`, | ||
err | ||
); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import requests | ||
|
||
# Fetch random joke function | ||
def fetchJoke(): | ||
try: | ||
response = requests.get('https://official-joke-api.appspot.com/random_joke') | ||
response.raise_for_status() # Raise an error for bad status codes | ||
joke = response.json() | ||
return { | ||
'setup': joke['setup'], | ||
'punchline': joke['punchline'] | ||
} | ||
except requests.RequestException as e: | ||
return {'message': 'Error fetching joke', 'error': str(e)} | ||
|
||
# Example usage | ||
if __name__ == "__main__": | ||
joke = fetchJoke() | ||
print(joke) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"language_id": "py", | ||
"path": ".", | ||
"scripts": ["handler.py"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters