Skip to content

Commit

Permalink
Use upload-core-dumps (#32)
Browse files Browse the repository at this point in the history
* Use upload-core-dumps

* Use upload-core-dumps
  • Loading branch information
ianks committed Feb 22, 2024
1 parent becb7b4 commit 8febd04
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test-cross-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- "cross-gem/**/*"
- ".github/workflows/test-cross-gem.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
SCCACHE_LOG: debug
jobs:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/test-post-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: test-upload-post-run
on:
push:
paths:
- "post-run/**/*"
- ".github/workflows/test-post-run.yml"
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
steps:
- uses: actions/checkout@v4

- uses: ./post-run
with:
run: |
echo "Running post-run"
ls -la .
20 changes: 15 additions & 5 deletions .github/workflows/test-setup-ruby-and-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
- "setup-ruby-and-rust/**/*"
- ".github/workflows/test-setup-ruby-and-rust.yml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
SCCACHE_LOG: debug
jobs:
Expand All @@ -25,10 +27,10 @@ jobs:
- name: "matsadler/magnus"
slug: magnus
ref: main
run: cargo test -- --nocapture
run: cargo test -- --nocapture --skip it_includes_backtrace_in_debug
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
rust: ["stable"]
ruby: ["3.0", "3.1", "3.2", "3.3"]
ruby: ["3.0", "3.1", "3.2", "3.3", "head"]
cargo-cache: ["true"]
include:
- os: "ubuntu-latest"
Expand Down Expand Up @@ -61,7 +63,7 @@ jobs:
name: "matsadler/magnus"
slug: magnus
ref: main
run: cargo test -- --nocapture || echo "::warning::cargo test failed on mswin"
run: cargo test -- --nocapture --skip it_includes_backtrace_in_debug || echo "::warning::cargo test failed on mswin"

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -78,6 +80,7 @@ jobs:
- uses: actions/checkout@v4
with:
path: ./tmp/actions
- uses: ./tmp/actions/upload-core-dumps
- uses: ./tmp/actions/setup-ruby-and-rust
id: setup
with:
Expand All @@ -93,4 +96,11 @@ jobs:
run: ruby ./tmp/actions/setup-ruby-and-rust/test.rb -v
- name: Run tests for ${{ matrix.repo.name }}
shell: bash
run: ${{ matrix.repo.run }}
run: |
: ${{ matrix.repo.run }}
if [[ "${{runner.os}}" != "Windows" ]]; then
ulimit -c unlimited # Enable core dumps
fi
${{ matrix.repo.run }}
4 changes: 4 additions & 0 deletions .github/workflows/test-upload-core-dumps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
run: |
ulimit -c unlimited # Enable core dumps
if [ "$RUNNER_OS" = "Windows" ]; then
drmingw -i || true
fi
echo "::group::Write some C code to crash"
echo "int main() { return *(int*)0 = 1; }" > segfault.c
if [ "$RUNNER_OS" = "Windows" ]; then
Expand Down
10 changes: 8 additions & 2 deletions post-run/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ console.log(`::info::Running command in ${cwd}:\n\n${run}`);
const options = {
cwd: cwd,
stdio: ["pipe", process.stdout, process.stderr],
shell: "/bin/bash",
};
let shell;

const bashProcess = spawn("/bin/bash", [], options);
if (process.env.RUNNER_OS === "Windows") {
shell = "C:\\msys64\\usr\\bin\\bash.EXE";
} else {
shell = "/bin/bash";
}

const bashProcess = spawn(shell, [], options);

bashProcess.stdin.write(run);
bashProcess.stdin.end();
Expand Down
2 changes: 1 addition & 1 deletion upload-core-dumps/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const { execSync } = require("child_process");
const { execSync, execFileSync } = require("child_process");
const fs = require("fs");
const os = require("os");

Expand Down
98 changes: 85 additions & 13 deletions upload-core-dumps/post.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
// @ts-check
const fs = require("fs");
const { execFileSync } = require("child_process");
const { execFileSync, execSync } = require("child_process");
const path = require("path");
const os = require("os");

const uploadScriptUrl =
"https://raw.githubusercontent.com/actions/upload-artifact/v4.3.1/dist/upload/index.js";
const filePath = path.join(__dirname, "downloaded_script.js");
const installPackagesScripts = {
linux: "sudo apt-get install -y lldb gdb",
darwin: "brew install llvm",
win32: "choco install llvm",
};

function log(message) {
const color = "\x1b[32m";
const reset = "\x1b[0m";
console.log(`${color}${message}${reset}`);
}

function logGroup(message, f) {
let ret;
try {
console.log(`::group::${message}`);
ret = f();
} finally {
console.log("::endgroup::");
}
}

function executeCommandForSummary(command, args) {
let markdownContent = "";
try {
const output = runCommandOrInstallPackage(command, args);
if (output) {
markdownContent += `### Command: \`${command} ${args.join(" ")}\`\n\n`;
markdownContent += "```bash\n" + output + "\n```\n\n";
}
console.log(output);
} catch (error) {
// If there's an error (e.g., command not found), include it in the markdown as well
markdownContent += `### Command: \`${command} ${args.join(
" "
)}\` (Failed)\n\n`;
markdownContent += "```bash\n" + error.stdout + "\n```\n\n";
}

let summary = process.env.GITHUB_STEP_SUMMARY;

if (summary && summary.length > 0) {
fs.appendFileSync(summary, markdownContent);
} else {
console.log(markdownContent);
}
}

function filterCoreDumps() {
const coresPath = "/cores";
let files;
Expand All @@ -24,15 +66,17 @@ function filterCoreDumps() {
}

let toUpload = [];
const maxSizeByes = 10 * 1024 * 1024 * 1024;

for (let file of files) {
const filePath = path.join(coresPath, file);
const stats = fs.statSync(filePath);
if (stats.size <= 50 * 1024 * 1024 * 1024) {

if (stats.size <= maxSizeByes) {
log(
`Adding ${file} to the list of cores to upload (size: ${
stats.size / 1024 / 1024
} MiB)`
stats.size / 1024 / 1024 / 1024
} GiB)`
);
toUpload.push(filePath);
} else {
Expand All @@ -46,26 +90,48 @@ function filterCoreDumps() {
return toUpload;
}

function logNotice(message) {
console.log(`::notice::${message}`);
}

function downloadFile(url, destPath) {
const args = ["--fail", "--silent", "--location", "--output", destPath, url];
const opts = { stdio: "inherit" }; // @ts-ignore
execFileSync("curl", args, opts);
}

function runCommandOrInstallPackage(cmd, args) {
let ret;
try {
ret = execFileSync(cmd, args, { encoding: "utf-8" });
} catch (error) {
const status = error.status;
if (status === 127) {
const installScript = installPackagesScripts[os.platform()];
if (installScript) {
logGroup(`Installing deps with: $ ${installScript}`, () => {
execSync(installScript, { stdio: "inherit" });
});
execFileSync(cmd, args, { encoding: "utf-8" });
} else {
log(
`::warning::Unsupported platform for installation on ${os.platform()}`
);
}
}
}
return ret;
}

function genHelpers(pathToCore) {
const relativePathToCore = "." + pathToCore;
const lldb = `
#!/bin/sh
lldb <<EOF
target create --core ${relativePathToCore}
bt all
quit
EOF
#!/usr/bin/env bash
lldb --core ${relativePathToCore} -o "bt all" -o "quit"
`;
const gdb = `
#!/bin/sh
gdb -x <<EOF
core-file ${relativePathToCore}
#!/usr/bin/env bash
gdb -quiet -core=${relativePathToCore} $INFERRED_EXECUTABLE <<EOF
bt
quit
EOF
Expand Down Expand Up @@ -117,18 +183,24 @@ function executeScript(scriptPath) {
fs.mkdirSync(outdir, { recursive: true });

for (let core of cores) {
logNotice(
`Found core dump at ${core}, copying it to ${outdir} (check summary for details)`
);
const coredest = path.join(outdir, core);
fs.mkdirSync(path.dirname(coredest), { recursive: true });
fs.copyFileSync(core, coredest);
const executable = inferCrashingExecutable(core);
if (executable) {
const exedest = path.join(outdir, "bin", executable);
process.env.INFERRED_EXECUTABLE = path.join("bin", executable);
fs.mkdirSync(path.dirname(exedest), { recursive: true });
fs.copyFileSync(executable, exedest);
}
}
process.chdir(outdir);
genHelpers(cores[0]);
executeCommandForSummary("sh", ["analyze-lldb"]);
executeCommandForSummary("sh", ["analyze-gdb"]);
process.chdir("..");

const arch = `${process.platform}-${process.arch}`;
Expand Down

0 comments on commit 8febd04

Please sign in to comment.