Created
December 15, 2024 21:53
-
-
Save sassman/0a094b942e5bba43da50308654b83f7e to your computer and use it in GitHub Desktop.
GitHub Action for flamegraphs on PR as comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flamegraph PR | |
on: | |
pull_request: | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
flamegraph: | |
if: contains(github.event.pull_request.labels.*.name, 'flamegraph') | |
name: flamegraph | |
runs-on: ubuntu-latest | |
timeout-minutes: 8 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: determine the new added project | |
id: determine_project | |
run: | | |
# Get the name of the main branch (assuming it's 'main') | |
MAIN_BRANCH="main" | |
# Fetch the main branch | |
git fetch origin $MAIN_BRANCH:$MAIN_BRANCH | |
NEW_FOLDER=$(git diff --name-status $MAIN_BRANCH | grep -E '^[AM]' | awk '{print $2}' | grep 'Cargo.toml' | awk -F/ '{printf("%s/%s\n", $1, $2)}' | uniq) | |
# Extract the names of new folders | |
if [[ -z "$NEW_FOLDER" ]]; then | |
echo "No new project found - skipping the build" | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
fi | |
# Set the output variable | |
echo "PROJECT_FOLDER=$NEW_FOLDER" >> "$GITHUB_OUTPUT" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: setup | rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
default: true | |
profile: minimal | |
- name: build | |
run: cargo build --release | |
working-directory: ${{ steps.determine_project.outputs.PROJECT_FOLDER }} | |
- name: install flamegraph | |
run: cargo install flamegraph | |
- name: generate flamegraph | |
run: | | |
cargo flamegraph --root --verbose --cmd "record -F 997 --call-graph dwarf,16384 -g -o /tmp/perf.data" -- ../../samples/weather_1M.csv | |
shell: bash | |
working-directory: ${{ steps.determine_project.outputs.PROJECT_FOLDER }} | |
env: | |
CARGO_PROFILE_RELEASE_DEBUG: "true" | |
- name: rename the flamegraph to gitsha and run.id | |
run: | | |
mkdir -p guide/book/_flamegraphs | |
mv ${{ steps.determine_project.outputs.PROJECT_FOLDER }}/flamegraph.svg guide/book/_flamegraphs/flamegraph-${{ github.sha }}-${{ github.run_id }}.svg | |
shell: bash | |
- name: Store flamegraph | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: guide/book | |
keep_files: true | |
- name: post comment | |
run: | | |
# link of the just uploaded artefact | |
# TODO: replace the things in the URL below with your stuff | |
LINK='https://<your-org-or-gh-handle>.github.io/<repo-name>/_flamegraphs/flamegraph-${{ github.sha }}-${{ github.run_id }}.svg' | |
GITSHA=$(git rev-parse HEAD) | |
echo "### Flamegraph at $GITSHA" > comment.md | |
echo "" >> comment.md | |
echo "" >> comment.md | |
echo "" >> comment.md | |
# Post the comment to the PR | |
gh pr comment ${{ github.event.pull_request.number }} -F comment.md | |
env: | |
GH_TOKEN: ${{ github.token }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment