-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de3e119
commit 9e9c773
Showing
7 changed files
with
129 additions
and
2 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
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,14 @@ | ||
import fs from "fs"; | ||
|
||
export const loadLockFile = (filePath: string) => { | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
return JSON.parse(fileContent); | ||
}; | ||
|
||
export const saveLockFile = ( | ||
filePath: string, | ||
actionName: string, | ||
version: string | ||
) => { | ||
fs.writeFileSync(filePath, JSON.stringify({ actionName, version }, null, 2)); | ||
}; |
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,60 @@ | ||
import logger from "../../utils/logger"; | ||
|
||
export const updateLockFileWithActionVersion = ( | ||
filePath: string, | ||
actionName: string, | ||
version: string | ||
) => { | ||
const actionVersions = getVersionsFromLockFileAsJson(filePath); | ||
actionVersions[actionName] = version; | ||
saveLockFile(filePath, actionVersions); | ||
}; | ||
|
||
export const getVersionsFromLockFileAsJson = (filePath: string) => { | ||
try { | ||
const lockFileContent = require("fs").readFileSync(filePath, "utf8"); | ||
Check warning on line 15 in js/src/sdk/utils/lockFile.ts GitHub Actions / lint-and-prettify
|
||
const actionVersions: Record<string, string> = {}; | ||
const lines = lockFileContent.split("\n"); | ||
for (const line of lines) { | ||
if (line) { | ||
const [actionName, version] = line.split("="); | ||
actionVersions[actionName] = version; | ||
} | ||
} | ||
return actionVersions; | ||
} catch (e) { | ||
const error = e as NodeJS.ErrnoException; | ||
if (error.code === "ENOENT") { | ||
logger.warn("Lock file does not exist, creating new one"); | ||
} else if (error.code === "EACCES" || error.code === "EPERM") { | ||
logger.error("Permission denied accessing lock file", e); | ||
} else { | ||
logger.warn("Error reading lock file", e); | ||
} | ||
return {}; | ||
} | ||
}; | ||
|
||
export const saveLockFile = ( | ||
filePath: string, | ||
actionVersions: Record<string, string> | ||
) => { | ||
try { | ||
const lockFileContent = Object.entries(actionVersions) | ||
.map(([actionName, version]) => `${actionName}=${version}`) | ||
.join("\n"); | ||
require("fs").writeFileSync(filePath, lockFileContent); | ||
Check warning on line 46 in js/src/sdk/utils/lockFile.ts GitHub Actions / lint-and-prettify
|
||
} catch (e) { | ||
const error = e as NodeJS.ErrnoException; | ||
if (error.code === "EACCES" || error.code === "EPERM") { | ||
logger.error("Permission denied writing to lock file", e); | ||
throw new Error("Permission denied writing to lock file"); | ||
} else if (error.code === "ENOENT") { | ||
logger.error("Directory does not exist for lock file", e); | ||
throw new Error("Directory does not exist for lock file"); | ||
} else { | ||
logger.error("Error writing to lock file", e); | ||
throw new Error("Error writing to lock file"); | ||
} | ||
} | ||
}; |
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,14 @@ | ||
import { RawActionData } from "../../../types/base_toolset"; | ||
|
||
export const actionLockProcessor = ( | ||
filePath: string, | ||
{ | ||
actionName, | ||
Check warning on line 6 in js/src/sdk/utils/processor/action_lock.ts GitHub Actions / lint-and-prettify
|
||
toolSchema, | ||
}: { | ||
actionName: string; | ||
toolSchema: RawActionData; | ||
} | ||
): RawActionData => { | ||
return toolSchema; | ||
}; |
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