Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 56c7172

Browse files
authored
Refactor TypeScripts error monitoring workflow to avoid tracking checkstyle.xml (#7717)
1 parent cef076a commit 56c7172

File tree

5 files changed

+26
-4246
lines changed

5 files changed

+26
-4246
lines changed

.github/monitor-typescript-errors/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ inputs:
44
repo-token:
55
description: 'GitHub token'
66
required: true
7-
compare:
8-
description: 'Path checkstyle.xml file'
7+
checkstyle:
8+
description: 'Path checkstyle.xml file of current PR/branch'
9+
required: true
10+
checkstyle-trunk:
11+
description: 'Path checkstyle.xml file of trunk'
912
required: true
1013

1114
runs:

.github/monitor-typescript-errors/index.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,26 @@ const { setFailed, getInput } = require( '@actions/core' );
44
const { parseXml, getFilesWithNewErrors } = require( './utils/xml' );
55
const { generateMarkdownMessage } = require( './utils/markdown' );
66
const { addRecord } = require( './utils/airtable' );
7-
const { getFileContent, addComment } = require( './utils/github' );
7+
const { addComment } = require( './utils/github' );
88

99
const runner = async () => {
1010
const token = getInput( 'repo-token', { required: true } );
1111
const octokit = getOctokit( token );
1212
const payload = context.payload;
1313
const repo = payload.repository.name;
1414
const owner = payload.repository.owner.login;
15-
const fileName = getInput( 'compare', {
15+
const fileName = getInput( 'checkstyle', {
16+
required: true,
17+
} );
18+
const trunkFileName = getInput( 'checkstyle-trunk', {
1619
required: true,
1720
} );
1821

1922
const newCheckStyleFile = fs.readFileSync( fileName );
2023
const newCheckStyleFileParsed = parseXml( newCheckStyleFile );
21-
const currentCheckStyleFile = await getFileContent( {
22-
octokit,
23-
owner,
24-
repo,
25-
fileName,
26-
onFail: setFailed,
27-
} );
28-
29-
if ( ! currentCheckStyleFile.data ) {
30-
setFailed( 'No Content Available' );
31-
return;
32-
}
33-
24+
const currentCheckStyleFile = fs.readFileSync( trunkFileName );
3425
const currentCheckStyleFileContentParsed = parseXml(
35-
currentCheckStyleFile.data
26+
currentCheckStyleFile
3627
);
3728

3829
const { header } = generateMarkdownMessage( newCheckStyleFileParsed );

.github/monitor-typescript-errors/utils/github.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
exports.getFileContent = async ( {
2-
octokit,
3-
owner,
4-
repo,
5-
fileName,
6-
onFail,
7-
} ) => {
8-
try {
9-
return await octokit.rest.repos.getContent( {
10-
owner,
11-
repo,
12-
path: fileName,
13-
mediaType: {
14-
format: 'raw',
15-
},
16-
} );
17-
} catch ( err ) {
18-
if ( err.status === '404' ) {
19-
return;
20-
}
21-
22-
onFail( err.message );
23-
}
24-
};
25-
261
const getReportCommentId = async ( { octokit, owner, repo, payload } ) => {
272
const currentComments = await octokit.rest.issues.listComments( {
283
owner,

.github/workflows/typescript-monitoring.yml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ jobs:
88
check-typescript-errors-with-trunk:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
with:
13-
ref: ${{ github.event.pull_request.head.ref }}
13+
ref: 'trunk'
1414

1515
- name: Cache node modules
1616
uses: actions/cache@v3
@@ -30,10 +30,19 @@ jobs:
3030
node-version-file: '.nvmrc'
3131
cache: 'npm'
3232

33-
- name: npm install
33+
- name: Generate checkstyle for trunk
3434
run: |
3535
npm ci
3636
npm run ts:log-errors
37+
mv checkstyle.xml $HOME/checkstyle-trunk.xml
38+
39+
- uses: actions/checkout@v3
40+
41+
- name: Generate checkstyle for current PR
42+
run: |
43+
npm ci
44+
npm run ts:log-errors
45+
mv $HOME/checkstyle-trunk.xml checkstyle-trunk.xml
3746
3847
- name: Get branch name
3948
id: branch-name
@@ -43,21 +52,8 @@ jobs:
4352
uses: ./.github/monitor-typescript-errors
4453
with:
4554
repo-token: '${{ secrets.GITHUB_TOKEN }}'
46-
compare: checkstyle.xml
55+
checkstyle: checkstyle.xml
56+
checkstyle-trunk: checkstyle-trunk.xml
4757
env:
4858
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
4959
CURRENT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
50-
51-
- name: Check if the checklist.xml file is changed
52-
id: verify_diff
53-
run: |
54-
git diff --quiet checkstyle.xml || echo "is_different_checkstyle=true" >> $GITHUB_OUTPUT
55-
56-
- name: Commit the new checklist.xml file
57-
if: steps.verify_diff.outputs.is_different_checkstyle == 'true'
58-
run: |
59-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
60-
git config --global user.name "github-actions[bot]"
61-
git add checkstyle.xml
62-
git commit -m "bot: update checkstyle.xml"
63-
git push

0 commit comments

Comments
 (0)