Skip to content

Commit 28b826c

Browse files
authored
Better logging (#5)
* replace `throw new Error` with `setFailed` * replace `console.log` with `githubCore.info` * use `githubCore.setOutput` to set GHC version output
1 parent bd83965 commit 28b826c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ function parseBaseUpperBound(packageYamlPath) {
6565

6666
const baseDep = deps.find(dep => dep.startsWith("base"));
6767
if (!baseDep) {
68-
throw new Error("No base dependency found in package.yaml");
68+
githubCore.setFailed("No base dependency found in package.yaml");
6969
}
7070

7171
const versionConstraint = getBaseUpperBound(baseDep);
7272
if (!versionConstraint) {
73-
throw new Error("No upper bound for base found in package.yaml");
73+
githubCore.setFailed("No upper bound for base found in package.yaml");
7474
}
7575

7676
return versionConstraint;
@@ -94,9 +94,9 @@ async function main() {
9494
}).filter(Boolean);
9595

9696
if (ghcupList.length > 0) {
97-
console.log(`Found ${ghcupList.length} GHC versions`);
97+
githubCore.info(`Found ${ghcupList.length} GHC versions`);
9898
} else {
99-
throw new Error('Failed to get GHC versions from GHCup');
99+
githubCore.setFailed('Failed to get GHC versions from GHCup');
100100
}
101101

102102
const validVersions = ghcupList.filter(ghcEntry => {
@@ -121,13 +121,11 @@ async function main() {
121121

122122
const latestGhc = validVersions[0].version;
123123

124-
console.log(`Latest GHC under base < ${baseUpperBound.version}: ${latestGhc}`);
124+
githubCore.info(`Latest GHC under base < ${baseUpperBound.version}: ${latestGhc}`);
125125

126-
const outputPath = process.env.GITHUB_OUTPUT;
127-
fs.appendFileSync(outputPath, `ghc-version=${latestGhc}\n`);
126+
githubCore.setOutput('ghc-version', latestGhc);
128127
} catch (err) {
129-
console.error(err);
130-
process.exit(1);
128+
githubCore.setFailed(err.message);
131129
}
132130
}
133131

0 commit comments

Comments
 (0)