diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0322a8082..0f66159e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ on: type: boolean concurrency: - group: ${{ github.ref }} + group: ${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a2becdbe1..12536edfe 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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 @@ -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 }} @@ -39,4 +47,38 @@ jobs: uses: actions/upload-artifact@v4 with: name: linter-result - path: super-linter.log \ No newline at end of file + 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.") \ No newline at end of file