For Future Stackoverflow reader,
Below is the code I use to resolve my issue. First, I wanted to see what are all the files I have? After that ,I narrowed down to the path I wanted and was able to add the JSON
to the issue. Note, I added entire JSON
to the issue, but was able to capture what I was looking for. Thanks @jonrsharpe for pointers.
name: close-issue-after-lint-open
on:
issues:
types: [opened]
jobs:
close-issue:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
packages: read
statuses: write
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Run Super-linter
uses: super-linter/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_SQLFLUFF: true
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: true
- name: Log error to the issue
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.number }}
ERROR_LOG_PATH: ${{ github.workspace }}/super-linter-output/super-linter/super-linter-worker-results-SQLFLUFF.json
run: |
echo "Listing all files and directories in workspace:"
ls -R $GITHUB_WORKSPACE # List everything recursively in the workspace
# Optionally, list the contents of the specific super-linter output directory
if [ -d "${GITHUB_WORKSPACE}/${{ env.SUPER_LINTER_OUTPUT_DIRECTORY_NAME }}/super-linter" ]; then
echo "Listing contents of the Super Linter output directory:"
ls -R "${GITHUB_WORKSPACE}/${{ env.SUPER_LINTER_OUTPUT_DIRECTORY_NAME }}/super-linter"
else
echo "Super Linter output directory not found."
fi
# Check if the error log exists
if [ -f "$ERROR_LOG_PATH" ]; then
ERROR_LOG=$(cat "$ERROR_LOG_PATH")
else
ERROR_LOG="No errors found."
fi
# Post the error log to the issue
gh issue comment $ISSUE --body "Super Linter found the following issues:$ERROR_LOG"
- name: Close issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
ISSUE: ${{ github.event.issue.number }}
run: |
# Close the issue and add a comment
gh issue close --repo "$REPO" --comment "Autoclosing issue $ISSUE due to linting errors."