Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "Alpine",
"image": "mcr.microsoft.com/devcontainers/base:alpine-3.21",
"name": ".github",
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": false
},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"remoteEnv": {
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
},
"customizations": {
"vscode": {
"extensions": [
Expand Down
51 changes: 37 additions & 14 deletions .github/actions/generate-resume-pdf/generate-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,41 @@ const buildRenderOptions = (resumeData, resumePath) => {
};

const optimizePdf = async (inputPath) => {
const tempPath = inputPath.replace(/\.pdf$/i, ".optimized.tmp.pdf");
await fs.unlink(tempPath).catch(() => undefined);
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "resume-optimize-"));
const tempInputPath = path.join(tempDir, path.basename(inputPath));
const tempPath = path.join(
tempDir,
path.basename(inputPath).replace(/\.pdf$/i, ".optimized.tmp.pdf"),
);

const originalStats = await fs.stat(inputPath);
await execFileAsync("gs", [
"-sDEVICE=pdfwrite",
"-dCompatibilityLevel=1.4",
"-dPDFSETTINGS=/ebook",
"-dNOPAUSE",
"-dQUIET",
"-dBATCH",
`-sOutputFile=${tempPath}`,
inputPath,
]);
await fs.copyFile(inputPath, tempInputPath);
try {
await execFileAsync("gs", [
"-sDEVICE=pdfwrite",
"-dCompatibilityLevel=1.4",
"-dPDFSETTINGS=/ebook",
"-dNOPAUSE",
"-dQUIET",
"-dBATCH",
`-sOutputFile=${tempPath}`,
tempInputPath,
]);
} catch (error) {
if (error?.code === "ENOENT") {
throw new Error(
"Ghostscript is required for PDF optimization but was not found in PATH.",
);
}
throw error;
}

const optimizedStats = await fs.stat(tempPath);

await fs.unlink(inputPath);
await fs.rename(tempPath, inputPath);
await fs.copyFile(tempPath, inputPath);
await fs.unlink(tempInputPath).catch(() => undefined);
await fs.unlink(tempPath).catch(() => undefined);
await fs.rmdir(tempDir).catch(() => undefined);

const reduction =
((originalStats.size - optimizedStats.size) / originalStats.size) * 100;
Expand Down Expand Up @@ -155,6 +171,10 @@ async function generatePagedPdfFromHtml(htmlPath, outputPath, renderOptions) {
const { PDFDocument } = require("pdf-lib");

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const isContainerized = await fs
.access("/.dockerenv")
.then(() => true)
.catch(() => false);

const shouldDisableSandbox = (() => {
if (process.env.PUPPETEER_NO_SANDBOX === "1") {
Expand All @@ -163,6 +183,9 @@ async function generatePagedPdfFromHtml(htmlPath, outputPath, renderOptions) {
if (process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true") {
return true;
}
if (isContainerized) {
return true;
}
if (typeof process.getuid === "function" && process.getuid() === 0) {
return true;
}
Expand Down
Loading
Loading