Skip to content

Revert "Merge pull request #5594 from DataDog/apmlp-1090-remove-jruby… #1

Revert "Merge pull request #5594 from DataDog/apmlp-1090-remove-jruby…

Revert "Merge pull request #5594 from DataDog/apmlp-1090-remove-jruby… #1

Workflow file for this run

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:
id-token: write
pull-requests: write
runs-on: ubuntu-24.04
steps:
- name: Get GitHub Token via dd-octo-sts
id: generate-token
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
with:
scope: DataDog/dd-trace-rb
policy: self.typing-stats
- name: Find existing comment
id: comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.generate-token.outputs.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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Ruby
uses: ruby/setup-ruby@a30dfa457ad68707b8b910ac3a244714b61c0626 # v1.320.0
with:
ruby-version: "4.0"
- name: Install steep
# zizmor: ignore[adhoc-packages] pinned tool install for computing typing stats, not an app dependency
run: gem install steep -v 2.0
- 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.generate-token.outputs.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})
}