[PROF-12743] Runtime stack collection callback registration #876
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: Comment typing stats on PR | |
| on: # yamllint disable-line rule:truthy | |
| pull_request: | |
| branches: | |
| - master | |
| # TODO: | |
| # Upload the report somewhere not limited by the 64k char limit (maybe FPD ?) to be able to include links to the files | |
| # Compare the result with master to see if there are any progress/regression | |
| # Create a Datadog dashboard to track the progress on a larger timescale | |
| jobs: | |
| compute-stats: | |
| permissions: | |
| pull-requests: write | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Find existing comment | |
| id: comment | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| const options = github.rest.issues.listComments.endpoint.merge({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| }); | |
| const comments = await github.paginate(options) | |
| const comment = comments.find((cmnt) => { | |
| return cmnt.body.startsWith("<!-- TYPING_STATS_HIDDEN_MARKER -->") | |
| }) | |
| return undefined === comment ? null : comment.id | |
| - name: Checkout current branch | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0 | |
| with: | |
| ruby-version: "3.4" | |
| - name: Install steep | |
| run: gem install steep -v 1.10 | |
| - name: Copy scripts to directory outside of workspace | |
| run: | | |
| cp .github/scripts/typing_stats_compute.rb ${{ runner.temp }}/typing_stats_compute.rb | |
| cp .github/scripts/typing_stats_compare.rb ${{ runner.temp }}/typing_stats_compare.rb | |
| - name: Run typing stats on current branch | |
| id: typing-stats-current | |
| env: | |
| STEEPFILE_PATH: ${{ github.workspace }}/Steepfile | |
| run: | | |
| mkdir -p "${{ github.workspace }}/tmp" | |
| ruby ${{ runner.temp }}/typing_stats_compute.rb >> "${{ runner.temp }}/typing-stats-current.json" | |
| - name: Checkout base branch | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| persist-credentials: false | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| - name: Run typing stats on base branch | |
| id: typing-stats-base | |
| env: | |
| STEEPFILE_PATH: ${{ github.workspace }}/Steepfile | |
| run: ruby ${{ runner.temp }}/typing_stats_compute.rb >> "${{ runner.temp }}/typing-stats-base.json" | |
| - name: Run typing stats compare | |
| id: typing-stats-compare | |
| env: | |
| CURRENT_STATS_PATH: ${{ runner.temp }}/typing-stats-current.json | |
| BASE_STATS_PATH: ${{ runner.temp }}/typing-stats-base.json | |
| run: ruby ${{ runner.temp }}/typing_stats_compare.rb >> "${{ runner.temp }}/typing-stats-compare.md" | |
| - name: Write comment | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| var fs = require('fs') | |
| const previousCommentId = ${{steps.comment.outputs.result}} | |
| const commentContent = fs.readFileSync("${{ runner.temp }}/typing-stats-compare.md", "utf8") | |
| const commentBody = `<!-- TYPING_STATS_HIDDEN_MARKER --> | |
| ## Typing analysis | |
| ${commentContent} | |
| ` | |
| const thankYouBody = `<!-- TYPING_STATS_HIDDEN_MARKER --> | |
| ## Typing analysis | |
| *This PR does not change typing compared to the base branch.* | |
| ` | |
| const options = { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| body: commentContent !== "" ? commentBody : thankYouBody | |
| } | |
| if (null === previousCommentId && commentContent !== "") { | |
| await github.rest.issues.createComment(options) | |
| } else if (previousCommentId) { | |
| await github.rest.issues.updateComment({...options, comment_id: previousCommentId}) | |
| } |