Skip to content

Commit

Permalink
feat(CI): Add GitHub Markdown summary for linter CI (#412)
Browse files Browse the repository at this point in the history
* test: Added a comment to check for failed lint check

* fix: Set continue on error option to true to upload artifacts

* test: Added a wrong package name to check for failed linter workflow

* test: Added a wrong package name to check for failed linter workflow

* feat(CI): Added Workflow summary generation support to linter CI

* revert: Reverted back the changes made solely for testing CI

* fix: added ansi-remover

* fix: added ansi-remover

* feat(CI): Added Workflow summary generation support to linter CI

* feat(CI): Added Workflow summary generation support to linter CI

* feat(CI): Added Workflow summary generation support to linter CI

* fix(CI): Fixed extra newlines in workflow summary

* fix(CI): Fixed extra newlines in workflow summary

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment code

* feat(CI): Added PR comment permission

* feat(CI): Added PR comment permission

* feat(CI): Added PR comment permission

* feat(CI): Added PR comment permission

* feat(CI): Added PR comment permission

* feat(CI): Added PR comment permission

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* fix(CI): Fixed gh pr comment formatting issue

* feat(CI): Added limit to run only the latest trigger

* feat(CI): Added limit to run only the latest trigger

* feat(CI): Added limit to run only the latest trigger

* revert: Reverted back the changes made solely for testing CI

* chore: Changed the summary for successful run of linter

* fix: Fixed failure in running Build CI in source branch if it is triggered in PR
  • Loading branch information
SaptarshiSarkar12 authored Jan 12, 2024
1 parent e47dbb5 commit e3c492d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
type: boolean

concurrency:
group: ${{ github.ref }}
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Expand Down
48 changes: 45 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ on:
push:
pull_request:

concurrency:
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
contents: write
pull-requests: write
issues: write
statuses: write
packages: read
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -20,7 +26,9 @@ jobs:
# list of changed files within `super-linter`
fetch-depth: 0
- name: Lint Code Base
id: lint
uses: super-linter/super-linter/slim@v5
continue-on-error: true
env:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,4 +47,38 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: linter-result
path: super-linter.log
path: super-linter.log
- name: Generate Workflow Summary for successful run
if: ${{ steps.lint.outcome == 'success' }}
run: |
echo "## :ballot_box_with_check: Linting passed!" >> $GITHUB_STEP_SUMMARY
- name: Generate Workflow Summary for failed run
if: ${{ steps.lint.outcome == 'failure' }}
run: |
echo "## :x: Linting errors found!" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat super-linter.log | grep "\[ERROR]" | sed 's/[0-9A-Z:.-]\+ [0-9:]\+ //' | sed 's/\[ERROR]//' | sed 's/ //' | sed 's/Found errors in \[[A-Za-z]\+\] linter!//' | sed 's/Error code: 1. Command output://' | sed 's/ //' | sed 's/ERRORSFOUND//' | sed 's/ in [A-Z:]\+//' | sed 's/[[0-9]\+]//' | sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" | sed '1,2d' | tr -s '\n' '\n' | sed 's/\/github\/workspace\///' >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Comment on PR for failed run
if: ${{ steps.lint.outcome == 'failure' && github.event_name == 'pull_request' }}
shell: bash
run: |
COMMENT_INITIAL=$(echo -e "## :x: Linting errors found!\n")
COMMENT_MIDDLE=$(cat super-linter.log | grep "\[ERROR]" | sed 's/[0-9A-Z:.-]\+ [0-9:]\+ //' | sed 's/\[ERROR]//' | sed 's/ //' | sed 's/Found errors in \[[A-Za-z]\+\] linter!//' | sed 's/Error code: 1. Command output://' | sed 's/ //' | sed 's/ERRORSFOUND//' | sed 's/ in [A-Z:]\+//' | sed 's/[[0-9]\+]//' | sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g" | sed '1,2d' | tr -s '\n' '\n' | sed 's/\/github\/workspace\///')
COMMENT_BODY=$(echo -e "$COMMENT_INITIAL \n @${{ github.actor }} Please fix the following errors:\n\n\`\`\`\n$COMMENT_MIDDLE\n\`\`\`")
COMMENT=$(echo "$COMMENT_BODY")
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
-f body="$COMMENT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail Workflow for failure in linting
if: ${{ steps.lint.outcome == 'failure' }}
uses: actions/github-script@v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
core.setFailed("Linting errors found! Please check workflow summary for details.")

1 comment on commit e3c492d

@vercel
Copy link

@vercel vercel bot commented on e3c492d Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.