@@ -15,113 +15,48 @@ jobs:
1515 pull-requests : write
1616 runs-on : ubuntu-24.04
1717 steps :
18- - name : Find existing comment
19- id : comment
20- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
21- with :
22- github-token : ${{secrets.GITHUB_TOKEN}}
23- script : |
24- const options = github.rest.issues.listComments.endpoint.merge({
25- owner: context.repo.owner,
26- repo: context.repo.repo,
27- issue_number: context.payload.pull_request.number,
28- });
29- const comments = await github.paginate(options)
30- const comment = comments.find((cmnt) => {
31- return cmnt.body.startsWith("<!-- TYPING_STATS_HIDDEN_MARKER -->")
32- })
33-
34- return undefined === comment ? null : comment.id
35-
36- - name : Checkout code
18+ - name : Checkout current branch
3719 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3820 with :
3921 persist-credentials : false
4022
4123 - name : Set up Ruby
4224 uses : ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0
4325 with :
44- ruby-version : " 3.3 "
26+ ruby-version : " 3.4 "
4527
4628 - name : Install steep
47- run : gem install steep -v 1.9.1
29+ run : gem install steep -v 1.10
4830
49- - name : Run typing stats
50- id : typing-stats
31+ - name : Copy scripts to directory outside of workspace
32+ run : |
33+ cp .github/scripts/typing_stats_compute.rb ${{ runner.temp }}/typing_stats_compute.rb
34+ cp .github/scripts/typing_stats_compare.rb ${{ runner.temp }}/typing_stats_compare.rb
35+
36+ - name : Run typing stats on current branch
37+ id : typing-stats-current
5138 env :
5239 STEEPFILE_PATH : ${{ github.workspace }}/Steepfile
5340 run : |
5441 mkdir -p "${{ github.workspace }}/tmp"
55- ruby .github/scripts/typing_stats .rb >> "${{ github.workspace }}/tmp/ typing-stats.json"
42+ ruby ${{ runner.temp }}/typing_stats_compute .rb >> "${{ runner.temp }}/typing-stats-current .json"
5643
57- - name : Write comment
58- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
44+ - name : Checkout base branch
45+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5946 with :
60- github-token : ${{secrets.GITHUB_TOKEN}}
61- script : |
62- var fs = require('fs')
63-
64- const previousCommentId = ${{steps.comment.outputs.result}}
65- const stats = JSON.parse(fs.readFileSync("${{ github.workspace }}/tmp/typing-stats.json", "utf8"))
66-
67- const typedFilesPercentage = ((stats.total_files_size - stats.ignored_files.size) / stats.total_files_size * 100).toFixed(2)
68-
69- const totalMethods = stats.untyped_methods.length + stats.partially_typed_methods.length + stats.typed_methods_size
70- const typedMethodsPercentage = (stats.typed_methods_size / totalMethods * 100).toFixed(2)
71-
72- const totalOthers = stats.untyped_others.length + stats.partially_typed_others.length + stats.typed_others_size
73- const typedOthersPercentage = (stats.typed_others_size / totalOthers * 100).toFixed(2)
74-
75- const commentBody = `<!-- TYPING_STATS_HIDDEN_MARKER -->
76- ## Typing analysis
77-
78- ### Ignored files
79- There are **${stats.ignored_files.size}** ignored files in the Steepfile out of ${stats.total_files_size}.
80- **${typedFilesPercentage}%** of the codebase is type checked.
81- <details><summary>Ignored files</summary>
82- <pre><code>${stats.ignored_files.paths.map((path) => `${path}`).join('\n')}</code></pre>
83- </details>
84-
85- *__Note__: Ignored files are excluded from the next sections.*
86-
87- ### \`steep:ignore\` comments
88- There are **${stats.steep_ignore_comments.length}** \`steep:ignore\` comments in the codebase.
89- <details><summary><code>steep:ignore</code> comments</summary>
90- <pre><code>${stats.steep_ignore_comments.map((comment) => `${comment.path}:${comment.line}`).join('\n')}</code></pre>
91- </details>
92-
93- ### Untyped methods
94- There are **${stats.untyped_methods.length}** untyped and **${stats.partially_typed_methods.length}** partially typed methods out of ${totalMethods}.
95- **${typedMethodsPercentage}%** of the methods are typed.
96- <details><summary>Untyped methods</summary>
97- <pre><code>${stats.untyped_methods.map((method) => `${method.path}:${method.line}\n└── ${method.line_content}`).join('\n')}</code></pre>
98- </details>
99- <details><summary>Partially typed methods</summary>
100- <pre><code>${stats.partially_typed_methods.map((method) => `${method.path}:${method.line}\n└── ${method.line_content}`).join('\n')}</code></pre>
101- </details>
102-
103- ### Untyped attributes, constants, globals, instance variables
104- There are **${stats.untyped_others.length}** untyped and **${stats.partially_typed_others.length}** partially typed attributes, constants, globals, instance variables out of **${totalOthers}**.
105- **${typedOthersPercentage}%** of them are typed.
106- <details><summary>Untyped attributes, constants, globals, instance variables</summary>
107- <pre><code>${stats.untyped_others.map((other) => `${other.path}:${other.line}\n└── ${other.line_content}`).join('\n')}</code></pre>
108- </details>
109- <details><summary>Partially typed attributes, constants, globals, instance variables</summary>
110- <pre><code>${stats.partially_typed_others.map((other) => `${other.path}:${other.line}\n└── ${other.line_content}`).join('\n')}</code></pre>
111- </details>
112-
113- *If you believe a method or an attribute is rightfully untyped or partially typed, you can add \`# untyped:accept\` to the end of the line to remove it from the stats.*
114- `
47+ persist-credentials : false
48+ ref : ${{ github.event.pull_request.base.ref }}
11549
116- const options = {
117- owner: context.repo.owner,
118- repo: context.repo.repo,
119- issue_number: context.payload.pull_request.number,
120- body: commentBody
121- }
50+ - name : Run typing stats on base branch
51+ id : typing-stats-base
52+ env :
53+ STEEPFILE_PATH : ${{ github.workspace }}/Steepfile
54+ run : ruby ${{ runner.temp }}/typing_stats_compute.rb >> "${{ runner.temp }}/typing-stats-base.json"
12255
123- if (null === previousCommentId) {
124- await github.rest.issues.createComment(options)
125- } else {
126- await github.rest.issues.updateComment({...options, comment_id: previousCommentId})
127- }
56+ - name : Run typing stats compare
57+ id : typing-stats-compare
58+ env :
59+ CURRENT_STATS_PATH : ${{ runner.temp }}/typing-stats-current.json
60+ BASE_STATS_PATH : ${{ runner.temp }}/typing-stats-base.json
61+ # run: ruby ${{ runner.temp }}/typing_stats_compare.rb >> "${{ runner.temp }}/typing-stats-compare.json"
62+ run : ruby ${{ runner.temp }}/typing_stats_compare.rb
0 commit comments