Skip to content

Commit

Permalink
feat: improve error handling when a dependency is missing (#592)
Browse files Browse the repository at this point in the history
Co-authored-by: boyum <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
boyum and github-actions[bot] authored Sep 10, 2024
1 parent f35434d commit 7a6bcb1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ inputs:
required: false

runs:
using: node16
using: node20
main: dist/index.js
10 changes: 3 additions & 7 deletions demo/build_info/repos
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
https://github.com/h5p/blob
https://github.com/h5p/blob
https://github.com/h5p/blob
https://github.com/h5p/downloadify
https://github.com/h5p/drop
https://github.com/h5p/embeddedjs
https://github.com/h5p/filesaver
https://github.com/h5p/drop
https://github.com/h5p/drop
https://github.com/h5p/flowplayer
https://github.com/h5p/font-awesome
https://github.com/h5p/h5p-advanced-text
Expand Down Expand Up @@ -61,7 +57,7 @@ https://github.com/h5p/h5p-true-false.git
https://github.com/h5p/h5p-twitter-user-feed.git
https://github.com/h5p/h5p-video.git
https://github.com/h5p/jquery-ui.git
https://github.com/h5p/shepherd.git
# https://github.com/h5p/shepherd.git
https://github.com/h5p/tether.git
https://github.com/NDLANO/h5p-chart.git
https://github.com/NDLANO/h5p-drag-n-bar.git
Expand Down
19 changes: 16 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack-h5p-action",
"version": "1.0.1",
"version": "1.1.0",
"description": "Pack a H5P content type and its dependencies to a .h5p file",
"main": "lib/main.js",
"scripts": {
Expand Down
20 changes: 18 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,29 @@ async function cloneDependencies(
...new Set(
dependencyFile
.split("\n")
.filter(dependencyName => dependencyName.trim().length > 0),
.filter(dependencyName => dependencyName.trim().length > 0)
.filter(dependencyName => !dependencyName.startsWith("#")),
),
];

info(`Dependencies: ${JSON.stringify(dependencies)}`);
info(`Dependencies: ${JSON.stringify(dependencies, null, 2)}`);

return Promise.all(
dependencies.map(async dependency =>
exec(`git clone ${dependency}`, undefined, {
cwd: rootDir,
// eslint-disable-next-line github/no-then
}).catch(async error => {
let errorMessage = `Failed to clone ${dependency}: ${error}`;

switch (error) {
case "Error: The process '/usr/bin/git' failed with exit code 128":
errorMessage = `Failed to clone ${dependency}: The repository is probably either deleted or private. ${error}`;
break;
}

setFailed(errorMessage);
return Promise.reject(error);
}),
),
);
Expand All @@ -138,7 +151,10 @@ async function npmBuildProject(projectPath: string): Promise<void> {
const isNodeProject = fs.existsSync(`${projectPath}/package.json`);
if (isNodeProject) {
try {
info(`Installing dependencies in ${projectPath}`);
await exec("npm install", undefined, { cwd: projectPath });

info(`Building project in ${projectPath}`);
await exec("npm run build --if-present", undefined, {
cwd: projectPath,
});
Expand Down

0 comments on commit 7a6bcb1

Please sign in to comment.