Refactor TypeScripts error monitoring workflow to avoid tracking checkstyle.xml (https://github.com/woocommerce/woocommerce-blocks/pull/7717)
This commit is contained in:
parent
65afb95e35
commit
8108f42c30
|
@ -4,8 +4,11 @@ inputs:
|
||||||
repo-token:
|
repo-token:
|
||||||
description: 'GitHub token'
|
description: 'GitHub token'
|
||||||
required: true
|
required: true
|
||||||
compare:
|
checkstyle:
|
||||||
description: 'Path checkstyle.xml file'
|
description: 'Path checkstyle.xml file of current PR/branch'
|
||||||
|
required: true
|
||||||
|
checkstyle-trunk:
|
||||||
|
description: 'Path checkstyle.xml file of trunk'
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { setFailed, getInput } = require( '@actions/core' );
|
||||||
const { parseXml, getFilesWithNewErrors } = require( './utils/xml' );
|
const { parseXml, getFilesWithNewErrors } = require( './utils/xml' );
|
||||||
const { generateMarkdownMessage } = require( './utils/markdown' );
|
const { generateMarkdownMessage } = require( './utils/markdown' );
|
||||||
const { addRecord } = require( './utils/airtable' );
|
const { addRecord } = require( './utils/airtable' );
|
||||||
const { getFileContent, addComment } = require( './utils/github' );
|
const { addComment } = require( './utils/github' );
|
||||||
|
|
||||||
const runner = async () => {
|
const runner = async () => {
|
||||||
const token = getInput( 'repo-token', { required: true } );
|
const token = getInput( 'repo-token', { required: true } );
|
||||||
|
@ -12,27 +12,18 @@ const runner = async () => {
|
||||||
const payload = context.payload;
|
const payload = context.payload;
|
||||||
const repo = payload.repository.name;
|
const repo = payload.repository.name;
|
||||||
const owner = payload.repository.owner.login;
|
const owner = payload.repository.owner.login;
|
||||||
const fileName = getInput( 'compare', {
|
const fileName = getInput( 'checkstyle', {
|
||||||
|
required: true,
|
||||||
|
} );
|
||||||
|
const trunkFileName = getInput( 'checkstyle-trunk', {
|
||||||
required: true,
|
required: true,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
const newCheckStyleFile = fs.readFileSync( fileName );
|
const newCheckStyleFile = fs.readFileSync( fileName );
|
||||||
const newCheckStyleFileParsed = parseXml( newCheckStyleFile );
|
const newCheckStyleFileParsed = parseXml( newCheckStyleFile );
|
||||||
const currentCheckStyleFile = await getFileContent( {
|
const currentCheckStyleFile = fs.readFileSync( trunkFileName );
|
||||||
octokit,
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
fileName,
|
|
||||||
onFail: setFailed,
|
|
||||||
} );
|
|
||||||
|
|
||||||
if ( ! currentCheckStyleFile.data ) {
|
|
||||||
setFailed( 'No Content Available' );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentCheckStyleFileContentParsed = parseXml(
|
const currentCheckStyleFileContentParsed = parseXml(
|
||||||
currentCheckStyleFile.data
|
currentCheckStyleFile
|
||||||
);
|
);
|
||||||
|
|
||||||
const { header } = generateMarkdownMessage( newCheckStyleFileParsed );
|
const { header } = generateMarkdownMessage( newCheckStyleFileParsed );
|
||||||
|
|
|
@ -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 getReportCommentId = async ( { octokit, owner, repo, payload } ) => {
|
||||||
const currentComments = await octokit.rest.issues.listComments( {
|
const currentComments = await octokit.rest.issues.listComments( {
|
||||||
owner,
|
owner,
|
||||||
|
|
|
@ -8,9 +8,9 @@ jobs:
|
||||||
check-typescript-errors-with-trunk:
|
check-typescript-errors-with-trunk:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.ref }}
|
ref: 'trunk'
|
||||||
|
|
||||||
- name: Cache node modules
|
- name: Cache node modules
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
|
@ -30,10 +30,19 @@ jobs:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: npm install
|
- name: Generate checkstyle for trunk
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run ts:log-errors
|
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
|
- name: Get branch name
|
||||||
id: branch-name
|
id: branch-name
|
||||||
|
@ -43,21 +52,8 @@ jobs:
|
||||||
uses: ./.github/monitor-typescript-errors
|
uses: ./.github/monitor-typescript-errors
|
||||||
with:
|
with:
|
||||||
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
compare: checkstyle.xml
|
checkstyle: checkstyle.xml
|
||||||
|
checkstyle-trunk: checkstyle-trunk.xml
|
||||||
env:
|
env:
|
||||||
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
|
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
|
||||||
CURRENT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
|
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
Loading…
Reference in New Issue