fix: enhance mega-linter workflow and improve script error handling #3243
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: mega-linter | |
on: | |
workflow_dispatch: | |
push: | |
branches-ignore: | |
- main | |
permissions: read-all | |
jobs: | |
github-context: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Debug | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: | | |
echo "${GITHUB_CONTEXT}" | |
mega-linter: | |
runs-on: ubuntu-latest | |
if: ${{ (!startsWith(github.ref_name, 'renovate/') && !startsWith(github.ref_name, 'release-please--')) || github.event_name == 'workflow_dispatch' }} | |
timeout-minutes: 30 | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Extract commands from markdown files | |
run: | | |
set -euxo pipefail | |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | |
brew install mdq | |
readarray -d '' MD_FILES < <(find . -type f -name "*.md" -print0) | |
for MD_FILE in "${MD_FILES[@]}"; do | |
for MDQ_CODE_BLOCK in bash sh shell; do | |
mdq '```/^'"${MDQ_CODE_BLOCK}"'$/' --br -o plain "$MD_FILE" > "${MD_FILE%.md}-${MDQ_CODE_BLOCK}.sh" | |
if [[ ! -s "${MD_FILE%.md}.sh" ]]; then | |
rm "${MD_FILE%.md}.sh" | |
else | |
sed -i '1i#!/usr/bin/env bash' "${MD_FILE%.md}-${MDQ_CODE_BLOCK}.sh" | |
chmod a+x "${MD_FILE%.md}.sh" | |
fi | |
done | |
done | |
- name: 💡 MegaLinter | |
uses: oxsecurity/megalinter@146333030da68e2e58c6ff826633824fabe01eaf # v8.5.0 | |
env: | |
GITHUB_COMMENT_REPORTER: false | |
# Disabled due to error: [GitHub Status Reporter] Error posting Status for REPOSITORY with ...: 403 | |
GITHUB_STATUS_REPORTER: false | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |