Refactor TypeScripts error monitoring workflow to avoid tracking checkstyle.xml (https://github.com/woocommerce/woocommerce-blocks/pull/7717)

This commit is contained in:
Tung Du 2022-11-21 19:07:23 +07:00 committed by GitHub
parent 65afb95e35
commit 8108f42c30
5 changed files with 26 additions and 4246 deletions

View File

@ -4,8 +4,11 @@ inputs:
repo-token:
description: 'GitHub token'
required: true
compare:
description: 'Path checkstyle.xml file'
checkstyle:
description: 'Path checkstyle.xml file of current PR/branch'
required: true
checkstyle-trunk:
description: 'Path checkstyle.xml file of trunk'
required: true
runs:

View File

@ -4,7 +4,7 @@ const { setFailed, getInput } = require( '@actions/core' );
const { parseXml, getFilesWithNewErrors } = require( './utils/xml' );
const { generateMarkdownMessage } = require( './utils/markdown' );
const { addRecord } = require( './utils/airtable' );
const { getFileContent, addComment } = require( './utils/github' );
const { addComment } = require( './utils/github' );
const runner = async () => {
const token = getInput( 'repo-token', { required: true } );
@ -12,27 +12,18 @@ const runner = async () => {
const payload = context.payload;
const repo = payload.repository.name;
const owner = payload.repository.owner.login;
const fileName = getInput( 'compare', {
const fileName = getInput( 'checkstyle', {
required: true,
} );
const trunkFileName = getInput( 'checkstyle-trunk', {
required: true,
} );
const newCheckStyleFile = fs.readFileSync( fileName );
const newCheckStyleFileParsed = parseXml( newCheckStyleFile );
const currentCheckStyleFile = await getFileContent( {
octokit,
owner,
repo,
fileName,
onFail: setFailed,
} );
if ( ! currentCheckStyleFile.data ) {
setFailed( 'No Content Available' );
return;
}
const currentCheckStyleFile = fs.readFileSync( trunkFileName );
const currentCheckStyleFileContentParsed = parseXml(
currentCheckStyleFile.data
currentCheckStyleFile
);
const { header } = generateMarkdownMessage( newCheckStyleFileParsed );

View File

@ -1,28 +1,3 @@
exports.getFileContent = async ( {
octokit,
owner,
repo,
fileName,
onFail,
} ) => {
try {
return await octokit.rest.repos.getContent( {
owner,
repo,
path: fileName,
mediaType: {
format: 'raw',
},
} );
} catch ( err ) {
if ( err.status === '404' ) {
return;
}
onFail( err.message );
}
};
const getReportCommentId = async ( { octokit, owner, repo, payload } ) => {
const currentComments = await octokit.rest.issues.listComments( {
owner,

View File

@ -8,9 +8,9 @@ jobs:
check-typescript-errors-with-trunk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
ref: 'trunk'
- name: Cache node modules
uses: actions/cache@v3
@ -30,10 +30,19 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
- name: Generate checkstyle for trunk
run: |
npm ci
npm run ts:log-errors
mv checkstyle.xml $HOME/checkstyle-trunk.xml
- uses: actions/checkout@v3
- name: Generate checkstyle for current PR
run: |
npm ci
npm run ts:log-errors
mv $HOME/checkstyle-trunk.xml checkstyle-trunk.xml
- name: Get branch name
id: branch-name
@ -43,21 +52,8 @@ jobs:
uses: ./.github/monitor-typescript-errors
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
compare: checkstyle.xml
checkstyle: checkstyle.xml
checkstyle-trunk: checkstyle-trunk.xml
env:
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
CURRENT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
- name: Check if the checklist.xml file is changed
id: verify_diff
run: |
git diff --quiet checkstyle.xml || echo "is_different_checkstyle=true" >> $GITHUB_OUTPUT
- name: Commit the new checklist.xml file
if: steps.verify_diff.outputs.is_different_checkstyle == 'true'
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add checkstyle.xml
git commit -m "bot: update checkstyle.xml"
git push

File diff suppressed because it is too large Load Diff