/
index.js
47 lines (37 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const core = require("@actions/core");
const github = require("@actions/github");
const path = require("path");
const puppeteer = require("puppeteer");
try {
core.startGroup("Async Processing");
return core
.group("Async Processing", async () => {
const filePath = core.getInput("path-to-markup-file");
const browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium-browser",
product: "chrome",
headless: true,
});
const page = await browser.newPage();
await page.goto(`file://${path.resolve(filePath)}`);
const branchName = github.context.ref.split("/").pop();
core.setOutput("branch-name", branchName);
const outputPdfPath = path.resolve(`${branchName}.pdf`);
const pdf = await page.pdf({
path: outputPdfPath,
format: "letter",
printBackground: true,
});
return outputPdfPath;
})
.then((data) => {
core.setOutput("output-pdf-path", data);
core.endGroup();
process.exit(0);
})
.catch((error) => {
core.setFailed(error.message);
});
} catch (error) {
core.setFailed(error.message);
}