forked from DataDog/dd-trace-rb
-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (103 loc) · 4.65 KB
/
Copy pathtyping-stats.yml
File metadata and controls
119 lines (103 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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})
}